pycopanlpjml.Component#
- class pycopanlpjml.Component(config_file=None, lpjml=None, lpjml_couplerversion=3, lpjml_host='localhost', lpjml_port=2042, **kwargs)[source]#
Bases:
objectAn LPJmL-integrating mixin model component to build copan:LPJmL models.
The model component initializes the LPJmL coupler and establishes a connection to the LPJmL model. It provides a method to initialize cell instances and an update method to exchange input and output data with LPJmL while updating the output in world and implicitly in the corresponding cells through (numpy) views. It acts as a mixin to enable integrated copan:LPJmL modeling and to be combined with further model components in a model class.
- Parameters:
config_file (str) – File path to the integrated model configuration file.
lpjml (LPJmLCoupler) – LPJmL coupler instance.
lpjml_couplerversion (int) – LPJmL coupler version.
lpjml_host (str) – Hostname of the LPJmL coupler.
lpjml_port (int) – Port of the LPJmL coupler.
kwargs (dict, optional) – Additional keyword arguments.
- Returns:
An instance of the LPJmL component.
- Return type:
Examples
class StopFertilizationModel(lpjml.Component): name = "Model to simulate a stop global artificial fertilization." def __init__(self, stop_year, **kwargs): super().__init__(**kwargs) # initialize LPJmL world self.world = lpjml.World( input=self.lpjml.read_input(copy=False), output=self.lpjml.read_historic_output(), grid=self.lpjml.grid, country=self.lpjml.country, ) # initialize cells self.init_cells(cell_class=lpjml.Cell) def stop_fertilization(self, t, stop_year): if t == stop_year: self.world.input.fertilization.values[:] = 0 def update(self, t): self.stop_fertilization(t) self.update_lpjml(t) # Create and run the model model = StopFertilizationModel( config_file="path/to/config_file.json", stop_year=2025 ) for year in model.lpjml.get_sim_years(): model.update(year)
- init_cells(cell_class, world_views=None, **kwargs)[source]#
- Initialize cell instances for each corresponding cell via numpy
views.
- Parameters:
cell_class (Cell) – Cell class to be instantiated for each cell.
world_views (list, optional) – List of world attributes which are are of type xarray.Dataarray, xarray.DataSet, pycoupler.LPJmLData or pycoupler.LPJmLDataSet to generate cell views from, to access corresponding cell entity data.
kwargs (dict, optional) – Additional keyword arguments for cell instances.