Double Counting Removal by Mescal

6 minute read

Published:

This is my first blog post. I wanna introduce a tool which I am using right now. It is called Mescal and it’s used for Energyscope. Double counting removal can be done easily by means of it but first of all we should delve into it to deeply understand its mechanism.

Introduction

In the new methodology implemented in REHO, the life cycle of a technology is divided into 3 sections: Resources, Construction, and Operation. Whereas, in Ecoinvent, double-counting occurs regarding the flows that are explicitly modelled in our energy system model, e.g., energy flows (electricity, heat, fuels, etc.).

For example, in ecoinvent when we consider the operation of some technologies, such as heat production by gas boiler, the entry of this activity would include the gas boiler construction. Then we need to remove the double counting since we have concluded the construction in the construction part. Same things should be done for some energy flows. Since all these flows have been considered in the calculation during resource phase, there is no need to count it again in the operation.

Methodology

In mescal, Central Product Classification (CPC) is adapted. It consists of a coherent and consistent classification structure for products (goods and services) based on a set of internationally agreed concepts, definitions, principles and classification rules. With the help of CPC, we could distinguish the difference among all kinds of flows and products even if they have different names in our energy systems. The figure below shows the mechanism of mescal:

Firstly, we map each product and flows to CPC category and we can get a list L of CPC categories for all technology input flows. Then we assign a CPC category to each intermediary flow i. The flow i should be the flow regarding how we model our technologies in our own energy system model. If flow i’s CPC is in the list L, that means it has been considered and we shall set the amount of this flow to 0.

Double counting removal process

The idea is to give an overview of this tool like what files we need and how mescal can removed the double counting with those files. If you want to directly use this tool, please directly refer to Mescal tutorial.

Files to be input

mapping = pd.read_csv(f'./REHO_data/{esm_location}/mapping_{ecoinvent_version}.csv')
unit_conversion = pd.read_csv(f'./REHO_data/{esm_location}/unit_conversion_{ecoinvent_version}.csv')
mapping_esm_flows_to_CPC = pd.read_csv(f'./REHO_data/{esm_location}/mapping_esm_flows_to_CPC_{ecoinvent_version}.csv')
model = pd.read_csv(f'./REHO_data/{esm_location}/model.csv')
mapping_product_to_CPC = pd.read_csv(f'./REHO_data/{esm_location}/mapping_product_to_CPC.csv')
technology_compositions = pd.read_csv(f'./REHO_data/{esm_location}/technology_compositions.csv')
technology_specifics = pd.read_csv(f'./REHO_data/{esm_location}/technology_specifics.csv')
lifetime = pd.read_csv(f'./REHO_data/{esm_location}/lifetime.csv')
impact_abbrev = pd.read_csv(f'./REHO_data/{esm_location}/impact_abbrev.csv')
  • mapping is the file which we map energy technologies and resources of our energy system model with some lifecycle assessment databases(i.e. Ecoinvent);
  • unit_conversion is the file we give unit conversion factors between LCI and our ESM;
  • mapping_esm_flows_to_CPC is a mapping between the energy model flows and CPC categories;
  • model is how we defined our model. For each technology, we define it’s input and output flow in the model file. The main output flow should have 1 as an amount;
  • mapping_product_to_CPC is a mapping between the products and activities in the LCI database and the CPC categories;
  • technology_compositions is for defining some special technologies which is composed of several technologies;
  • lifetime is a file denoting the life time of the technologies in our own model;
  • impact_abbrev is the abbreviation of the environmental impacts, which are used as indicators in our energy system model.

Double counting removal

The most attractive as well as the key part of mescal is the py file double_counting_removal where double counting is removed.

In the function of create_esm_database, it creates the ESM database after double counting removal.

First of all, operation and construction activity is saved to database because double counting only happens in operation phase:

# Add construction and resource activities to the database (which do not need double counting removal)
    main_database = add_activities_to_database(mapping, 'Construction', main_database, db_dict_name,
                                               db_dict_code, esm_db_name, regionalize_foregrounds, accepted_locations,
                                               target_region, locations_ranking)
    main_database = add_activities_to_database(mapping, 'Resource', main_database, db_dict_name,
                                               db_dict_code, esm_db_name, regionalize_foregrounds, accepted_locations,
                                               target_region, locations_ranking)

Then the double counting removal is conducted by detecting the flows which are to be disgarded and set those flows’ amounts to 0.

Here the technosphere flow in the ecoinvent is firstly searched out:

if tech in no_background_search_list:
  new_act_op['comment'] = f"Subject to double-counting removal. " + new_act_op.get('comment', '')
  perform_d_c = [[new_act_op['name'], new_act_op['code'], 1, 0, ESM_inputs]]
else:
  perform_d_c, db, db_dict_code, db_dict_name = background_search(
        act=new_act_op,
        k=0,
        k_lim=10,
        amount=1,
        explore_type='market',
        ESM_inputs=ESM_inputs,
        db=db,
        db_dict_code=db_dict_code,
        db_dict_name=db_dict_name,
        esm_db_name=esm_db_name,
        perform_d_c=[],
        create_new_db=create_new_db,
    )  # list of activities to perform double counting removal on

As indicated in the methodology part, list of inputs in the ESM together with their CPCs are sorted out:

if perform_d_c[id_d_c][4] == 'all':
  # list of inputs in the ESM (i.e., negative flows in layers_in_out)
    ES_inputs = list(df_op.iloc[:, N:].iloc[i][df_op.iloc[:, N:].iloc[i] < 0].index)
else:
    ES_inputs = perform_d_c[id_d_c][4]

# CPCs corresponding to the ESM list of inputs
CPC_inputs = list(mapping_esm_flows_to_CPC_dict[inp] for inp in ES_inputs)
CPC_inputs = [item for sublist in CPC_inputs for item in sublist]  # flatten the list of lists

Then the list containing the CPCs of all technosphere flows of the activity is sorted out:

# Creating the list containing the CPCs of all technosphere flows of the activity
technosphere_inputs = get_technosphere_flows(new_act_op_d_c)
technosphere_inputs_CPC = []

for exc in technosphere_inputs:

    database = exc['database']
    code = exc['code']
    act_flow = db_dict_code[(database, code)]

    if 'classifications' in list(act_flow.keys()):
        if 'CPC' in dict(act_flow['classifications']).keys():
            technosphere_inputs_CPC.append(dict(act_flow['classifications'])['CPC'])
        else:
            technosphere_inputs_CPC.append('None')
    else:
        technosphere_inputs_CPC.append('None')

Then the technosphere flow for which should be set to 0 is generated.

# Finding the indices of technosphere flows that are also in the ESM inputs
# (i.e., flows that we want to put to zero)
set_CPC_inputs = set(CPC_inputs)
id_technosphere_inputs_zero = [i for i, e in enumerate(technosphere_inputs_CPC) if e in set_CPC_inputs]

Then the similar procedures are repeated for construction. The amounts of those flows are set to zero while the amounts of the removed flow are also taken down in ei_removal.

Case study

You can visit my github to see how I implement Mescal into my own energy system optimization model, REHO.