Core¶
This is the SimKit core package. SimKit is extensible through its built-in classes; therefore adding new data sources, formulas importers, calculators, simulations is accomplished by sub-classing the appropriate class.
The built-in classes are organized into 5 categories, which make up the layers of a model.
Data
Formulas
Calculations
Simulations
Outputs
See the Developers in the developer section for more information on each section.
Registry¶
-
class
simkit.core.Registry[source]¶ Base class for a registry.
The register method can be used to add new keys to the registry only if they don’t already exist. A registry can also have meta data associated with subsets of the registered keys. To enforce rules on meta when the keys are registered, override the register method and raise exceptions before calling the
super()built-in function.By default there are no meta attributes, only the register method. To set meta attributes, in a subclass, set the
meta_namesclass attribute in the subclass:class MyRegistry(Registry): meta_names = ['meta1', 'meta2', ...]
The
Registrysuperclass will check that the meta names are not already attributes and then set instance attributes as empty dictionaries in the subclass. To document them, use the class docstring or document them in the documentation API.-
register(newitems, *args, **kwargs)[source]¶ Register newitems in registry.
- Parameters
newitems (mapping) – New items to add to registry. When registering new items, keys are not allowed to override existing keys in the registry.
args – Positional arguments with meta data corresponding to order of meta names class attributes
kwargs – Maps of corresponding meta for new keys. Each set of meta keys must be a subset of the new item keys.
- Raises
-
Convert Arguments Decorator¶
-
simkit.core.convert_args(test_fcn, *test_args)[source]¶ Decorator to be using in formulas to convert
test_argsdepending on thetest_fcn.- Parameters
test_fcn (function) – A test function that converts arguments.
test_args (str) – Names of args to convert using
test_fcn.
The following test functions are available. *
dimensionless_to_index()Example: Convert
dawn_idxandeve_idxto indices:@convert_args(dimensionless_to_index, 'dawn_idx', 'eve_idx') def f_max_T(Tcell24, dawn_idx, eve_idx): idx = dawn_idx + np.argmax(Tcell24[dawn_idx:eve_idx]) return Tcell24[idx], idx
SimKit JSON Encoder¶
Common Base¶
-
class
simkit.core.CommonBase[source]¶ Provides common metaclass methods.
get_parents()ensures initialization only from subclasses of the main class and not the main class itselfset_param_file_or_parameters()adds class attributesparam_fileorparametersdepending on whether the path and file of the parameters are given or if the parameters are listed as class attributes.
Base classes must implement the
_path_attrand_file_attras class attributes:class ExampleBase(CommonBase): _path_attr = 'outputs_path' # class attribute with parameter path _file_attr = 'outputs_file' # class attribute with parameter file
-
static
get_parents(bases, parent)[source]¶ Ensures that initialization only performed on subclasses of parent https://github.com/django/django/blob/master/django/db/models/base.py
-
classmethod
set_meta(bases, attr)[source]¶ Get all of the
Metaclasses from bases and combine them with this class.Pops or creates
Metafrom attributes, combines all bases, adds_metato attributes with all meta- Parameters
bases – bases of this class
attr – class attributes
- Returns
attributes with
Metaclass from combined parents
-
classmethod
set_param_file_or_parameters(attr)[source]¶ Set parameters from class attributes that are instances of
Parameteror from a parameter file.Any class attributes that are instances of
Parameterare popped from the class and added to a theparametersattribute, which is a dictionary of the parameters.- Parameters
attr – class attributes
- Returns
new list of class attributes with parameters