microbenthos.utils package¶
Submodules¶
microbenthos.utils.create module¶
-
class
microbenthos.utils.create.CreateMixin[source]¶ Bases:
objectA Mixin class that can create instances of classes defined in schema.yml, based on the
schema_key. A variety of object types are handled increate_from(), and the validated input is stored asdefinition_-
classmethod
create_from(obj, **kwargs)[source]¶ Instantiate class from the given object, and if possible, save the definition that was used to create the instance.
- Parameters
obj (object, dict, str,
IOBase) –object: if an instance of the cls, then it is returned directlydict: if a mapping, then it is passed tovalidate_dict()str: if a string, it is converted to stream-like and passed to
validate_yaml()io.IOBase: if a stream, it is passed tovalidate_yaml()
**kwargs – passed to
validate_dict()orvalidate_yaml()as necessary.
- Variables
`definition_` – the validated definition used to create the instance
- Returns
instance of the class this is subclassed by
-
classmethod
microbenthos.utils.loader module¶
-
class
microbenthos.utils.loader.MicroBenthosSchemaValidator(*args, **kwargs)[source]¶ Bases:
cerberus.validator.ValidatorA
cereberusvalidator for schema.yml in MicroBenthos-
logger= <Logger microbenthos.utils.loader (DEBUG)>¶
-
types_mapping= {'binary': TypeDefinition(name='binary', included_types=(<class 'bytes'>, <class 'bytearray'>), excluded_types=()), 'boolean': TypeDefinition(name='boolean', included_types=(<class 'bool'>,), excluded_types=()), 'container': TypeDefinition(name='container', included_types=(<class 'collections.abc.Container'>,), excluded_types=(<class 'str'>,)), 'date': TypeDefinition(name='date', included_types=(<class 'datetime.date'>,), excluded_types=()), 'datetime': TypeDefinition(name='datetime', included_types=(<class 'datetime.datetime'>,), excluded_types=()), 'dict': TypeDefinition(name='dict', included_types=(<class 'collections.abc.Mapping'>,), excluded_types=()), 'float': TypeDefinition(name='float', included_types=(<class 'float'>, (<class 'int'>,)), excluded_types=()), 'integer': TypeDefinition(name='integer', included_types=((<class 'int'>,),), excluded_types=()), 'list': TypeDefinition(name='list', included_types=(<class 'collections.abc.Sequence'>,), excluded_types=(<class 'str'>,)), 'number': TypeDefinition(name='number', included_types=((<class 'int'>,), <class 'float'>), excluded_types=(<class 'bool'>,)), 'physical_unit': TypeDefinition(name='physical_unit', included_types=(<class 'fipy.tools.dimensions.physicalField.PhysicalField'>,), excluded_types=()), 'set': TypeDefinition(name='set', included_types=(<class 'set'>,), excluded_types=()), 'string': TypeDefinition(name='string', included_types=<class 'str'>, excluded_types=())}¶
-
_check_with_importpath(field, value)[source]¶ Validates if the value is a usable import path for an entity class
- Valid examples are:
pkg1.pkg2.mod1.class
class_name
- Invalid examples:
.class_name
- Parameters
value – A string
- Returns
True if valid
-
_validate_like_unit(unit, field, value)[source]¶ Test that the given value has compatible units
- Parameters
unit – A string useful with
PhysicalFieldfield –
value – An instance of a physical unit
- Returns
boolean if validated
The rule’s arguments are validated against this schema: {‘type’: ‘string’}
-
_check_with_sympy_symbol(field, value)[source]¶ String that can be run through sympify and only has one variable symbol in it.
-
_check_with_model_path(field, value)[source]¶ Validate that the value of the field is a model store path
- Value should be of type:
domain.oxy
env.oxy.var
microbes.cyano.processes.oxyPS
The rule’s arguments are validated against this schema: {‘type’: ‘string’}
-
checkers= ('importpath', 'model_path', 'sympify', 'sympy_symbol', 'unit_name')¶
-
coercers= ('float',)¶
-
default_setters= ()¶
-
normalization_rules= {'coerce': {'oneof': [{'type': 'callable'}, {'type': 'list', 'schema': {'oneof': [{'type': 'callable'}, {'type': 'string', 'allowed': ('float',)}]}}, {'type': 'string', 'allowed': ('float',)}]}, 'default': {'nullable': True}, 'default_setter': {'oneof': [{'type': 'callable'}, {'type': 'string', 'allowed': ()}]}, 'purge_unknown': {'type': 'boolean'}, 'rename': {'type': 'hashable'}, 'rename_handler': {'oneof': [{'type': 'callable'}, {'type': 'list', 'schema': {'oneof': [{'type': 'callable'}, {'type': 'string', 'allowed': ('float',)}]}}, {'type': 'string', 'allowed': ('float',)}]}}¶
-
rules= {'allof': {'logical': 'allof', 'type': 'list'}, 'allow_unknown': {'oneof': [{'type': 'boolean'}, {'type': ['dict', 'string'], 'check_with': 'bulk_schema'}]}, 'allowed': {'type': 'container'}, 'anyof': {'logical': 'anyof', 'type': 'list'}, 'check_with': {'oneof': [{'type': 'callable'}, {'type': 'list', 'schema': {'oneof': [{'type': 'callable'}, {'type': 'string', 'allowed': ('importpath', 'model_path', 'sympify', 'sympy_symbol', 'unit_name')}]}}, {'type': 'string', 'allowed': ('importpath', 'model_path', 'sympify', 'sympy_symbol', 'unit_name')}]}, 'coerce': {'oneof': [{'type': 'callable'}, {'type': 'list', 'schema': {'oneof': [{'type': 'callable'}, {'type': 'string', 'allowed': ('float',)}]}}, {'type': 'string', 'allowed': ('float',)}]}, 'contains': {'empty': False}, 'default': {'nullable': True}, 'default_setter': {'oneof': [{'type': 'callable'}, {'type': 'string', 'allowed': ()}]}, 'dependencies': {'check_with': 'dependencies', 'type': ('dict', 'hashable', 'list')}, 'empty': {'type': 'boolean'}, 'excludes': {'schema': {'type': 'hashable'}, 'type': ('hashable', 'list')}, 'forbidden': {'type': 'list'}, 'items': {'check_with': 'items', 'type': 'list'}, 'keysrules': {'check_with': 'bulk_schema', 'forbidden': ['rename', 'rename_handler'], 'type': ['dict', 'string']}, 'like_unit': {'type': 'string'}, 'max': {'nullable': False}, 'maxlength': {'type': 'integer'}, 'meta': {}, 'min': {'nullable': False}, 'minlength': {'type': 'integer'}, 'noneof': {'logical': 'noneof', 'type': 'list'}, 'nullable': {'type': 'boolean'}, 'oneof': {'logical': 'oneof', 'type': 'list'}, 'purge_unknown': {'type': 'boolean'}, 'readonly': {'type': 'boolean'}, 'regex': {'type': 'string'}, 'rename': {'type': 'hashable'}, 'rename_handler': {'oneof': [{'type': 'callable'}, {'type': 'list', 'schema': {'oneof': [{'type': 'callable'}, {'type': 'string', 'allowed': ('float',)}]}}, {'type': 'string', 'allowed': ('float',)}]}, 'require_all': {'type': 'boolean'}, 'required': {'type': 'boolean'}, 'schema': {'anyof': [{'check_with': 'schema'}, {'check_with': 'bulk_schema'}], 'type': ['dict', 'string']}, 'type': {'check_with': 'type', 'type': ['string', 'list']}, 'valuesrules': {'check_with': 'bulk_schema', 'forbidden': ['rename', 'rename_handler'], 'type': ['dict', 'string']}}¶
-
validation_rules= {'allof': {'logical': 'allof', 'type': 'list'}, 'allow_unknown': {'oneof': [{'type': 'boolean'}, {'type': ['dict', 'string'], 'check_with': 'bulk_schema'}]}, 'allowed': {'type': 'container'}, 'anyof': {'logical': 'anyof', 'type': 'list'}, 'check_with': {'oneof': [{'type': 'callable'}, {'type': 'list', 'schema': {'oneof': [{'type': 'callable'}, {'type': 'string', 'allowed': ('importpath', 'model_path', 'sympify', 'sympy_symbol', 'unit_name')}]}}, {'type': 'string', 'allowed': ('importpath', 'model_path', 'sympify', 'sympy_symbol', 'unit_name')}]}, 'contains': {'empty': False}, 'dependencies': {'check_with': 'dependencies', 'type': ('dict', 'hashable', 'list')}, 'empty': {'type': 'boolean'}, 'excludes': {'schema': {'type': 'hashable'}, 'type': ('hashable', 'list')}, 'forbidden': {'type': 'list'}, 'items': {'check_with': 'items', 'type': 'list'}, 'keysrules': {'check_with': 'bulk_schema', 'forbidden': ['rename', 'rename_handler'], 'type': ['dict', 'string']}, 'like_unit': {'type': 'string'}, 'max': {'nullable': False}, 'maxlength': {'type': 'integer'}, 'meta': {}, 'min': {'nullable': False}, 'minlength': {'type': 'integer'}, 'noneof': {'logical': 'noneof', 'type': 'list'}, 'nullable': {'type': 'boolean'}, 'oneof': {'logical': 'oneof', 'type': 'list'}, 'readonly': {'type': 'boolean'}, 'regex': {'type': 'string'}, 'require_all': {'type': 'boolean'}, 'required': {'type': 'boolean'}, 'schema': {'anyof': [{'check_with': 'schema'}, {'check_with': 'bulk_schema'}], 'type': ['dict', 'string']}, 'type': {'check_with': 'type', 'type': ['string', 'list']}, 'valuesrules': {'check_with': 'bulk_schema', 'forbidden': ['rename', 'rename_handler'], 'type': ['dict', 'string']}}¶
-
microbenthos.utils.log module¶
microbenthos.utils.snapshotters module¶
-
microbenthos.utils.snapshotters.snapshot_var(V, base=False, to_unit=None)[source]¶ Utility to express a variable array as its numeric value and corresponding units
-
microbenthos.utils.snapshotters.restore_var(input, tidx)[source]¶ This is the inverse operation of
snapshot_var(). It takes the output of that function and returns a PhysicalField quantity- Returns
PhysicalField
microbenthos.utils.yaml_setup module¶
Imports yaml from PyYaml and adds serialization options for fipy.PhysicalField.