simodin package¶
Subpackages¶
Submodules¶
simodin.interface module¶
- class simodin.interface.Edge(*, edge_type: str, source: Activity | SimModel | None = None, target: Activity | SimModel | None = None, comment: str | dict[str, str] | None = None, tags: dict[str, JsonValue] | None = None, properties: dict[str, JsonValue] | None = None, name: str)[source]¶
Bases:
BaseModel- model_config = {'arbitrary_types_allowed': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class simodin.interface.QuantitativeEdge(*, edge_type: QuantitativeEdgeTypes, source: Activity | SimModel | None = None, target: Activity | SimModel | None = None, comment: str | dict[str, str] | None = None, tags: dict[str, JsonValue] | None = None, properties: dict[str, JsonValue] | None = None, name: str, amount: Callable, uncertainty_type: int | None = None, loc: float | None = None, scale: float | None = None, shape: float | None = None, minimum: float | None = None, maximum: float | None = None, negative: bool | None = None, description: str | dict[str, str] | None = None, default_name: str = '', default_code: str = '', dataset_correction: float | None = None)[source]¶
Bases:
EdgeAn quantitative edge linking two nodes in the graph.
- edge_type: QuantitativeEdgeTypes¶
- model_config = {'arbitrary_types_allowed': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class simodin.interface.QuantitativeEdgeTypes(value)[source]¶
Bases:
StrEnum- biosphere = 'biosphere'¶
- characterization = 'characterization'¶
- normalization = 'normalization'¶
- technosphere = 'technosphere'¶
- weighting = 'weighting'¶
- class simodin.interface.SimModel[source]¶
Bases:
ABCClass containing a simulation model.
- Parameters:
name – model name.
init_arg – Arguments needed for initialising the model.
**model_params – Parameters for the simulation Model.
- add_flow(flow: technosphere_edge | biosphere_edge)[source]¶
Add a flow to the flow dicts.
- Parameters:
flow – Flow to be added.
- property biosphere¶
- abstractmethod calculate_model(**model_params)[source]¶
Abstract method to calculate the model based on the parameters provided.
- property citation¶
Citation of the model:
- description = ''¶
- abstractmethod init_model(**model_params)[source]¶
Abstract method to initiate the model.
- Parameters:
**model_params – Parameters for the simulation Model.
- parameters = {}¶
self.name = name self.ureg=pint.UnitRegistry() # check and create parameter dict: self.params = model_params for _, p in self.__class__.parameters.items():
- if p.name not in model_params and p.default == None:
- raise Exception(
f’’’The parameter {p.name} is not defined. it mus be passed as parameter in the __init__ method or be defined as default parameter in the class definition.’’’ )
- elif p.name not in model_params and p.default != None:
self.params[p.name]= p.default
undefined_params= [p for p in model_params if p not in self.__class__.parameters] if len(undefined_params) >0:
- raise Warning(
f’’’The parameters {list(undefined_params)} are not defined for this model. No validy check possible for this parameter. Please check if the parameter name is correct and if it is defined in the model class definition.’’’ )
self.location = ‘GLO’ #self.init_model(init_arg, **model_params) #self.define_flows() self.converges= False
- recalculate_model(**model_params)[source]¶
Method to recalculate the model based on the parameters provided. Executes a new initialising and calculation of the model. Might be overwritten if a better and faster way to recalculate the model is possible.
- reference = {'author': '', 'key': '', 'license': '', 'title': '', 'type': 'misc', 'url': ''}¶
- set_flow_attr(flow_name, flow_property, value)[source]¶
Set a property of a flow.
- Parameters:
flow_name – Name of the flow to be set.
flow_property – Property of the flow to be set.
value – Value to be set.
- property technosphere¶
- class simodin.interface.biosphere_edge(*, edge_type: Literal[QuantitativeEdgeTypes.biosphere] = QuantitativeEdgeTypes.biosphere, source: Activity | SimModel | None = None, target: Activity | SimModel | None = None, comment: str | dict[str, str] | None = None, tags: dict[str, JsonValue] | None = None, properties: dict[str, JsonValue] | None = None, name: str, amount: Callable, uncertainty_type: int | None = None, loc: float | None = None, scale: float | None = None, shape: float | None = None, minimum: float | None = None, maximum: float | None = None, negative: bool | None = None, description: str | dict[str, str] | None = None, default_name: str = '', default_code: str = '', dataset_correction: float | None = None, model_unit: Unit | str | None = None, dataset_unit: Unit | str | None = None)[source]¶
Bases:
QuantitativeEdgeA biosphere flow.
- model_config = {'arbitrary_types_allowed': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class simodin.interface.modelInterface(name, model)[source]¶
Bases:
BaseModelClass for interface external simulation models with brightway25.
Attributes:¶
name: Name of the model. model: The Simulation model as SimModel class.
- add_dataset(flow_name, dataset)[source]¶
Link a brightway25 dataset to a model flow.
- Parameters:
flow_name – Name of the flow to be linked.
dataset – Brightway25 dataset to be linked.
- calculate_background_impact()[source]¶
Calculate the background impact based on the parameters provided.
- export_to_bw(database=None, identifier=None)[source]¶
Export the model to a brightway dataset. Creates the database simulation_model_db if no database is passed. Creates a identifier by the model name, functional unit flow name, and a time stamp if none is passed.
- Parameters:
database – Database in which the model activity should be exported. Default is “simodin_db”
identifier – code for the brightway activity. If empty, the activity code will be created by the name of the mode, the name of the functional flow, and a timestamp. If provided but multifunctional, it will create a dataset for each with a code consisting of the name of the functional flow and the provided identifier.
- model_config = {'arbitrary_types_allowed': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context: Any, /) None¶
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
- ureg: UnitRegistry¶
- class simodin.interface.parameter(*, name: str, val: float | list | int | str | Quantity | None = None, default: float | list | int | str | Quantity | None, min: float | int | str | Quantity | None = None, max: float | int | str | Quantity | None = None, description: str | dict[str, str] | None = None, reference: str | dict[str, str] | None = None)[source]¶
Bases:
BaseModel- model_config = {'arbitrary_types_allowed': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class simodin.interface.technosphereTypes(value)[source]¶
Bases:
StrEnum- input = 'input'¶
- output = 'output'¶
- product = 'product'¶
- substitution = 'substitution'¶
- class simodin.interface.technosphere_edge(*, edge_type: Literal[QuantitativeEdgeTypes.technosphere] = QuantitativeEdgeTypes.technosphere, source: Activity | SimModel | None = None, target: Activity | SimModel | None = None, comment: str | dict[str, str] | None = None, tags: dict[str, JsonValue] | None = None, properties: dict[str, JsonValue] | None = None, name: str, amount: Callable, uncertainty_type: int | None = None, loc: float | None = None, scale: float | None = None, shape: float | None = None, minimum: float | None = None, maximum: float | None = None, negative: bool | None = None, description: str | dict[str, str] | None = None, default_name: str = '', default_code: str = '', dataset_correction: float | None = None, functional: bool = False, reference: bool = False, model_unit: Unit | str | None = None, dataset_unit: Unit | str | None = None, allocationfactor: float | Callable = 1.0, type: technosphereTypes, database: str | None = None, dataset: str | None = None, impact: dict[str, Quantity | float] | None = None)[source]¶
Bases:
QuantitativeEdgeA technosphere flow.
- model_config = {'arbitrary_types_allowed': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- type: technosphereTypes¶