Layers

This is the Layers module. There are five layers in a SimKit model:

  • Data

  • Formulas

  • Calculations

  • Outputs

  • Simulations

Layers are used to assemble the model. For example, the data layer assembles all of the Data Sources, calling the Data Readers and putting all of the data (and meta) into the DataRegistry.

In general all model layers have add, open and load() methods. The add method adds a particular format such as a DataSource. The open method gets data from a file in the format that was added. The load() method loads the layer into the model. The load() method must be implemented in each subclass of Layer or NotImplementedError is raised.

Layer

class simkit.core.layers.Layer(sources=None)[source]

A layer in the model.

Parameters

sources (dict) – Dictionary of model parameters specific to this layer.

add(src_cls, module, package=None)[source]

Add layer class to model. This method may be overloaded by layer.

Parameters
  • src_cls (str) – layer class to add, should not start with underscores

  • module (str) – Python module that contains layer class

  • package (str) – optional package containing module with layer class

Raises

NotImplementedError

delete(src_cls)[source]

Delete layer source class from layer. :param src_cls: layer source class to delete. :raises: NotImplementedError

edit(src_cls, value)[source]

Edit layer source class with value.

Parameters
  • src_cls (str) – layer source class to edit

  • value – new value of layer source class

Raises

NotImplementedError

layer = None

dictionary of layer sources

load(relpath=None)[source]

Load the layer from the model data. This method must be implemented by each layer.

Parameters

relpath – alternate path if specified path is missing or None

Raises

NotImplementedError

objects = None

dictionary of source class instances added to the layer

reg = None

registry of items contained in this layer

reg_cls = NotImplemented

registry class

sources = None

dictionary of layer source classes added to the layer

src_cls = NotImplemented

source class

Data

class simkit.core.layers.Data(sources=None)[source]

The Data layer of the model.

The layer attribute is a dictionary of data sources names as keys of dictionaries for each data source with the module and optionally the package containing the module, the filename, which can be None, containing specific data for the data source and an optional path to the data file. If the path is None, then the default path for data internal to SimKit is used. External data files should specify the path.

add(data_source, module, package=None)[source]

Add data_source to model. Tries to import module, then looks for data source class definition.

Parameters
  • data_source (str) – Name of data source to add.

  • module (str) – Module in which data source resides. Can be absolute or relative. See importlib.import_module()

  • package (str) – Optional, but must be used if module is relative.

delete(data_src)[source]

Delete data sources.

edit(data_src, value)[source]

Edit data layer.

Parameters
  • data_src (str) – Name of DataSource to edit.

  • value (dict) – Values to edit.

load(rel_path=None)[source]

Add data_sources to layer and open files with data for the data_source.

open(data_source, *args, **kwargs)[source]

Open filename to get data for data_source.

Parameters

data_source (str) – Data source for which the file contains data.

Positional and keyword arguments can contain either the data to use for the data source or the full path of the file which contains data for the data source.

reg_cls

alias of simkit.core.data_sources.DataRegistry

src_cls

alias of simkit.core.data_sources.DataSource

Formulas

class simkit.core.layers.Formulas(sources=None)[source]

Layer containing formulas.

add(formula, module, package=None)[source]

Import module (from package) with formulas, import formulas and add them to formula registry.

Parameters
  • formula – Name of the formula source to add/open.

  • module – Module containing formula source.

  • package – [Optional] Package of formula source module.

delete(src_cls)[source]

Delete layer source class from layer. :param src_cls: layer source class to delete. :raises: NotImplementedError

edit(src_cls, value)[source]

Edit layer source class with value.

Parameters
  • src_cls (str) – layer source class to edit

  • value – new value of layer source class

Raises

NotImplementedError

load(_=None)[source]

Add formulas to layer.

reg_cls

alias of simkit.core.formulas.FormulaRegistry

src_cls

alias of simkit.core.formulas.Formula

Calculations

class simkit.core.layers.Calculations(sources=None)[source]

Layer containing formulas.

add(calc, module, package=None)[source]

Add calc to layer.

delete(src_cls)[source]

Delete layer source class from layer. :param src_cls: layer source class to delete. :raises: NotImplementedError

edit(src_cls, value)[source]

Edit layer source class with value.

Parameters
  • src_cls (str) – layer source class to edit

  • value – new value of layer source class

Raises

NotImplementedError

load(_=None)[source]

Add calcs to layer.

reg_cls

alias of simkit.core.calculations.CalcRegistry

src_cls

alias of simkit.core.calculations.Calc

Outputs

class simkit.core.layers.Outputs(sources=None)[source]

Layer containing output sources.

add(output, module, package=None)[source]

Add output to

delete(src_cls)[source]

Delete layer source class from layer. :param src_cls: layer source class to delete. :raises: NotImplementedError

edit(src_cls, value)[source]

Edit layer source class with value.

Parameters
  • src_cls (str) – layer source class to edit

  • value – new value of layer source class

Raises

NotImplementedError

load(_=None)[source]

Add output_source to layer.

reg_cls

alias of simkit.core.outputs.OutputRegistry

src_cls

alias of simkit.core.outputs.Output

Simulations

class simkit.core.layers.Simulations(sources=None)[source]

Layer containing simulation sources.

add(sim, module, package=None)[source]

Add simulation to layer.

delete(src_cls)[source]

Delete layer source class from layer. :param src_cls: layer source class to delete. :raises: NotImplementedError

edit(src_cls, value)[source]

Edit layer source class with value.

Parameters
  • src_cls (str) – layer source class to edit

  • value – new value of layer source class

Raises

NotImplementedError

load(rel_path=None)[source]

Add sim_src to layer.

reg_cls

alias of simkit.core.simulations.SimRegistry

src_cls

alias of simkit.core.simulations.Simulation