API documentation for the litter_model module#
The litter_model module creates a
LitterModel class as a child of
the BaseModel class. At present a lot of
the abstract methods of the parent class (e.g.
spinup()) are overwritten using
placeholder functions that don’t do anything. This will change as the Virtual Ecosystem
model develops. The factory method
from_config() exists in
a more complete state, and unpacks a small number of parameters from our currently
pretty minimal configuration dictionary. These parameters are then used to generate a
class instance. If errors crop here when converting the information from the config
dictionary to the required types (e.g. timedelta64) they are caught and
then logged, and at the end of the unpacking an error is thrown. This error should be
caught and handled by downstream functions so that all model configuration failures can
be reported as one.
Classes:
|
A class defining the litter model. |
- class virtual_ecosystem.models.litter.litter_model.LitterModel(data: Data, core_components: CoreComponents, model_constants: LitterConstants = LitterConstants(), static: bool = False)[source]#
A class defining the litter model.
This model can be configured based on the data object and a config dictionary. At present the underlying model this class wraps is quite simple (i.e. two litter pools), but this will get more complex as the Virtual Ecosystem develops.
- Parameters:
data – The data object to be used in the model.
core_components – The core components used across models.
model_constants – Set of constants for the litter model.
static – Boolean flag indicating if the model should run in static mode.
Methods:
Check the init data contains the required variables.
cleanup()Placeholder function for litter model cleanup.
from_config(data, configuration, core_components)Factory function to initialise the litter model from configuration.
spinup()Placeholder function to spin up the litter model.
update(time_index, **kwargs)Function to update the model.
Attributes:
The core constants used in the model.
A Data instance providing access to the shared simulation data.
The Grid details used in the model.
The LayerStructure details used in the model.
Litter chemistry object for tracking of litter pool chemistries.
Set of constants for the litter model.
The ModelTiming details used in the model.
Bounds on model update frequencies.
Variables that are initialised by the model during the first update.
Variables that are initialised by the model during the setup.
Required variables for model initialisation.
Variables that are required by the update method of the model.
Variables that are updated by the model.
- check_init_data() None#
Check the init data contains the required variables.
This method is used to check that the set of variables defined in the
vars_required_for_initclass attribute are present in theDatainstance used to create a new instance of the class.- Raises:
ValueError – If the Data instance does not contain all the required variables or if those variables do not map onto the required axes.
- core_constants: CoreConstants#
The core constants used in the model.
- classmethod from_config(data: Data, configuration: CompiledConfiguration, core_components: CoreComponents) LitterModel[source]#
Factory function to initialise the litter model from configuration.
This function unpacks the relevant information from the configuration file, and then uses it to initialise the model. If any information from the config is invalid rather than returning an initialised model instance an error is raised.
- Parameters:
data – A
Datainstance.configuration – A validated Virtual Ecosystem model configuration object.
core_components – The core components used across models.
- layer_structure: LayerStructure#
The LayerStructure details used in the model.
- litter_chemistry: LitterChemistry#
Litter chemistry object for tracking of litter pool chemistries.
- model_constants: LitterConstants#
Set of constants for the litter model.
- model_timing: ModelTiming#
The ModelTiming details used in the model.
- model_update_bounds: tuple[Quantity, Quantity] = (<Quantity(30, 'minute')>, <Quantity(3, 'month')>)#
Bounds on model update frequencies.
This class attribute defines two time intervals that define a lower and upper bound on the update frequency that can reasonably be used with a model. Models updated more often than the lower bound may fail to capture transient dynamics and models updated more slowly than the upper bound may fail to capture important temporal patterns.
- update(time_index: int, **kwargs: Any) None#
Function to update the model.
If the model is static, the inner update method, self._update will only run once, at most.
- Parameters:
time_index – The index representing the current time step in the data object.
**kwargs – Further arguments to the update method.
- vars_populated_by_first_update: tuple[str, ...] = ('litter_mineralisation_rate_cnp',)#
Variables that are initialised by the model during the first update.
These are the variables that are initialised by the model and stored in the data object when running the update method for the first time. They will be available for other models to use in their update methods but not in the setup methods.
- vars_populated_by_init: tuple[str, ...] = ()#
Variables that are initialised by the model during the setup.
These are the variables that are initialised by the model and stored in the data object when running the setup method and that will be available for other models to use in their own setup or update methods.
- vars_required_for_init: tuple[str, ...] = ('litter_pool_above_metabolic_cnp', 'litter_pool_above_structural_cnp', 'litter_pool_woody_cnp', 'litter_pool_below_metabolic_cnp', 'litter_pool_below_structural_cnp', 'lignin_above_structural', 'lignin_woody', 'lignin_below_structural')#
Required variables for model initialisation.
This class property defines a set of variable names that must be present in the
Datainstance used to initialise an instance of this class. It is a tuple containing zero or more tuples, each providing a variable name and then a tuple of zero or more core axes that the variable must map onto.For example:
(('temperature', ('spatial', 'temporal')),)
- vars_required_for_update: tuple[str, ...] = ('litter_pool_above_metabolic_cnp', 'litter_pool_above_structural_cnp', 'litter_pool_woody_cnp', 'litter_pool_below_metabolic_cnp', 'litter_pool_below_structural_cnp', 'lignin_above_structural', 'lignin_woody', 'lignin_below_structural', 'stem_turnover_cnp', 'root_turnover_cnp', 'foliage_turnover_cnp', 'stem_lignin', 'senesced_leaf_lignin', 'root_lignin', 'herbivory_waste_leaf_cnp', 'herbivory_waste_leaf_lignin', 'litter_consumed_above_metabolic_cnp', 'litter_consumed_above_structural_cnp', 'litter_consumed_woody_cnp', 'litter_consumed_below_metabolic_cnp', 'litter_consumed_below_structural_cnp', 'air_temperature', 'soil_temperature', 'matric_potential')#
Variables that are required by the update method of the model.
These variables should have been initialised by another model or loaded from external sources, but in either case they will be available in the data object.
- vars_updated: tuple[str, ...] = ('litter_pool_above_metabolic_cnp', 'litter_pool_above_structural_cnp', 'litter_pool_woody_cnp', 'litter_pool_below_metabolic_cnp', 'litter_pool_below_structural_cnp', 'lignin_above_structural', 'lignin_woody', 'lignin_below_structural', 'litter_mineralisation_rate_cnp')#
Variables that are updated by the model.
At the moment, this tuple is used to decide which variables to output from the
Dataobject, i.e. every variable updated by a model used in the specific simulation. It is also be used warn if multiple models will be updating the same variable and to verify that these variables are indeed initialised by another model, and therefore will be available.