New Wurst Database
- class premise.ecoinvent_modification.NewDatabase(*args: Any, **kwargs: Any)
Database Cleaner
- class premise.clean_datasets.DatabaseCleaner(source_db: str, source_type: str, source_file_path: Path, version: str)
Class that cleans the datasets contained in the inventory database for further processing.
- Variables:
source_type (str) – type of the database source. Can be ´brightway´ or ‘ecospold’.
source_db (str) – name of the source database if source_type == ‘brightway’
source_file_path (str) – filepath of the database if source_type == ‘ecospold’.
- add_location_field_to_exchanges() None
Add the location key to the production and technosphere exchanges in
database.- Raises:
IndexError – if no corresponding activity (and reference product) can be found.
- add_product_field_to_exchanges() None
Add the product key to the production and technosphere exchanges in
database.For production exchanges, use the value of the reference_product field. For technosphere exchanges, search the activities in
databaseand use the reference product.- Raises:
IndexError – if no corresponding activity (and reference product) can be found.
- correct_biogas_activities()
Some activities producing biogas are not given any biogenic CO2 or energy input, leading to imbalanced carbon and energy flows when combusted.
- find_location_given_lookup_dict(lookup_dict: Dict[str, str]) List[str]
Return a list of location names, given the filtering conditions given in lookup_dict. It is, for example, used to return a list of location names based on the name and the unit of a dataset.
- Parameters:
lookup_dict – a dictionary with filtering conditions
- Returns:
a list of location names
- find_product_given_lookup_dict(lookup_dict: Dict[str, str]) List[str]
Return a list of location names, given the filtering conditions given in lookup_dict. It is, for example, used to return a list of location names based on the name and the unit of a dataset.
- Parameters:
lookup_dict – a dictionary with filtering conditions
- Returns:
a list of location names
- fix_biosphere_flow_categories() None
Add a categories for biosphere flows if missing. This happens when importing directly from ecospold files
- fix_unset_technosphere_and_production_exchange_locations(matching_fields: Tuple[str, str] = ('name', 'unit')) None
Give all the production and technopshere exchanges with a missing location name the location of the dataset they belong to. Modifies in place (does not return anything).
- Parameters:
matching_fields (tuple) – filter conditions
- prepare_datasets(keep_uncertainty_data) List[dict]
Clean datasets for all databases listed in scenarios: fix location names, remove empty exchanges, etc.
- transform_parameter_field() None
Transform the parameter field of the database to a dictionary.
Inventory Imports
- class premise.inventory_imports.BaseInventoryImport(database: List[dict], version_in: str, version_out: str, path: str | Path, system_model: str, keep_uncertainty_data: bool = False)
Base class for inventories that are to be merged with the wurst database.
- Variables:
database – the target database for the import (the ecoinvent database),
unpacked to a list of dicts :ivar version_in: the ecoinvent database version of the inventory to import :ivar version_out: the ecoinvent database version the imported inventories should comply with :ivar path: the filepath of the inventories to import
- __init__(database: List[dict], version_in: str, version_out: str, path: str | Path, system_model: str, keep_uncertainty_data: bool = False) None
Create a
BaseInventoryImportinstance.
- add_biosphere_links() None
Add links for biosphere exchanges to
import_dbModifies theimport_dbattribute in place.
- add_product_field_to_exchanges() None
Add the product key to the production and technosphere exchanges in
import_db. Also add code field if missing. For production exchanges, use the value of the reference_product field. For technosphere exchanges, search the activities inimport_dband use the reference product. If none is found, search the Ecoinventdatabase. Modifies theimport_dbattribute in place. :raises IndexError: if no corresponding activity (and reference product) can be found.
- check_for_already_existing_datasets() None
Check whether the inventories to be imported are not already in the source database.
- check_units() None
Check that the units of the exchanges are compliant with the ecoinvent database. :returns: Nothing
- correct_product_field(exc: tuple) [<class 'str'>, None]
Find the correct name for the product field of the exchange :param exc: a dataset exchange :return: name of the product field of the exchange
- display_unlinked_exchanges()
Display the list of unlinked exchanges using prettytable
- load_inventory() None
Load an inventory from a specified path. Sets the
import_dbattribute. :returns: Nothing.
- merge_inventory() List[dict]
Prepare
import_dband merge the inventory to the ecoinventdatabase. Callsprepare_inventory(). Changes thedatabaseattribute. :returns: Nothing
- prepare_inventory() None
Prepare the inventory for the merger with Ecoinvent. Modifies
import_dbin-place. :returns: Nothing
- remove_ds_and_modifiy_exchanges(name: str, ex_data: dict) None
Remove an activity dataset from
import_dband replace the corresponding technosphere exchanges by what is given as second argument. :param str name: name of activity to be removed :param dict ex_data: data to replace the corresponding exchanges :returns: Nothing
- search_missing_exchanges(label: str, value: str) List[dict]
Return a list of activities for which a given exchange cannot be found :param label: the label of the field to look for :param value: the value of the field to look for :return:
- search_missing_field(field: str, scope: str = 'activity') List[dict]
Find exchanges and activities that do not contain a specific field in
imort_db:param str field: label of the field to search for. :param scope: “activity” or “all”. whether to search in the activity or the activity and its exchanges :returns: a list of dictionaries, activities and exchanges :rtype: list
Remind Data Collection
- class premise.data_collection.IAMDataCollection(model: str, pathway: str, year: int, filepath_iam_files: Path, key: bytes, external_scenarios: dict | None = None, system_model: str = 'cutoff', system_model_args: dict | None = None, gains_scenario: str = 'CLE', use_absolute_efficiency: bool = False)
- Variables:
model – name of the IAM model (e.g., “remind”)
pathway – name of the IAM scenario (e.g., “SSP2-Base”)
year – year to produce the database for
system_model – “cutoff” or “consequential”.
- fetch_external_data_battery_mobile_scenarios()
Fetch external data on mobile battery scenarios.
- fetch_external_data_battery_stationary_scenarios(exclude_chemistries=['NAS'])
Fetch external data on stationary battery scenarios.
- fetch_external_data_coal_power_plants()
Fetch data on coal power plants from external sources. Source: Oberschelp, C., Pfister, S., Raptis, C.E. et al. Global emission hotspots of coal power generation. Nat Sustain 2, 113–121 (2019). https://doi.org/10.1038/s41893-019-0221-6
- get_external_data(external_scenarios: list)
Fetch data from external sources. :param external_scenarios: a list of dictionaries with keys “scenario” and “data” :return: a dictionary with data
- get_iam_efficiencies(data: DataArray, efficiency_labels: dict | None = None, production_labels: dict | None = None, energy_labels: dict | None = None, use_absolute_efficiency: bool = False) [<class 'xarray.core.dataarray.DataArray'>, None]
This method retrieves efficiency values for the specified sector, for a specified year, for each region provided by the IAM.
- Parameters:
data – The data to process.
efficiency_labels – The efficiency labels to use.
production_labels – The production labels to use.
energy_labels – The energy labels to use.
use_absolute_efficiency – If True, the efficiency is considered as absolute.
- Returns:
a multidimensional array with sector’s technologies market
share for a given year, for all regions.
Remind to Ecoinvent mapping
- class premise.activity_maps.InventorySet(database: List[dict], version: str | None = None, model: str | None = None)
Hosts different filter sets to find equivalencies between
premiseterms andecoinventactivities and exchanges.It stores: * material_filters: filters for activities related to materials. * powerplant_filters: filters for activities related to power generation technologies. * powerplant_fuel_filters: filters for fuel providers in power generation technologies. * fuel_filters: filters for fuel providers in general. * emissions_map: REMIND emission labels as keys, ecoinvent emission labels as values
The functions
generate_material_map(),generate_powerplant_map()andgenerate_fuel_map()can be used to extract the actual activity objects as dictionaries. These functions return the result of applyingact_fltr()to the filter dictionaries.- generate_carbon_storage_map() dict
Filter ecoinvent processes related to carbon storage.
- Returns:
dictionary with el. prod. techs as keys (see below) and sets of related ecoinvent activities as values.
- Return type:
dict
- generate_cement_fuels_map() dict
Filter ecoinvent processes related to cement production.
- Returns:
dictionary with el. prod. techs as keys (see below) and sets of related ecoinvent activities as values.
- Return type:
dict
- generate_daccs_map() dict
Filter ecoinvent processes related to direct air capture.
- Returns:
dictionary with el. prod. techs as keys (see below) and sets of related ecoinvent activities as values.
- Return type:
dict
- generate_fuel_map() dict
Filter ecoinvent processes related to fuel supply.
- Returns:
dictionary with fuel names as keys (see below) and sets of related ecoinvent activities as values.
- Return type:
dict
- generate_gains_mapping()
Generate a dictionary with GAINS variables as keys and ecoinvent datasets as values.
- generate_heat_map() dict
Filter ecoinvent processes related to heat production.
- Returns:
dictionary with heat prod. techs as keys (see below) and sets of related ecoinvent activities as values.
- Return type:
dict
- generate_material_map() dict
Filter ecoinvent processes related to materials. Rerurns a dictionary with material names as keys (see below) and a set of related ecoinvent activities’ names as values.
- generate_powerplant_fuels_map() dict
Filter ecoinvent processes related to electricity production.
- Returns:
dictionary with el. prod. techs as keys (see below) and sets of related ecoinvent activities as values.
- Return type:
dict
- generate_powerplant_map() dict
Filter ecoinvent processes related to electricity production.
- Returns:
dictionary with el. prod. techs as keys (see below) and sets of related ecoinvent activities as values.
- Return type:
dict
- generate_sets_from_filters(filtr: dict, database=None) dict
Generate a dictionary with sets of activity names for technologies from the filter specifications.
- Parameters:
filtr
activity_maps.InventorySet.act_fltr(). :return: dictionary with the same keys as provided in filterand a set of activity data set names as values.
- Return type:
dict
- generate_transport_map(transport_type: str) dict
Filter ecoinvent processes related to transport. Rerurns a dictionary with transport type as keys (see below) and a set of related ecoinvent activities’ names as values.
- generate_vehicle_fuel_map(transport_type: str) dict
Filter ecoinvent processes related to transport fuels. Rerurns a dictionary with transport type as keys (see below) and a set of related ecoinvent activities’ names as values.
Electricity markets modelling
- class premise.electricity.Electricity(database: List[dict], iam_data: IAMDataCollection, model: str, pathway: str, year: int, version: str, system_model: str, use_absolute_efficiency: bool = False, cache: dict | None = None, index: dict | None = None)
Class that modifies electricity markets in the database based on IAM output data. Inherits from transformation.BaseTransformation.
- Variables:
database (list) – wurst database, which is a list of dictionaries
iam_data (xarray.DataArray) – IAM data
model (str) – name of the IAM model (e.g., “remind”, “image”)
year (int) – year of the pathway (e.g., 2030)
- adjust_aluminium_electricity_markets() None
Aluminium production is a major electricity consumer. In Ecoinvent, aluminium producers have their own electricity markets. In the IAM, aluminium production is part of the electricity market. We need to adjust the electricity markets of aluminium producers by linking them to the regional electricity markets. However, some aluminium electricity markets are already deeply decarbonized because some smelters are powered by hydroelectricity. Hence, we choose to link aluminium producers to the regional electricity markets but only those that are not already decarbonized, meaning from those regions:
RoW
IAI Area, Africa
CN
IAI Area, South America
UN-OCEANIA
IAI Area, Asia, without China and GCC
IAI Area, Gulf Cooperation Council
while we leave untouched the following regions:
IAI Area, Russia & RER w/o EU27 & EFTA
CA
IAI Area, EU27 & EFTA
- adjust_coal_power_plant_emissions() None
Based on: Fetch data on coal power plants from external sources. Source: Oberschelp, C., Pfister, S., Raptis, C.E. et al. Global emission hotspots of coal power generation. Nat Sustain 2, 113–121 (2019). https://doi.org/10.1038/s41893-019-0221-6
We adjust efficiency and emissions of coal power plants, including coal-fired CHPs.
- correct_hydropower_water_emissions() None
Correct the emissions of water for hydropower plants. In Swiss datasets, water evaoporation is too high. We use a new factor from Flury and Frischknecht (2021) to correct this. https://treeze.ch/fileadmin/user_upload/downloads/Publications/Case_Studies/Energy/flury-2012-hydroelectric-power-generation.pdf
- create_missing_power_plant_datasets() None
Create missing power plant datasets. We use proxy datasets, copy them and rename them.
- create_new_markets_high_voltage() None
Create high voltage market groups for electricity, based on electricity mixes given by the IAM scenario. Contribution from solar power is added in low voltage market groups. Does not return anything. Modifies the database in place.
- create_new_markets_low_voltage() None
Create low voltage market groups for electricity, by receiving medium voltage market groups as input and adding transformation and distribution losses. Transformation and distribution losses are taken from ei37. Contribution from solar power is added here as well, as most is delivered at low voltage, although CSP delivers at high voltage. Does not return anything. Modifies the database in place.
- create_new_markets_medium_voltage() None
Create medium voltage market groups for electricity, by receiving high voltage market groups as inputs and adding transformation and distribution losses. Contribution from solar power is added in low voltage market groups. Does not return anything. Modifies the database in place.
- create_region_specific_power_plants()
Some power plant inventories are not native to ecoinvent but imported. However, they are defined for a specific location (mostly European), but are used in many electricity markets (non-European). Hence, we create region-specific versions of these datasets, to align inputs providers with the geographical scope of the region.
- generate_world_market(dataset: dict, regions: List[str]) dict
Generate the world market for a given dataset and product variables.
- Parameters:
dataset – The dataset for which to generate the world market.
regions – A dictionary of activity datasets, keyed by region.
This function generates the world market exchanges for a given dataset and set of product variables. It first filters out non-production exchanges from the dataset, and then calculates the total production volume for the world using the given product variables. For each region, it calculates the share of the production volume and adds a technosphere exchange to the dataset with the appropriate share.
- get_production_per_tech_dict() Dict[Tuple[str, str], float]
Create a dictionary with tuples (technology, country) as keys and production volumes as values. :return: technology to production volume dictionary :rtype: dict
Return the share of production of an electricity-producing dataset in a specific location, relative to the summed production of similar technologies in locations contained in the same IAM region. :param supplier: electricity-producing dataset :type supplier: wurst dataset :param suppliers: list of electricity-producing datasets :type suppliers: list of wurst datasets :return: share of production relative to the total population :rtype: float
- update_efficiency_of_solar_pv() None
Update the efficiency of solar PV modules. We look at how many square meters are needed per kilowatt of installed capacity to obtain the current efficiency. Then we update the surface needed according to the projected efficiency. :return:
- update_electricity_efficiency() None
This method modifies each ecoinvent coal, gas, oil and biomass dataset using data from the IAM scenario. Return a wurst database with modified datasets.
- Returns:
a wurst database, with rescaled electricity-producing datasets.
- Return type:
list
- update_electricity_markets() None
Delete electricity markets. Create high, medium and low voltage market groups for electricity. Link electricity-consuming datasets to newly created market groups for electricity. Return a wurst database with modified datasets.
- Returns:
a wurst database with new market groups for electricity
- Return type:
list
- write_log(dataset, status='created')
Write log file.