Core

This is the Carousel core package. Carousel 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.

Unit Registry

carousel.core.UREG

Pint package default unit registry

Registry

class carousel.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_names class attribute in the subclass:

class MyRegistry(Registry):
    meta_names = ['meta1', 'meta2', ...]

The Registry superclass 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:

DuplicateRegItemError, MismatchRegMetaKeysError

unregister(items)[source]

Remove items from registry.

Parameters:items

Convert Arguments Decorator

carousel.core.convert_args(test_fcn, *test_args)[source]

Decorator to be using in formulas to convert test_args depending on the test_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_idx and eve_idx to 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

Dimensionless to Index

carousel.core.dimensionless_to_index(index)[source]

Common Base

class carousel.core.CommonBase[source]

Provides common metaclass methods.

  • get_parents() ensures initialization only from subclasses of the main class and not the main class itself
  • set_param_file_or_parameters() adds class attributes param_file or parameters depending 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_attr and _file_attr as 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

Parameters:
  • bases (list) – Bases to compare against parent.
  • parent – Superclass that bases should be subclassed from.
Returns:

Bases subclassed from parent.

Return type:

list

classmethod set_meta(mcs, bases, attr)[source]

Get all of the Meta classes from bases and combine them with this class.

Pops or creates Meta from attributes, combines all bases, adds _meta to attributes with all meta

Parameters:
  • bases – bases of this class
  • attr – class attributes
Returns:

attributes with Meta class from combined parents

classmethod set_param_file_or_parameters(mcs, attr)[source]

Set parameters from class attributes that are instances of Parameter or from a parameter file.

Any class attributes that are instances of Parameter are popped from the class and added to a the parameters attribute, which is a dictionary of the parameters.

Parameters:attr – class attributes
Returns:new list of class attributes with parameters

Parameter

class carousel.core.Parameter(*args, **kwargs)[source]