appabuild.database.serialized_data#
This module contains classes to make the interface between serialized data (such as json and yaml). Main purposes of those classes are to check serialized data schema and realize operations on those fields. Classes of this module are not environment-aware, i.e. they have no information about LCA context (background databases, functional unit, LCA parameters…).
Attributes#
Classes#
Contain a set of characteristics to identify an activity. An ActivityIdentifier is |
|
SerializedActivity is the easiest way to import user datasets, as Activity |
|
SerializedExchange is the easiest way to import user datasets, as Exchange |
|
Is used to handle categorical parameters, allowing to map to different exchange |
|
For each attribute different than None, will replace exchange's attribute value. |
Module Contents#
- class appabuild.database.serialized_data.ActivityIdentifier#
Bases:
pydantic.BaseModel
Contain a set of characteristics to identify an activity. An ActivityIdentifier is considered as unresolved is uuid is not defined. An unresolved ActivityIdentifier can be defined by its name and location.
- to_dict()#
Convert self to dict. :return: self as a dict
- property code: str#
Brightway refers to uuid as ‘code’. This property helps to harmonize with Activity class’s code attribute. :return: object’s uuid
- database: str#
- property is_unresolved: bool#
An ActivityIdentifier is considered as unresolved is uuid is not defined. :return: True if object is unresolved.
- location: str | None = None#
- name: str | None = None#
- uuid: str | None = None#
- class appabuild.database.serialized_data.SerializedActivity#
Bases:
pydantic.BaseModel
SerializedActivity is the easiest way to import user datasets, as Activity class can use SerializedActivity objects to create Brightway compatible datasets.
- to_dict()#
Convert self to dict. :return: self as a dict
- to_yaml(filepath: str)#
Convert self to yaml file. :param filepath: filepath of the yaml file to create.
- amount: float | None = 1#
Amount of output flow generated for given amount of exchanges.
- property code#
Brightway refers to uuid as ‘code’. This property helps to harmonize with Activity class’s code attribute. :return: object’s uuid
- comment: str | None = None#
Free text for any context information about the dataset.
- data_quality: Dict[str, int] | None = None#
Deprecated.
- database: str#
Name of the user database.
- exchanges: List[SerializedExchange] = []#
Emissions or consumptions generated when a unit of the activity is used.
- include_in_tree: bool | None = False#
If True, activity will become a node in built ImpactModel.
- location: str | None = 'GLO'#
Location of the activity. Default value is GLO for global.
- name: str#
Name of the activity. Should be unique if include_in_tree is True, else, a suffix will be generated.
- parameters: List[str] | None = []#
Optional list of parameters necessary to execute this dataset.
- properties: Dict[str, str | float | bool] | None#
Properties will remain on impact model, and can be used by apparun to breakdown the results according to life cycle phase, for exemple. Properties can be key/value (ex: {“phase”: “production”} or flags (ex: {production_phase: True}).
- type: str | None = None#
According to Brightway, can be production, technosphere, or biosphere.
- unit: str#
Unit of the amount.
- uuid: str#
Must be unique in the user database.
- class appabuild.database.serialized_data.SerializedExchange#
Bases:
pydantic.BaseModel
SerializedExchange is the easiest way to import user datasets, as Exchange class can use SerializedExchange objects to create Brightway compatible datasets. Exchange are connection between an input and an output dataset. Contrarily to Brightway, the later is not explicitly indicated and will always be affected to the calling Activity.
- resolve_switch() List[SerializedExchange] #
Generates one SerializedExchange per switch option (switch option being possible value of corresponding categorical parameter). One-hot encoded representation of the parameter is multiplied to exchange’s quantity, resulting in a exchange being toggled or not depending on the categorical parameter’s value during execution. :return: one SerializedExchange per switch option.
- to_dict()#
Convert self to dict. :return: self as a dict
- amount: float | str | None = None#
Quantity of input required to generate the output. Can be a fixed quantity or a formula.
- comment: str | None = None#
Free text for any context information about the exchange.
- database: str = None#
Name of the user database.
- input: ActivityIdentifier | None = None#
Identifier of the downstream Activity.
- name: str#
Name of the exchange. Can be used to dynamically name ImpactModel node.
- parameters_matching: Dict[str, float | str | Dict[str, int]] | None#
Name or values of input’s parameters can be dynamically changed. Key is the name of the input parameter’s name to change, and value the replacing variable. A float will set the parameter to a fixed value, str will update parameter’s name or affect it to a formula, and dict is used to fix value of a categorical parameter.
- switch: Switch | None = None#
Used to handle categorical parameters, allowing to map to different exchange parameterization depending on parameter’s value. In practice, will generate one exchange per possible value by one-hot encoding the parameter.
- type: str | None = None#
- use_exchange_name: bool = False#
Replace input’s name by exchange’s name. Useful if an Activity is used several times as a node for ImpactModel tree.
- class appabuild.database.serialized_data.Switch#
Bases:
pydantic.BaseModel
Is used to handle categorical parameters, allowing to map to different exchange parameterization depending on parameter’s value. In practice, will generate one exchange per possible value (=switch option) when resolved by one-hot encoding the parameter.
- name: str#
Name of the corresponding categorical parameter.
- options: List[SwitchOption]#
One option per possible corresponding categorical parameter value, use to replace exchange’s attribute values.
- class appabuild.database.serialized_data.SwitchOption#
Bases:
pydantic.BaseModel
For each attribute different than None, will replace exchange’s attribute value. For field description, please refer to SerializedExchange documentation, except for name.
- amount: float | str | None = None#
- input: Dict[str, str] | None = None#
- name: str#
Name of the corresponding categorical parameter’s value.
- parameters_matching: Dict[str, float | str | Dict[str, int]] | None#
- type: str | None = None#
- unit: str | None = None#
- appabuild.database.serialized_data.yaml#