maverig.utils

maverig.utils.colorTools

maverig.utils.colorTools.lab_color(color)

Convert QColor, tuple, list or numpy-array to LabColor.

maverig.utils.colorTools.q_color(color)

Convert tuple, list or numpy-array and QGlobalColor to QColor.

maverig.utils.colorTools.np_color(color)

Convert tuple, list, QGlobalColor and QColor to numpy array.

maverig.utils.colorTools.color_interp(x, values, colors)

Return linear color interpolation of value x within values mapped to colors.

Example:

x = 0.09
values = [0.05, 0.08, 0.1]
colors = [Qt.black, Qt.yellow, Qt.red]
return QColor(255, 127, 0) # orange
maverig.utils.colorTools.get_icon_color(filename)

Scan an icon and return the most prevalent color.

maverig.utils.colorTools.compare_color(color1, color2)

Compare two colors (tuple, QColor or LabColor) with delta_e_cie_2000 human color perception approximation.

Return a float value where 2.3 corresponds to a JND (just noticeable difference).

maverig.utils.colorTools.distinct_colors(base_colors)

Return a list of colors where approximately same colors in base_colors are replaced by distinct colors.

maverig.utils.colorTools.distinct_colors_from_palette(base_colors, palette_colors)

Generate distinct colors similar to base_colors from palette_colors.

maverig.utils.colorTools.palette_tableau10()

Tableau-10 color set taken from http://tableaufriction.blogspot.ro/2012/11/finally-you-can-use-tableau-data-colors.html

maverig.utils.colorTools.palette_iwanthue50()

Generated colors with http://tools.medialab.sciences-po.fr/iwanthue/

settings: H=[0..360] C=[0.. 2] L=[0..1.15]

maverig.utils.event

class maverig.utils.event.Event

Bases: object

Simple Event Class - see: http://www.valuedlessons.com/2008/04/events-in-python.html usage:

handle(handler)
unhandle(handler)
demand()
fire(*args, **kwargs)

fires the event with given arguments and return a list of results of each call

get_handler_count()

maverig.utils.flowlayout

class maverig.utils.flowlayout.FlowLayout(parent=None, margin=0, spacing=-1)

Bases: PySide.QtGui.QLayout

PyQt4 port of the layouts/flowlayout example from Qt v4.x

Usage Example:
flowLayout = FlowLayout() flowLayout.addWidget(QtGui.QPushButton(“Short”)) flowLayout.addWidget(QtGui.QPushButton(“Longer”)) flowLayout.addWidget(QtGui.QPushButton(“Different text”)) flowLayout.addWidget(QtGui.QPushButton(“More text”)) flowLayout.addWidget(QtGui.QPushButton(“Even longer button text”)) self.setLayout(flowLayout)
addItem(item)
count()
itemAt(index)
takeAt(index)
expandingDirections()
hasHeightForWidth()
heightForWidth(width)
setGeometry(rect)
sizeHint()
minimumSize()
doLayout(rect, testOnly)

maverig.utils.forceatlas2

maverig.utils.forceatlas2.init_edge_weights(g)
maverig.utils.forceatlas2.init_data(g, nodelist, dim=2, edge_weight=False)

Sets the default positions and visability data edge_weight calculation should only be done if a graph already converged

maverig.utils.forceatlas2.init_nodelist(g, nodelist=None)
maverig.utils.forceatlas2.length_arr(delta, minimum=0, squared=False)

Return the length for each node in delta delta = [[x1,x2,x3...],[y1,y2,y3...] length_arr = [length1, length2, length3...]

delta: the numpy (dim,nnodes) array minimum: the minimum lengths to return

class maverig.utils.forceatlas2.SpeedModel(mass_arr, ratio=0.01, k_s=1, k_s_max=10, max_rise=0.5)

Bases: object

see: https://github.com/gephi/gephi/tree/master/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/forceAtlas2/ForceAtlas.java

get_speed_arr(force_arr)

Return the local adaptive speed as array for each node. Call this once in each iteration after force calculation and before applying forces

class maverig.utils.forceatlas2.ForceAtlas2(g, nodelist=None, attr_weight=None, attr_size=None, avoidoverlap=False, linlog=False, dissuadehubs=False, scale=2, dim=2, repulsion_factor=150, standard_size=15)

Bases: object

Basic concept taken from: https://github.com/tpoisot/nxfa2 (Timothée Poisot). Completely revised.

A ForceAtlas2-algorithm graph layouter. Numpy optimized version with additional options, but no barnes-hut-grid approach.

do_layout()

do one layout calculation step. position data is assigned as ‘pos’ attribute to each node

maverig.utils.logger

class maverig.utils.logger.StreamToLogger(logger, log_level=20)

Bases: object

Fake file-like stream object that redirects writes to a logger instance. taken from http://www.electricmonk.nl/log/2011/08/14/redirect-stdout-and-stderr-to-a-logger-in-python

write(buf)
flush()
maverig.utils.logger.activate_logger(log_file)

maverig.utils.maverig_csv

class maverig.utils.maverig_csv.CSV

Bases: mosaik_api.Simulator

An extended copy of mosaik-csv simulator with static and dynamic data support.

Example:

House — static data — num_hh, res 3, 4 — dynamic data — Date, P # [W] 2014-10-20 00:00:00, 1080.1 2014-10-20 00:15:00, 686.06 ...
init(sid, sim_start, datafile)
create(num, model)
step(time, inputs=None)
get_data(outputs)
maverig.utils.maverig_csv.main()

maverig.utils.numTools

maverig.utils.numTools.convert(string_value, to_type_str=None)

convert string value to base type representation

maverig.utils.numTools.get_unit_prefixed(value)

return the adapted value and prefix

maverig.utils.numTools.get_short_value_text(value, unit)

return shortened value string with unit prefixes or exponents for small and big numbers

maverig.utils.processServer

class maverig.utils.processServer.Call_Pack(func_name, args, kwargs)

Bases: tuple

Transfer method format for calling functions via ServerProxy.

args

Alias for field number 1

func_name

Alias for field number 0

kwargs

Alias for field number 2

class maverig.utils.processServer.Server(interval=40)

Bases: object

A server managing incoming function calls via zero-mq socket.

register_function(func_name)

Register a server function that can be called via proxy.

start()

Start listening to incoming function calls and activate the socket.

run()

Repeatedly listens to incoming function calls as Call_Pack and trigger them.

stop()

Stop listening to incoming function calls and close socket.

class maverig.utils.processServer.ProcessServer(interval=40)

Bases: maverig.utils.processServer.Server

A server managing subprocesses and their incoming function calls.

register_process_factory(process_factory)

Register a factory method to create a subprocess.

start()

Start subprocesses and constantly listen to incoming function calls.

stop()

Stop subprocesses and stop listening to incoming functions.

class maverig.utils.processServer.MethodProxy(server_proxy, func_name)

Bases: object

A callable method proxy that can directly be called on the parent ServerProxy with same name and parameters like the Server function.

class maverig.utils.processServer.ServerProxy(server)

Bases: object

Subprocess (~client) side access to registered server functions. Calls can currently only be one-directional. Function return values are ommitted.

init_socket()

Activate the socket for sending method calls to Server from Subprocess. This method must be called from Subprocess!

close_socket()

Close the Subprocess socket to Server. This method must be called from Subprocess!

maverig.utils.scenarioErrors

exception maverig.utils.scenarioErrors.ScenarioError

Bases: Exception

title
console_text
text
info_text
elem_ids = []
exception maverig.utils.scenarioErrors.ScenarioEmptyError

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioOfflineElementError(elem_id='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioConnectionError(elem_id='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioBaseVoltageLevelError(ref_id='', bus_id='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioRefBusConnectionError(elem_id='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioRefBusMissingError

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioRefBusCountError(elem_ids=[])

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioDatafileError(elem_id='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioFileNotFoundError(elem_id='', sim_name='', filename='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioSimulatorError(elem_id='', sim_name='', tb='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioComponentError(elem_id='', sim_model='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioElementError(elem_id='', tb='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioSimulationBranchLengthError(elem_id='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioSimulationPowerflowError(elem_ids=[])

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text
exception maverig.utils.scenarioErrors.ScenarioSimulationRuntimeError(tb='')

Bases: maverig.utils.scenarioErrors.ScenarioError

title
console_text
text
info_text

maverig.utils.tableWidgets

class maverig.utils.tableWidgets.CellLineEdit(table, cell_item)

Bases: PySide.QtGui.QLineEdit

keyPressEvent(event)
text_changed(text)

add or remove rows according to last element content

class maverig.utils.tableWidgets.AutoRowTableWidget(*args, **kwargs)

Bases: PySide.QtGui.QTableWidget

Table Widget which always leaves one empty row as last row. RowCount is automatically adapted to cell contents.

text(row, col)
row_has_text(row)
append_row()

maverig.utils.visSimulator

class maverig.utils.visSimulator.VisSimulator

Bases: mosaik_api.Simulator

The Maverig Visualization Simulator which collects simulated data from other entities and send them via maverig.utils.processServer.ServerProxy to maverig.models.model.SimulationServer in order to update the visualization in the main application process.

init(sid, start_date, step_size, sim_proxy, elements)

Initialize the simulator with the ID sid, the start date start_date, the step size step_size, the simulation proxy sim_proxy and the elements list elements.

create(num, model)

Create num instances of model.

step(time, inputs)

Perform the next simulation step from time time using input values from inputs, update the simulation data (time, progress, element values) via the simulation proxy and return the new simulation time (the time at which step() should be called again).

maverig.utils.visSimulator.main()