midas.util package

Submodules

midas.util.base_data_model module

This module contains the model for data simulators.

class midas.util.base_data_model.DataModel(data_p, data_q, data_step_size, scaling, **params)

Bases: object

A model for a single load or sgen time series.

There are a few assumptions for the time series that are not checked. First, the time series ranges over a whole year and secondly, the time passed between two values is 15 minutes. Therefore, not less than 35040 value are expected to be in each time series (for data_p and for data_q).

However, the DataModel could be extended to support other timely resolutions and make use of data of a second (third, fourth,…) year.

Parameters
  • data_p (pandas.DataFrame) – Contains values (either load or sgen) for active power. The index columns are simple int.

  • data_q (pandas.DataFrame) – Contains values (either load or sgen) for reactive power. The index columns are simple int. If None is provided for data_q, the cos phi is used in each step to calculate a value for q.

  • data_step_size (int) – Timely resolution of the data in seconds.

  • scaling (float) – An overall scaling for this model. This scaling is applied in each to step both of p and q.

  • seed (int, optional) – A seed for the random number generator.

  • interpolate (bool, optional) – If set to True, interpolation is applied when values between full 15-minute intervalls are requested.

  • randomize_data (bool, optional) – If set to True, a normally distributed random noise is applied to all outputs.

  • randomize_cos_phi (bool, optional) – If set to True and data_q is not provided, the cos phi for the calculation of q is randomized.

  • date_index (bool, optional) – Set this to True if the has datetime as index instead of ints.

now_dt

now_dt is an input and needs to be provided in each step. The current simulated time. Is used to calculate the index for the current value in the time series.

Type

datetime.datetime

cos_phi

cos_phi is an input and needs to be provided in each step. The phase angle used to calculate reactive power if no reactive power time series is provided.

Type

float

p_mw

p_mw is an output. The active power for the current step.

Type

float

q_mvar

q_mvar is an output. The reactive power for the current step.

Type

float

step()

Perform a simulation step.

midas.util.base_data_simulator module

This module contains the base simulator class for certain data simulators.

The models itself are simple data providers.

class midas.util.base_data_simulator.BaseDataSimulator(meta)

Bases: mosaik_api.Simulator

A base simulator for hdf5 data.

Parameters

meta (dict) – The meta dict this simulator should pass to mosaik_api.

create(num, model, **model_params)

Initialize the simulation model instance (entity)

Parameters
  • num (int) – The number of models to create.

  • model (str) – The name of the models to create. Must be present inside the simulator’s meta.

Returns

A list with information on the created entity.

Return type

list

get_data(outputs)

Return the requested output (if feasible).

Parameters

outputs (dict) – A dict containing requested outputs of each entity.

Returns

A dict containing the values of the requested outputs.

Return type

dict

init(sid, **sim_params)

Called exactly ones after the simulator has been started.

Parameters
  • sid (str) – Simulator ID for this simulator.

  • step_size (int, optional) – Step size for this simulator. Defaults to 900.

  • now_dt (str) – An ISO datestring with Europe/Berlin timezone.

  • interpolate (bool) – If True, interpolation is applied when step size is lower than the resolution of the data.

  • randomize_data (bool) – If True, a small random noise is added to the data in each step.

  • cos_phi (float) – A static cos phi used if no values for q are present in the data.

  • randomize_cos_phi (bool) – If True, the cos phi is randomized. Applies only to data without values for q.

  • seed (int) – A seed for the random number generator. Random numbers are only used, if one of the randomize flags is set.

Returns

The meta dict (set by mosaik_api.Simulator)

Return type

dict

step(time, inputs)

Perform a simulation step.

Parameters
  • time (int) – The current simulation step (by convention in seconds since simulation start.

  • inputs (dict) – A dict containing inputs for entities of this simulator.

Returns

The next step this simulator wants to be stepped.

Return type

int

midas.util.compute_q module

midas.util.compute_q.compute_q(p_w, cos_phi, mode='inductive')

Calculates reactive power

Parameters
  • p_w (float) – The active power (can also be kW)

  • cos_phi (float) – The phase angle to calculate q.

  • mode (str, optional) – Can be either ‘inductive’ or ‘capacitive’. Defaults to ‘inductive’, which returns the value as it is. If set to ‘capacitive’, the sign of the output is flipped.

Returns

Returns q_var in the same size of order like p_w (e.g., if p is in kW, q will be in kvar)

Return type

float

midas.util.dateformat module

This module contains supported date format strings.

midas.util.dict_util module

This module contains a set of utility functions for dictionaries.

midas.util.dict_util.convert(src)

Recursive conversion to basic data types.

midas.util.dict_util.convert_list(old_list)
midas.util.dict_util.convert_val(val)
midas.util.dict_util.update(src, upd)

Recursive update of dictionaries.

See stackoverflow:

https://stackoverflow.com/questions/3232943/ update-value-of-a-nested-dictionary-of-varying-depth

midas.util.logging_util module

This module contains the logging configuration for midas.

midas.util.logging_util.setup_logging(loglevel=None, logfilename=None)

Setup logging with loglevel level.

Module contents