mescal.utils

Functions

_short_name_ds_type(→ str)

Returns the short name of the LCI dataset type

change_mapping_year(→ pandas.DataFrame)

Change the year in the name of the activities and databases in the mapping file

change_year_in_name(→ pandas.Series)

Change the year in the name of the activity and database

ecoinvent_unit_convention(→ str)

Reformat unit to the ecoinvent convention

expand_impact_category_levels(→ pandas.DataFrame)

Expand the impact category levels into separate columns

premise_changing_names(→ tuple[str, str, str])

Returns the updated name, product and location in case some changes have occurred in premise

random_code(→ str)

Create a random code

Module Contents

mescal.utils._short_name_ds_type(ds_type: str) str[source]

Returns the short name of the LCI dataset type

Parameters:

ds_type (str) – type of LCI dataset

Returns:

short name of the LCI dataset type

Return type:

str

mescal.utils.change_mapping_year(mapping: pandas.DataFrame, year_from: int, year_to: int) pandas.DataFrame[source]

Change the year in the name of the activities and databases in the mapping file

Parameters:
  • mapping (pandas.DataFrame) – mapping file between the LCI database and the ESM database

  • year_from (int) – year of the original mapping file

  • year_to (int) – year of the new mapping file

Returns:

updated mapping file

Return type:

pandas.DataFrame

mescal.utils.change_year_in_name(row: pandas.Series, year_from: int, year_to: int) pandas.Series[source]

Change the year in the name of the activity and database

Parameters:
  • row (pandas.Series) – row of the mapping file

  • year_from (int) – year of the original mapping file

  • year_to (int) – year of the new mapping file

Returns:

updated mapping row

Return type:

pandas.Series

mescal.utils.ecoinvent_unit_convention(unit: str) str[source]

Reformat unit to the ecoinvent convention

Parameters:

unit (str) – unit to reformat

Returns:

ecoinvent unit

Return type:

str

mescal.utils.expand_impact_category_levels(df: pandas.DataFrame, impact_category_col: str = 'Impact_category') pandas.DataFrame[source]

Expand the impact category levels into separate columns

Parameters:
  • df (pandas.DataFrame) – dataframe with impact category column

  • impact_category_col (str) – name of the impact category column

Returns:

the dataframe with expanded impact category levels

Return type:

pandas.DataFrame

mescal.utils.premise_changing_names(activity_name: str, activity_prod: str, activity_loc: str, name_premise_db, premise_db_dict_name: dict, premise_changes: pandas.DataFrame = None) tuple[str, str, str][source]

Returns the updated name, product and location in case some changes have occurred in premise

Parameters:
  • activity_name (str) – name of the LCI dataset

  • activity_prod (str) – product of the LCI dataset

  • activity_loc (str) – location of the LCI dataset

  • name_premise_db – name of the premise database

  • premise_db_dict_name (dict) – dictionary of the database with (name, product, location, database) as key

  • premise_changes (pandas.DataFrame) – file of the premise name changes impacting the mapping

Returns:

the updated name, product and location of the LCI dataset

Return type:

tuple[str, str, str]

mescal.utils.random_code() str[source]

Create a random code

Returns:

code

Return type:

str