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

comment: str | dict[str, str] | None
edge_type: str
model_config = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
properties: dict[str, JsonValue] | None
source: Activity | SimModel | None
tags: dict[str, JsonValue] | None
target: Activity | SimModel | None
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: Edge

An quantitative edge linking two nodes in the graph.

amount: Callable
dataset_correction: float | None
default_code: str
default_name: str
description: str | dict[str, str] | None
edge_type: QuantitativeEdgeTypes
loc: float | None
maximum: float | None
minimum: float | None
model_config = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

negative: bool | None
scale: float | None
shape: float | None
uncertainty_type: int | None
class simodin.interface.QuantitativeEdgeTypes(value)[source]

Bases: StrEnum

biosphere = 'biosphere'
characterization = 'characterization'
normalization = 'normalization'
technosphere = 'technosphere'
weighting = 'weighting'
class simodin.interface.SimModel[source]

Bases: ABC

Class 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:

abstractmethod define_flows()[source]

Abstract method to define the model flows.

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

print_technosphere(prop_list)[source]
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: QuantitativeEdge

A biosphere flow.

dataset_unit: Unit | str | None
edge_type: Literal[QuantitativeEdgeTypes.biosphere]
model_config = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_unit: Unit | str | None
simodin.interface.check_params(func)[source]

Decorater for check if all parameter are defined.

class simodin.interface.modelInterface(name, model)[source]

Bases: BaseModel

Class 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.

calculate_impact()[source]

Calculate the impact and returns the allocated impact.

converged: bool
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.

impact: dict
impact_allocated: Dict
impact_dissag: Dict
lca: MultiLCA | None
method_config: Dict
methods: list
model: SimModel
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.

name: str
params: Dict[str, float | int | bool | str] | None
remove_dataset(flow_name)[source]
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

default: float | list | int | str | Quantity | None
description: str | dict[str, str] | None
max: float | int | str | Quantity | None
min: float | int | str | Quantity | None
model_config = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
reference: str | dict[str, str] | None
val: float | list | int | str | Quantity | None
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: QuantitativeEdge

A technosphere flow.

allocationfactor: float | Callable
database: str | None
dataset: str | None
dataset_unit: Unit | str | None
edge_type: Literal[QuantitativeEdgeTypes.technosphere]
functional: bool
impact: dict[str, Quantity | float] | None
model_config = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_unit: Unit | str | None
reference: bool
type: technosphereTypes
simodin.interface.update_params(func)[source]

Decorator for overwrite params before call of concrete methods.

simodin.interface.wrap_init(func)[source]

Decorator executed before __init__ to load default parameters as instance attributes.

Module contents