Model (Main)

Simulation/calculation wrapper for GHG emission models.

This module is designed to handle a variety of inputs, configure settings for different calculation methods, and produce detailed emission reports.

The main components of this module include:

  1. Configurations:
    • The module reads configurations from a file to set default calculation methods and other options.

    • Configuration options are read from config/config.ini and include methods for retention coefficient calculation, phosphorus export calculation, and nitrous oxide emission calculation.

  2. Inputs Handling:
    • The Inputs class is used to manage and validate input data required for the simulations.

    • This includes catchment data, reservoir data, monthly temperature data, and other relevant parameters.

  3. Temperature Calculations:
    • The MonthlyTemperature class is used to handle monthly temperature data which is crucial for estimating gas emissions.

    • Effective temperature calculations are performed for different gases such as CO2, CH4, and N2O.

  4. Emissions Calculations:
    • Separate classes for each gas (CarbonDioxideEmission, MethaneEmission, NitrousOxideEmission) handle the specific calculations for each type of emission.

    • These classes utilize the inputs and configurations to compute emission profiles, total emissions, diffusion fluxes, and other relevant metrics.

  5. Presenter and Writer:
    • The Presenter class is responsible for formatting and presenting the results of the calculations.

    • Multiple writers can be added to the presenter to output data in different formats (e.g., CSV, JSON).

  6. Utility Functions:
    • Utility functions such as create_exec_dictionary help in organizing and managing the execution of various emission calculations.

    • Functions for adding presenters and saving results streamline the workflow for generating and exporting reports.

This module is designed to be flexible and extensible, allowing for easy integration of new calculation methods, input types, and output formats. It supports detailed logging and error handling to facilitate debugging and ensure robust performance.

Typical usage involves:
  1. Creating an EmissionModel object with appropriate inputs and configurations.

  2. Running the calculate method to perform the emissions calculations.

  3. Adding a presenter with desired output formats.

  4. Saving the results to specified files.

Example:

from reemission import EmissionModel, Inputs, Writer

# Initialize inputs
inputs = Inputs(input_data)

# Create emission model
model = EmissionModel(inputs=inputs, config='path/to/config.yaml')

# Calculate emissions
model.calculate()

# Add presenters for output
model.add_presenter(writers=[Writer], output_files=['output.csv'])

# Save results
model.save_results()

Note

Ensure the configuration file and input data are properly formatted and validated before running the calculations.

class reemission.model.EmissionModel(inputs: ~reemission.input.Inputs, config: ~typing.Dict | ~pathlib.Path | str, outputs: ~typing.Dict = <factory>, internal: ~typing.Dict = <factory>, author: str = '', report_title: str = 'Results', ret_coeff: str = 'empirical', p_model: str = 'g-res', n2o_model: str = 'model_1', presenter: ~reemission.presenter.Presenter | None = None)[source]

Calculates emissions for a reservoir or a number of reservoirs.

inputs

Inputs object with input data.

Type:

Inputs

config

Dictionary with configuration data or path to config file.

Type:

Union[Dict, pathlib.Path, str]

outputs

Emission calculation outputs in a dictionary structure.

Type:

Dict

internal

Internal variables for calculations.

Type:

Dict

author

Author’s name.

Type:

str

report_title

Title of output report / GHG emission estimation study.

Type:

str

ret_coeff

Reservoir retention coefficient calculation model.

Type:

str

p_model

P export calculation method.

Type:

str

n2o_model

Nitrous Oxide calculation method.

Type:

str

presenter

Presenter object for presenting input and output data in various formats.

Type:

Optional[Presenter]

__post_init__() None[source]

Initialize outputs dict an load config file if config is a path.

add_presenter(writers: List[Type[Writer]], output_files: List[str]) None[source]

Instantiate a presenter class to the emission model for data output formatting.

Parameters:
  • writers (List[Type[Writer]]) – List of presenter.Writer objects.

  • output_files (List[str]) – Paths to output files, one per writer.

author: str = ''
calculate() None[source]

Calculate emissions for a number of variables defined in config.

config: Dict | Path | str
static create_exec_dictionary(co2_em: CarbonDioxideEmission | None, ch4_em: MethaneEmission | None, n2o_em: NitrousOxideEmission | None, years: Tuple[int, ...] = (1, 5, 10, 20, 30, 40, 50, 100)) Dict[source]

Create a dictionary with function references and arguments for calculating gas emissions.

Parameters:
  • co2_em (Union[CarbonDioxideEmission, None]) – CarbonDioxideEmission object.

  • ch4_em (Union[MethaneEmission, None]) – MethaneEmission object.

  • n2o_em (Union[NitrousOxideEmission, None]) – NitrousOxideEmission object.

  • years (Tuple[int, ...]) – Vector of years for which the emission profiles are calculated.

Returns:

Dictionary with function references and arguments for gas emissions calculations.

Return type:

Dict

inputs: Inputs
internal: Dict
n2o_model: str = 'model_1'
outputs: Dict
p_model: str = 'g-res'
presenter: Presenter | None = None
report_title: str = 'Results'
ret_coeff: str = 'empirical'
save_results() None[source]

Save results using presenters defined in the presenters list.