Use SiModIn models¶
In this tutorial the setup of SiModIn models is shown. Furthermore the calculation of the LCA scores of the models, and the export to brightway25 datasets is described with an example.
Initialization¶
To use an existing SiModIn model, import and initialize the SimModel class:
from simodin import interface as link
from your_simodin_model_file import your_simodin_model_class
my_model= your_simodin_model_class('model_name')
With the attributes:
name: Name of the model.init_arg: Initialization arguments for the model.**model_params: Model Parameter.
Then initialize and calculate the model by calling the respective methods:
my_model.init_model()
my_model.calculate_model()
LCA setup¶
With define_flows, the flows of the model can be set up for LCA calculations:
my_model.define_flows()
For the LCA calculations, create a modelInterface instance by passing the model name and the SiModIn model object:
my_interface= link.modelInterface('model_name',my_model)
The modelInterface class links the SiModIn model to Brightway2 for LCA calculations. After initializing and calculating the model, call the define_flows method to set up the flows for LCA.
The LCA datasets can then be added to the model interface using the add_dataset method:
my_interface.add_dataset('technosphere_flow_A', bw25_activity_A)
my_interface.add_dataset('technosphere_flow_B', bw25_activity_B)
For the LCIA, the impact categorization method needs to be set by set the methods property.
#define impact method:
my_interface.methods=[('ecoinvent-3.11',
'EF v3.1',
'climate change',
'global warming potential (GWP100)')]
LCA calculation¶
The impact can be calculated by calling calculate_background_impact method, followed by the calculate_impact method:
my_interface.calculate_background_impact()
total_impact = my_interface.calculate_impact()
print("Total Impact:", total_impact)
Unit transformation
An unit transformation logic based on Pint is implemented in the modelInterface classs.
This works only when all of the following requirements are met:
brightway dataset:
the flow got a
unitproperty which is compatible with the default Pint unitsor the linked brightway activity got a
unitproperty which is compatible with the default Pint units
model flow:
the value returned by the model flow property
amountis a Pint quantityor the model flow property
model_unitis defined and is compatible with the default Pint units
The units must be compatible, otherwise an error is raised.
If the requirements are not met, a warning is raised and no transformation is done.
Export to a brightway25 dataset¶
Then, the model result can be exported to a brightway25 activity using the export_to_bw method.
The name of the activity can be passed as an argument, or it will use a string created by the model name,
the name of the functional unit and a time stamp.
The brightway25 database can also be specified, otherwise the default database simodin_db will be used.
code= my_interface.export_to_bw(
activity_name='my_simodin_model_activity',
database_name='my_simodin_db')