MyClimateModel(start_year, end_year, specie_name, specie_inventory, specie_settings, model_settings)
Bases: ClimateModel
Template class for climate model implementations.
Example
>>> import numpy as np
>>> from aerocm.climate_models.template import MyClimateModel
>>> start_year = 2020
>>> end_year = 2050
>>> specie_name = "species_1"
>>> specie_inventory = np.random.rand(end_year - start_year + 1) * 1e9 # Example emission profile
>>> specie_settings = {"param2": 0.5}
>>> model_settings = {"model_setting_1": np.array([0.1, 0.2, 0.3])}
>>> climate_model = MyClimateModel(
... start_year,
... end_year,
... specie_name,
... specie_inventory,
... specie_settings,
... model_settings
... )
>>> results = climate_model.run(return_df=True)
Source code in aerocm/utils/classes.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 | def __init__(
self,
start_year: int,
end_year: int,
specie_name: str,
specie_inventory: list | np.ndarray,
specie_settings: dict,
model_settings: dict,
):
"""Initialize the climate model with the provided settings.
Parameters
----------
start_year : int
Start year of the simulation.
end_year : int
End year of the simulation.
specie_name : str
Name of the species.
specie_inventory : list or np.ndarray
Emission profile for the species.
specie_settings : dict
Dictionary containing species settings.
model_settings : dict
Dictionary containing model settings.
"""
# --- Validate parameters ---
self.validate_model_settings(model_settings)
self.validate_specie_settings(specie_name, specie_settings)
self.validate_inventory(start_year, end_year, specie_inventory)
# --- Store parameters ---
self.start_year = start_year
self.end_year = end_year
self.specie_name = specie_name
self.specie_inventory = specie_inventory
self.specie_settings = specie_settings
self.model_settings = model_settings
|
run
Run the climate model with the assigned input data.
Returns:
| Name | Type |
Description |
output_data |
dict
|
Dictionary containing the results of the climate model.
|
Source code in aerocm/climate_models/template.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 | def run(self, return_df: bool = False) -> dict | pd.DataFrame:
"""Run the climate model with the assigned input data.
Returns
-------
output_data : dict
Dictionary containing the results of the climate model.
"""
# --- Extract model settings ---
model_setting_1 = self.model_settings["model_setting_1"]
# --- Extract species settings ---
specie_settings = self.specie_settings
param1 = specie_settings.get("param1", 1.0) # replace 2nd argument with default if needed
param2 = specie_settings.get("param2", 1.0)
param3 = specie_settings.get("param3", 1)
# --- Run the climate model ---
# Placeholder implementation - replace with actual model logic
radiative_forcing = self.specie_inventory * param1
effective_radiative_forcing = radiative_forcing * param2
cumulative_effective_radiative_forcing = np.cumsum(effective_radiative_forcing)
temperature = model_setting_1 * cumulative_effective_radiative_forcing * param3
# --- Prepare output data ---
output_data = {
"radiative_forcing": radiative_forcing,
"effective_radiative_forcing": effective_radiative_forcing,
"temperature": temperature
}
if return_df:
years = np.arange(self.start_year, self.end_year + 1)
output_data = pd.DataFrame(output_data, index=years)
return output_data
|