mescal.double_counting

Functions

_background_search(→ tuple[list[list], dict, dict, ...)

Explores the tree of the market activity with a recursive approach and write the activities to actually check for

_double_counting_removal(→ tuple[list[list], dict, ...)

Remove double counting in the ESM database and write it in the Brightway project

background_double_counting_removal(→ None)

Performs double-counting removal in the background inventory. Concretely, flows included in the ESM end-use demands

validation_double_counting(→ None or pd.DataFrame)

Generate a validation report for the double-counting removal process: comparison of quantities removed in LCI

Module Contents

Explores the tree of the market activity with a recursive approach and write the activities to actually check for double-counting in the list perform_d_c.

Parameters:
  • act (dict) – LCI dataset

  • k (int) – tree depth of act with respect to starting activity

  • k_lim (int) – maximum allowed tree depth (i.e., maximum recursion depth)

  • amount (float) – product of amounts when going down in the tree

  • explore_type (str) – can be ‘market’ or ‘background_removal_’ + ds_type (where ds_type can be ‘op’, ‘constr’, ‘decom’ or ‘res’)

  • ESM_inputs (list[str] or str) – list of the ESM flows to perform double counting removal on

  • perform_d_c (list[list]) – list of activities to check for double counting

  • db_dict_code (dict) – LCI database as dictionary of activities with (database, code) as key

  • db_dict_name (dict) – LCI database as dictionary of activities with (name, reference product, location, database) as key

  • db_as_list (list[dict]) – LCI database as list of activities

  • db_type (str) – type of database to use, either ‘esm’, ‘esm results’ or ‘esm results wo dcr’

Returns:

list of activities to check for double counting, dictionary of activities with code as key, dictionary of activities with name as key, list of activities

Return type:

tuple[list[list], dict, dict, list[dict]]

mescal.double_counting._double_counting_removal(self, df: pandas.DataFrame, N: int, ESM_inputs: list[str] or str = 'all', db_type: str = 'esm', ds_type: str = 'Operation') tuple[list[list], dict, list[list]][source]

Remove double counting in the ESM database and write it in the Brightway project

Parameters:
  • df (pandas.DataFrame) – mapping file with input flows of each technology or resource

  • N (int) – number of columns of the original mapping file

  • ESM_inputs (list[str] or str) – list of the ESM flows to perform double counting removal on

  • db_type (str) – type of database to use, either ‘esm’, ‘esm results’ or ‘esm results wo dcr’

  • ds_type (str) – type of LCI dataset to consider, can be ‘Operation’, ‘Construction’, ‘Decommission’ or ‘Resource’

Returns:

list of removed flows, dictionary of removed quantities, list of activities subject to double counting

Return type:

tuple[list[list], dict, list[list]]

mescal.double_counting.background_double_counting_removal(self, new_db_name: str = None, write_database: bool = True) None[source]

Performs double-counting removal in the background inventory. Concretely, flows included in the ESM end-use demands (e.g., energy flows in the ESM geographical scope) are removed from the technosphere matrix. This step is needed if the ESM end-use demands include the production and operation of new infrastructures.

Parameters:
  • new_db_name (str) – name of the new database to write, if None, a default name is used (<original_db_name>_adjusted_for_double_counting)

  • write_database (bool) – if True, writes the new database in Brightway

Returns:

None

Return type:

None

mescal.double_counting.validation_double_counting(self, esm_results: pandas.DataFrame = None, return_validation_report: bool = True, save_validation_report: bool = False) None or pd.DataFrame[source]

Generate a validation report for the double-counting removal process: comparison of quantities removed in LCI datasets vs quantities in ESM flows. LCI datasets quantities are converted in ESM units (both in terms of inputs and outputs, i.e., quantities of input fuels per functional unit). If an ESM results dataframe is provided, the input flows are aggregated to compare the system’s primary energy use.

Parameters:
  • return_validation_report (bool) – if True, returns a DataFrame with the validation report (double-counting removal or primary energy use, depending on whether esm_results is provided).

  • esm_results (pandas.DataFrame) – dataframe containing the annual production of each technology in the ESM. It must contain the columns ‘Name’ and ‘Production’, and it can possibly contain the ‘Run’ and ‘Year’ columns too. If provided, the system’s primary energy use will be compared.

  • save_validation_report (bool) – if True, saves the validation report as a CSV file in self.results_path_file.

Returns:

None or DataFrame with the validation report if return_validation_report is True

Return type:

None or pd.DataFrame