microbenthos.core package

Submodules

microbenthos.core.domain module

Module that defines the microbenthic domain: sediment + diffusive boundary layer

class microbenthos.core.domain.SedimentDBLDomain(cell_size=0.1, sediment_length=10, dbl_length=1, porosity=0.6)[source]

Bases: object

Class that defines the model domain as a sediment column with a diffusive boundary layer.

__init__(cell_size=0.1, sediment_length=10, dbl_length=1, porosity=0.6)[source]

Create a model domain that defines a sediment column and a diffusive boundary layer column on top of it. The mesh parameters should be supplied.

If the mesh dimensions are given as PhysicalField then they are converted into meters. If plain numbers (float) are given, then they are interpreted as being in units of mm. Finally, the parameters are all converted to base units (meters) for the creation of the mesh, so that the model equations and parameters can all work on a common dimension system.

Parameters
  • cell_size (float, PhysicalField) – The size of a cell (default: 100 micron)

  • sediment_length (float) – The length of the sediment column in mm (default: 10)

  • dbl_length (float) – The length of the DBL in mm (default: 1)

  • porosity (float) – The porosity value for the sediment column (default: 0.6)

VARS

Mapping of names to CellVariable instances available on the domain:

mesh

The fipy Mesh instance

cell_size

the mesh cell size as a PhysicalField

total_cells

sediment + DBL

Type

total cells in the domain

sediment_length

the sediment subdomain length as a PhysicalField

DBL_length

the diffusive boundary layer subdomain length as a PhysicalField

idx_surface

The coordinate index for the sediment surface

distances

An array of the scaled cell distances of the mesh

depths

An array of the cell center coordinates, with the 0 set at the sediment surface

sediment_mask

A variable named “sed_mask” which is 1 in the sediment subdomain

create_mesh()[source]

Create the fipy mesh for the domain using cell_size and total_cells.

The arrays depths and distances are created, which provide the coordinates and distances of the mesh cells.

create_var(name, store=True, **kwargs)[source]

Create a variable on the mesh as a CellVariable.

If a value is not supplied, then it is set to 0.0. Before creating the cell variable, the value is multiplied with an array of ones of the shape of the domain mesh. This ensures that no single-valued options end up creating an improper variable. As a result, several types for value are valid.

Parameters
  • name (str) – The name identifier for the variable

  • store (bool) – If True, then the created variable is stored in VARS

  • value (float, numpy.ndarray, PhysicalField) – value to set on the variable

  • unit (str) – The physical units for the variable

  • hasOld (bool) – Whether the variable maintains the older values, which is required for numerical solution through time discretization. This should be set to True for the variables of the equations that will be solved.

  • **kwargs – passed to the call to CellVariable.__init__()

Returns

The created variable

Raises
  • ValueError – If name is not a string with len > 0

  • ValueError – If value has a shape incompatible with the mesh

  • RuntimeError – If domain variable with same name already exists & store = True

var_in_sediment(vname)[source]

Convenience method to get the value of domain variable in the sediment

Parameters

vname (str) – Name of the variable

Returns

Slice of the variable in the sediment subdomain

var_in_DBL(vname)[source]

Convenience method to get the value of domain variable in the DBL

Parameters

vname (str) – Name of the variable

Returns

Slice of the variable in the DBL subdomain

set_porosity(porosity)[source]

Set the porosity for the sediment subdomain. The DBL porosity is set to 1.0. The supplied value is set in sediment_porosity.

Parameters

porosity (float) – A value between 0.1 and 0.9

Returns

The instance of the porosity variable

snapshot(base=False)[source]

Returns a snapshot of the domain’s state, with the following structure:

  • depths:
    • “data_static”
      • (depths, dict(unit=”m”))

  • distances:
    • “data_static”
  • metadata
    • cell_size

    • sediment_length

    • sediment_cells

    • DBL_cells

    • DBL_length

    • total_cells

    • total_length

    • sediment_porosity

    • idx_surface

Returns

dict

microbenthos.core.entity module

class microbenthos.core.entity.Entity(name=None, logger=None)[source]

Bases: object

A base class to represent a model entity.

It defines the interface for subclasses for:

name

The name of the entity

classmethod from_params(cls, init_params, post_params=None)[source]

Create entity instance from the given parameters.

The cls path is a string that specificies a class definition to be imported, and initialized with the given parameters. As a result, the returned instance need not be that of the calling class.

Parameters
  • cls (str) – The qualified module.class_name. If no module is in the string, then it is assumed to be “microbenthos”.

  • init_params (dict) – Params to supply to the __init__ of the target class

  • post_params (dict) – Dictionary of params for post_init() if available

Returns

Instance of the entity

Examples

>>> Entity.from_params(cls="Irradiance", ...)
>>> Entity.from_params(cls="microbenthos.Process", ...)
>>> Entity.from_params(cls="sympy.Lambda", ...)
classmethod from_dict(cdict)[source]

Pre-processor for from_params() that extracts and sends the keys “cls”, “init_params” and “post_params”.

Parameters

cdict (dict) – parameters for from_params()

Returns

Instance of the entity created

Raises

KeyError – If the cls key is missing in cdict

post_init(**kwargs)[source]

Hook to customize initialization of entity after construction by from_params().

This must be overriden by subclasses to be useful.

Parameters

**kwargs – arbitrary parameters for post_init()

Returns

None

on_time_updated(clocktime)[source]

Hook to respond to the model clock changing.

This must be overridden by subclasses to be useful.

Parameters

clocktime (float, PhysicalField) – The model clock time.

snapshot()[source]

Returns a snapshot of the entity’s state which will be a node in the nested structure to be consumed by save_snapshot().

Returns

dict – a representation of the state of the entity

restore_from(state, tidx)[source]

Restore the entity from a saved state

tidx is the time index. If it is None, then it is set to slice(None, None) and the entire time series is read out. Typically, tidx = -1, to read out the values of only the last time point.

The state dictionary must be of the structure as defined in snapshot().

Raises

ValueError – if the state restore does not succeed

class microbenthos.core.entity.DomainEntity(**kwargs)[source]

Bases: microbenthos.core.entity.Entity

An Entity that is aware of the model domain (see domain), and serves as the base class for MicrobialGroup, Irradiance, Variable, etc.

This class defines the interface to:

property domain

The domain for the entity

Parameters

domain – An instance of SedimentDBLDomain or similar

Raises

RuntimeError – if domain is already set

set_domain(domain)[source]

Silly method that just does self.domain = domain. Will likely be removed in a future version.

check_domain()[source]

A stricter version of has_domain

Returns

True – if domain is not None

Raises

RuntimeError – if has_domain is False

property has_domain

Returns: True if domain is not None

on_domain_set()[source]

Hook for when a domain is set

To be used by sub-classes to setup sub-entities

setup(**kwargs)[source]

Method to set up the mat entity once a domain is available

This may include logic to add any featuers it has also to the domain.

To be overridden by subclasses

property is_setup

A flag to indicate if an entity still needs setting up

Must be overriden by subclasses to be useful

microbenthos.core.variable module

class microbenthos.core.variable.ModelVariable(create, constraints=None, seed=None, clip_min=None, clip_max=None, **kwargs)[source]

Bases: microbenthos.core.entity.DomainEntity

A class to represent a variable on the model domain.

This class serves as means for defining features such as environmental variables, chemical analytes or microbiological features (biomass). The class allows defining the variable but deferring the initialization of the associated CellVariable until the domain is available.

The interface defined allows to:

__init__(create, constraints=None, seed=None, clip_min=None, clip_max=None, **kwargs)[source]

Configure the creation of a variable and its boundary conditions

Parameters
  • name (str) – The name of the variable

  • create (dict) – parameters for variable creation (see create())

  • constraints (dict) – Mapping of location to value of boundary condition through constrain()

  • seed (dict) – parameters to seed initial value of variable

var

type : fipy.CellVariable

Object created on domain.mesh

create_params

type : dict

Validated dict of params for creation of variable

constraints

mapping of domain location to values for boundary conditions (see constrain())

clip_min

the min value to which the variable array is clipped

clip_max

the max value to which the variable array is clipped

static check_create(**params)[source]

Check that the given params are valid for creating the variable once the domain is available

Parameters
  • name (str) – a required identifier string

  • unit (str) – a string like (“kg/m**3”) that defines the physical units of the variable

  • value (float, ndarray, PhysicalField) – the value to set for the variable. If a PhysicalField is supplied, then its (base) unit is used as unit and overrides any supplied unit.

Returns

dict – the params dictionary to be used

Raises
  • ValueError – if no name is supplied

  • ValueError – if unit is not a valid input for PhysicalField

Note

Due to limitation in fipy (v3.1.3) that meshes do not accept arrays PhysicalField as inputs, the variables defined here are cast into base units since the domain mesh is created in meters.

static check_constraints(constraints)[source]

Check that constraints is a mapping of location to value of boundary conditions. Recognized location values are: “top”, “bottom”.

Raises
  • TypeError if constraints is not a mapping

  • ValueError if loc is not valid

  • ValueError if value is not single-valued

setup(**kwargs)[source]

Once a domain is available, create() the variable with the requested parameters and apply any constraints.

Constraints are specified as:

  • "top" : domain.mesh.facesLeft

  • "bottom" : domain.mesh.facesRight

  • "dbl" : slice(0, domain.idx_surface)

  • "sediment: : slice(domain.idx_surface, None)

Note

The constraints “dbl” and “sediment” are not yet tested to work with fipy equations. It is likely that this formulation may not work correctly.

Specifying both “top” and “dbl” or “bottom” and “sediment” does not currently raise an error, but instead warning messages are logged.

create(value, unit=None, hasOld=False, **kwargs)[source]

Create a CellVariable by calling domain.create_var().

Parameters
  • value (int, float, array, PhysicalField) – the value for the array

  • unit (str) – physical units string for the variable. Is overridden if value is a PhysicalField.

  • hasOld (bool) – flag to indicate that the variable should store the older value separately (see fipy.CellVariable).

Returns

instance of the variable created

Raises
  • RuntimeError – if a domain variable with name already exists, or no mesh exists on the domain.

  • ValueError – if value.shape is not 1 or the domain shape

constrain(loc, value)[source]

Constrain the variable at the given location to the given value

Parameters
  • loc (str) – One of ("top", "bottom", "dbl", "sediment")

  • value (float, PhysicalField) – a numeric value for the constraint

Returns

None

Raises
  • TypeError – if the units for value are incompatible with var units

  • ValueError – for improper values for loc

  • ValueError – if value is not a 0-dimension array

  • RuntimeError – if variable doesn’t exist

seed(profile, **kwargs)[source]

Seed the value of the variable based on the profile and parameters

Available profiles are:

  • “normal”
    • normal distribution of values from scipy.stats.norm

    • loc and scale in units compatible with domain mesh

    • coeff to multiply the distribution with, in units compatible with that of var

    • the normal distribution is created to have unit height for different loc and scale values

  • “linear”
    • uses linspace() to fill the first dimension of var

    • start: the start value given, else taken from constraint “top”

    • stop: the stop value given, else taken from constraint “bottom”

  • “lognormal”
    • lognormal distributuion from scipy.stats.lognorm

    • loc and scale should be in units compatible with domain mesh

    • shape should be a float > 0

    • the distribution is normalized to have max value = 1

Parameters
  • profile (str) – The type of profile to use

  • **kwargs – Parmeters for the profile

Returns

None

Raises

ValueError – if incompatible units encountered

snapshot(base=False)[source]

Returns a snapshot of the variable’s state, with the following structure:

  • data:
    • (var, dict(unit=:meth:.var.unit.name()`)

  • metadata
Parameters

base (bool) – Convert to base units?

Returns

dict – the variable state

restore_from(state, tidx)[source]

Restore the variable from a saved state

It sets the value of the var to that stored in the state.

Parameters
The state dictionary must be of the structure:
  • data: (array, dict(unit=str))

Raises

ValueError – if the state restore does not succeed

microbenthos.core.expression module

class microbenthos.core.expression.Expression(formula=None, name=None, namespace=None, derived=None)[source]

Bases: object

Representation of mathematical expressions as strings to be used for definition of processes in the model domain.

The class relies on sympy to parse the formula, but allows the definition of piecewise functions (in add_piece()) to maintain differentiability of each piece. Calling expr() returns the combined expression of all the pieces, and diff() returns the derivative with respect to a symbol of all the pieces.

Note

As sympify() uses eval() internally, the same caveats apply on processing unvalidated inputs as listed in the sympy docs.

__init__(formula=None, name=None, namespace=None, derived=None)[source]

Create an expression with a symbolic representation

Parameters
  • formula (str, dict) – Definition of a base and possibly piecewise function symbolically. This is processed by parse_formula().

  • name (str) – An identifier for the instance

  • namespace (None, dict) –

    A mapping of symbolic names to expressions to be added to the _sympy_ns. The structure of the dictionary should be

    • name (str)
      • vars (list) : symbols in the expr to be passed to symbols()

      • expr (str) : the expression to be created with Lambda

  • derived (None, dict) – A mapping of symbol to expressions to be added to the _sympy_ns used. This is useful when a complicated subexpression needs to be specified separately.

Examples

Expression(formula = 'x**2 + 3*y')
Expression(formula=dict(base="x**2 + 3*y"))
Expression(formula=dict(
                base="x**2 + 3*y",
                pieces = [
                        dict(where="y>0", expr= "1"),
                        dict(where="y<=0", expr= "0.25*x"),
                        ]))
Expression(formula="3x * myXvar",
           derived=dict(myXvar="sin(x)**(x-0.5/(2-x))"))
base

the base expression as a sympy Expr

parse_formula(formula)[source]

Process the formula and return symbolic expressions for the base and any pieces.

Parameters

formula (str, dict) –

Input should be one of

  • str: which is then only a base expression with no piece-wise definitions.

  • dict: with the structure

    • "base": the base expression string

    • "pieces": a list of dicts where each dict has the structure
      • "where": str that expresses the condition for the functional space

      • "expr: The value of the function in that space

Returns

(base, pieces) – the base expression and a list of piece-wise expressions

Raises

ValueError – Improper input for formula

_sympify(formula)[source]

Run the given formula expression through sympify() using the _sympy_ns namespace.

Parameters

formula (str) – the expression as str

Returns

expr (sympy.core.expr.Expr) – the symbolic expression

Raises

ValueError – if sympify(formula, locals=self._sympy_ns) fails

add_piece(expr, condition)[source]

Add the expr as a piecewise term where condition is valid

Parameters
  • expr (Expr) – The sympy expression

  • condition (int, Expr) – The condition where the expression is active

symbols()[source]
Returns

set – atoms in expr() which are of type Symbol

expr()[source]

Evaluate the symbolic expression

Returns

Expr – full expression including piece-wise definitions

diff(*args)[source]

Compute the differentiation of expr() as symbolic expression

Parameters

*args – input to diff()

Returns

Expr – full expression including piece-wise definitions

microbenthos.core.irradiance module

class microbenthos.core.irradiance.Irradiance(hours_total=24, day_fraction=0.5, channels=None, **kwargs)[source]

Bases: microbenthos.core.entity.DomainEntity

Class that represents a source of irradiance in the model domain.

The irradiance is discretized into separate “channels” (see IrradianceChannel), representing a range of the light spectrum. This is useful to define channels such as PAR ( photosynthetically active radiation) or NIR (near-infrared), etc.

The irradiance has a surface_level which is modulated as cos(time), to mimic the cosinusoidal variation of solar radiance during a diel period. The diel period is considered to run from midnight to midnight. The intensity in each channel is then represented as a fraction of the surface level (set at 100).

__init__(hours_total=24, day_fraction=0.5, channels=None, **kwargs)[source]

Initialize an irradiance source in the model domain

Parameters
  • hours_total (int, float, PhysicalField) – Number of hours in a diel period

  • day_fraction (float) – Fraction (between 0 and 1) of diel period which is illuminated (default: 0.5)

  • channels – See create_channel()

  • **kwargs – passed to superclass

channels

the channels in the irradiance entity

hours_total

the number of hours in a diel period

day_fraction

fraction of diel period that is illuminated

hours_day

numer of hours in the illuminated fraction

zenith_time

the time within the diel period which is the zenith of radiation

zenith_level

the intensity level at the zenith time

surface_irrad

a Variable for the momentary radiance level at the surface

setup(**kwargs)[source]

With an available model instance, setup the defined channels.

property is_setup

Returns: bool: True if all the channels are setup

create_channel(name, k0=0, k_mods=None, model=None)[source]

Add a channel with IrradianceChannel, such as PAR or NIR

Parameters
  • name (str) – The channel name stored in channels

  • k0 (int, PhysicalField) – The base attenuation for this channel through the sediment

  • k_mods (list) – (var, coeff) pairs to add attenuation sources to k0 for the channel

  • model (None, object) – instance of the model, if available

Returns

The created IrradianceChannel instance

on_time_updated(clocktime)[source]

Update the surface irradiance according to the clock time

Parameters

clocktime (PhysicalField) – The model clock time

snapshot(base=False)[source]

Returns a snapshot of the Irradiance’s state with the structure

Parameters

base (bool) – Convert to base units?

Returns

dict – the state dictionary

restore_from(state, tidx)[source]

Restore state of each irradiance channel

class microbenthos.core.irradiance.IrradianceChannel(name, k0=PhysicalField(0, '1/cm'), k_mods=None, **kwargs)[source]

Bases: microbenthos.core.entity.DomainEntity

Class that represents a single scalar irradiance channel in Irradiance

__init__(name, k0=PhysicalField(0, '1/cm'), k_mods=None, **kwargs)[source]

A scalar irradiance channel.

This creates variables for the channel intensities, for the attenuation values.

Parameters
  • name (str) – The channel name

  • k0 (float, PhysicalField) – The base attenuation for this channel through the sediment with units of (1/cm)

  • k_mods (None, list) – (var, coeff) pairs that modify k0 based on the value of the variable pointed at by var (example: “microbes.cyano.biomass”) and multiplied with a coeff. coeff must have the units such that var * coeff has the units of k0.

Raises

ValueError – if the units of k0 are not compatible with 1/cm

intensities

CellVariable to hold the intensities of the irradiance channel through the domain

k0

the base attenuation through the sediment

k_var

variable that represents the net attenuation

k_mods

list of modulations for the attenuation in k0

setup(**kwargs)[source]

Define attenuations when domain is available

This initializes the intensities of the channel through the domain.

Parameters

model (object) – The model object lookups sources for k_mods. It should have a callable get_object(path)()

property k_name

Returns: str: name for the attenuation variable in the domain

define_attenuation()[source]

Create the attenuation k0 for the channel

add_attenuation_source(var, coeff, model=None)[source]

Add an extra source of attenuation to this channel, for example through biomass that attenuates light intensity

Parameters
  • var (str) – The name for the variable as attenuation source. var should be a string to a model variable (example "microbes.cyano.biomass") in which case it is looked up from the model.

  • coeff – The coefficient to multiply with. The term var * coeff should have dimensions of 1/length

  • model (object) – The model object to perform object lookups on if necessary with model.get_object(var)()

Raises

ValueError – If the units of var * coeff not compatible with 1/m

property is_setup

Returns: bool: True if all pending attenuation sources in k_mods have been added

property attenuation_profile

Calculates the attenuation profile for this channel

This returns the cumulative product of attenuation factors in each cell of the domain, allowing this to be multiplied by a surface value to get the irradiance intensity profile.

update_intensities(surface_level)[source]

Update the intensities of the channel based on the surface level

Parameters

surface_level – The variable indicating the surface intensity

Returns

numpy.ndarray – The intensity profile through the domain

snapshot(base=False)[source]

Returns a snapshot of the channel’s state, with the structure

  • “attenuation”
    • “data” : (k_var, dict(unit = k_var.unit))

    • “metadata”
      • “varname”: str(coeff) of the sources in k_mods

  • “intensity” : ( intensities, dict(unit = intensities.unit ) )

  • “metadata”
    • “k0” : str(k0)

Parameters

base (bool) – Convert to base units?

Returns

dict – state dictionary

restore_from(state, tidx)[source]

Restore the intensities from the state

microbenthos.core.microbes module

class microbenthos.core.microbes.MicrobialGroup(features=None, processes=None, **kwargs)[source]

Bases: microbenthos.core.entity.DomainEntity

Class to represent a category of microorganisms, such as cyanobacteria, sulfur bacteria, etc.

This class defines the interface to

  • define features such as biomass, distributed

    through the domain

  • setup processes which the microbes perform on domain entities

__init__(features=None, processes=None, **kwargs)[source]

Initialize a microbial group

Parameters
VARS

container of the fipy Variables belonging to the microbes

processes

the processes of the microbes, which are instances of Process.

add_feature_from(name, **params)[source]

Create a feature and add it it features

Parameters
  • name (str) – name of the feature

  • **params – parameters passed to from_dict()

add_process_from(name, **params)[source]

Create a process and add it it processes

Parameters
  • name (str) – name of the process

  • **params – parameters passed to from_dict()

property biomass

The feature “biomass” stored in features. This is considered as an essential feature for a microbial group. However, no error is raised if not defined currently.

Returns

fipy.CellVariable – biomass variable stored on the domain

on_domain_set()[source]

Set up the domain on the microbial group.

Note

Features, which are handlers for domain variables, receive the domain instances. However processes receive self as the domain, so that variable lookup happens first locally on the instance and then passed on to the domain.

setup(**kwargs)[source]

If the domain is available, then setup all the features and processes.

Store any fipy.CellVariable created in features into VARS.

on_time_updated(clocktime)[source]

When model clock updated, delegate to feature and process instances

snapshot(base=False)[source]

Returns a snapshot of the state with the structure:

Returns

dict – state of the microbial group

restore_from(state, tidx)[source]

Simply delegate to restore_from() of the features and processes

microbenthos.core.process module

class microbenthos.core.process.Process(expr, params=None, implicit=True, events=None, **kwargs)[source]

Bases: microbenthos.core.entity.DomainEntity

Class to represent a reaction occurring in the model domain.

It is used as an adapter to the symbolic formulation in Expression into the model equation terms. By calling evaluate() the symbolic expression, is cast into fipy terms which can be used as fipy.SourceTerm in the model. Additionally, if implicit is set, then the expression will attempted to be cast into a linear and implicit source term which can help the speed of numerical approximation.

__init__(expr, params=None, implicit=True, events=None, **kwargs)[source]

Initialize the process

Parameters
  • expr (dict, Expression) – input for expr of the process

  • params (dict) – mapping of symbolic vars to numerical values uses in expression, typically to represent process parameters or constants.

  • implicit (bool) – Whether to cast the equation as implicit source term (default: True)

  • events (None, dict) – definitions for add_event()

params

the container (dict) for the parameters uses to evaluate() the process

implicit

flag which controls if expression will be cast into linearized and implicit source terms

events

container (dict) of ProcessEvent

property expr

The symbolic expression of the mathematical formulation

Parameters

e (dict, Expression) – if a dict, then it is passed to Expression.__init__() with name = self.name to create the instance.

Returns

Expression

evaluate(expr, params=None, domain=None)[source]

Evaluate the given sympy expression on the supplied domain and param containers.

If domain is not given, then the domain is used. If params is not given, then params is used.

The expr atoms are inspected, and all symbols collected. Symbols that are not found in the params container, are set as variables to be sourced from the domain or events container.

The symbols from the expression are collected, the expression lambdified and then evaluated using the objects sourced from the containers and events.

Parameters
  • expr (int, Expr) – The expression to evaluate

  • params (dict, None) – The parameter container

  • domain (dict, None) – The domain container for variables

Returns

evaluated result typically one of (fipy binOp, numpy.ndarray)

as_source_for(varname, **kwargs)[source]

Cast the expr as a source condition for the given variable name.

If implicit is True, then the expression will be differentiated (symbolically) with respect to variable v (from varname), and the source expression S will be attempted to be split as S1 = dS/dv and S0 = S - S1 * v (see fipy docs).

If implicit is False, then returns (S,0). This also turns out to be the case when the expression S is linear with respect to the variable v.

Finally S0 and S1 are evaluated and returned.

Parameters
  • varname (str) – The variable that the expression is a source for

  • coeff (int, float) – Multiplier for the terms

  • kwargs (dict) – Keyword arguments forwarded to evaluate()

Returns

tuple

A (varobj, S0, S1) tuple, where varobj is the variable evaluated on the

domain, and S0 and S1 are the evaluated source expressions on the domain. If S1 is non-zero, then it indicates it should be cast as an implicit source.

as_term(**kwargs)[source]

Return the process as fipy term by calling evaluate()

repr_pretty()[source]

Return a pretty representation of the expr.

See pretty()

snapshot(base=False)[source]

Returns a snapshot of the state with the structure

Parameters

base (bool) – Convert to base units?

Returns

dict – the process state

restore_from(state, tidx)[source]

Restore the process state. This is a no-op as the term of the process is symbolically defined through fipy.binOp.

add_event(name, **definition)[source]

Add an event to this process through ProcessEvent

Parameters
  • name (str) – Name for the event

  • definition (dict) – definition for the event

Returns:

setup(**kwargs)[source]

Sets up any contained events

on_time_updated(clocktime)[source]

Updates any contained events

class microbenthos.core.process.ProcessEvent(expr, **kwargs)[source]

Bases: microbenthos.core.entity.DomainEntity

Class that represents a temporal event in the domain. Events are useful for tracking the last time at which a certain condition occurred in the domain.

It is represented as a relational expression between different domain variables. When this relation is True, then the time of the event is considered active at that domain depth location. The event time tracks the duration for which the event relation is True. This can be used to model inductive processes in microbial groups, where a certain amount of time is necessary after conditions are met for the metabolic activity to begin.

__init__(expr, **kwargs)[source]

Create the process event by specifying a symbolic expression for the relation between domain variables.

Parameters

expr (dict, Expression) – The relational expression between domain variables in symbolic form

Example

  • “oxy >= OxyThreshold”

  • “(oxy > oxyMin) & (light > lightMin)”

process

The process that this event belongs to

event_time

The depth distribution of the time when the event condition was reached

condition

The event condition expressed through domain variables

property expr

Similar to Process.expr

setup(process, model, **kwargs)[source]

Setup the event time variable that contains the duration since when the event condition was reached at each depth location. The event condition is created by using evaluate().

Parameters
  • process (Process) – The process this event belongs to

  • model (MicroBenthosModel) – The model instance

on_time_updated(clock)[source]

The event_time must be reset, wherever condition evaluates to False. Wherever it evaluates to True, then increment the value by (clock - prev_clock).

Module contents