API for the cnp module#

The cnp module contains the class for managing pools of stoichiometric explicit mass: carbon (C), nitrogen (N), and phosphorus (P).

Classes:

CNP(C, N, P)

A dataclass representing Carbon (C), Nitrogen (N), and Phosphorus (P) mass.

Functions:

find_microbial_stoichiometries(config)

Find the stoichiometries of each microbial functional group.

class virtual_ecosystem.models.animal.cnp.CNP(C: float, N: float, P: float)[source]#

A dataclass representing Carbon (C), Nitrogen (N), and Phosphorus (P) mass.

This class features common operations on CNP mass, including arithmetic manipulations, stoichiometric calculations, and ratio/proportion retrieval.

Variables:
  • C (float) – The mass of carbon in the entity [kg].

  • N (float) – The mass of nitrogen in the entity [kg].

  • P (float) – The mass of phosphorus in the entity [kg].

Methods:

from_dict(data)

Create a CNP instance from a dictionary.

get_proportions()

Calculate the proportion of each element relative to the total CNP mass.

get_ratios()

Calculate the Carbon:Nitrogen (C:N) and Carbon:Phosphorus (C:P) ratios.

update(*[, C, N, P])

Update C, N, and P values.

Attributes:

total

Calculate the total combined mass of C, N, and P.

classmethod from_dict(data: dict[str, float]) CNP[source]#

Create a CNP instance from a dictionary.

Parameters:

data (dict[str, float]) – A dictionary containing ‘C’, ‘N’, and ‘P’ as keys.

Returns:

A new CNP instance with the values from the dictionary.

Return type:

CNP

get_proportions() dict[str, float][source]#

Calculate the proportion of each element relative to the total CNP mass.

If the total mass is zero, proportions are set to zero to avoid division errors.

Returns:

A dictionary containing:
  • ”C” (float): Proportion of carbon in total mass.

  • ”N” (float): Proportion of nitrogen in total mass.

  • ”P” (float): Proportion of phosphorus in total mass.

Return type:

dict[str, float]

get_ratios() dict[str, float][source]#

Calculate the Carbon:Nitrogen (C:N) and Carbon:Phosphorus (C:P) ratios.

TODO: finalize alternative output with jacob

Returns:

A dictionary containing:
  • ”C:N” (float): Carbon-to-nitrogen ratio

  • ”C:P” (float): Carbon-to-phosphorus ratio

Return type:

dict[str, float]

property total: float#

Calculate the total combined mass of C, N, and P.

Returns:

The sum of carbon, nitrogen, and phosphorus mass.

Return type:

float

update(*, C: float = 0.0, N: float = 0.0, P: float = 0.0) None[source]#

Update C, N, and P values. Positive values add; negative values subtract.

Parameters:
  • C – Amount of carbon to adjust. Defaults to 0.0.

  • N – Amount of nitrogen to adjust. Defaults to 0.0.

  • P – Amount of phosphorus to adjust. Defaults to 0.0.

virtual_ecosystem.models.animal.cnp.find_microbial_stoichiometries(config: CompiledConfiguration) dict[str, dict[str, float]][source]#

Find the stoichiometries of each microbial functional group.

This extracts the soil configuration from the simulation configuration and then compiles a dictionary of CN and CP ratios for each microbial group.

Parameters:

config – A compiled Virtual Ecosystem configuration instance.

Returns:

A dictionary containing the carbon to nutrient ratios of each microbial functional group, for both nitrogen and phosphorus [unitless]