Calculations

This module provides base classes for calculations. All calculations should inherit from one of the calcs in this module.

Calculation Parameter

class simkit.core.calculations.CalcParameter(*args, **kwargs)[source]

Fields for calculations.

Parameters
  • dependencies (list) – required calculations

  • always_calc (bool) – calculations ignore simulation thresholds

  • frequency – dynamic calculations different from timestep

  • formula (str) – name of a function

  • args (dict) – dictionary of data and outputs

  • returns (list) – name(s) of outputs

  • calculator (Calculator) – calculator class used to calculate this

  • is_dynamic (bool) – true if this is a periodic calculation [False]

Calculation Registry

class simkit.core.calculations.CalcRegistry[source]

A registry for calculations. Each key is a calculation. The value of each calculation is split into 2 dictionaries: “static” and “dynamic”. Static calculations occur once at the beginning of a simulation and dynamic calculations occur at every interval. The contents of either the “static” or “dynamic” key is an ordered list of formulas, their arguments and return values.

Calculations can list dependencies that must be calculated first. Calculations marked as always_calc will not be limited by thresholds set in simulations. The frequency determines how often to dynamic calculations occur. Frequency can be given in intervals or can list a quantity of time, _EG:_ 2 * UREG.hours.

Calculation Base

class simkit.core.calculations.CalcBase[source]

Base calculation meta class.

Calculation

class simkit.core.calculations.Calc[source]

A class for all calculations.

Calculators

Calculators are used to execute calculations.

Calculator

class simkit.core.calculators.Calculator[source]

Base class for calculators. Must implement calculate method.

classmethod calculate(calc, formula_reg, data_reg, out_reg, timestep=None, idx=None)[source]

Execute calculation

Parameters
  • calc (dict) – calculation, with formula, args and return keys

  • formula_reg (FormulaRegistry) – Registry of formulas.

  • data_reg (DataRegistry) – Data registry.

  • out_reg (OutputRegistry) – Outputs registry.

  • timestep – simulation interval length [time], default is None

  • idx (int) – interval index, default is None

static get_covariance(datargs, outargs, vargs, datvar, outvar)[source]

Get covariance matrix.

Parameters
  • datargs – data arguments

  • outargs – output arguments

  • vargs – variable arguments

  • datvar – variance of data arguments

  • outvar – variance of output arguments

Returns

covariance