Skip to content

Commit

Permalink
EODC
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Nov 8, 2023
1 parent 3aef6a5 commit 0eb96f7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
Binary file added dev/final_energy_mapping.xlsx
Binary file not shown.
5 changes: 0 additions & 5 deletions dev/sample/mapping/mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@ Electricity:
reference product: electricity, low voltage
unit: kilowatt hour
scenario variable: Secondary Energy|Electricity
validation:
scenario variable: Emissions|CO2|Electricity Production
method: 'selected LCI results - air - CO2, fossil'
Biomass CHP:
dataset:
name: heat and power co-generation, wood chips, 2000 kW
reference product: electricity, high voltage
unit: kilowatt hour
scenario variable: Secondary Energy|Electricity|Biomass|w/o CCS|3
group: electricity
Biomass CHP CCS:
dataset:
name: electricity production, at co-generation wood-fired power plant, post, pipeline 200km, storage 1000m
reference product: electricity, high voltage
unit: kilowatt hour
scenario variable: Secondary Energy|Electricity|Biomass|w/ CCS|2
group: electricity
Biomass IGCC:
dataset:
name: electricity production, at biomass-fired IGCC power plant
Expand Down
Binary file added pathways/data/final_energy_mapping.xlsx
Binary file not shown.
43 changes: 43 additions & 0 deletions pathways/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
load_classifications,
load_units_conversion,
)
from . import DATA_DIR

# if pypardiso is installed, use it
try:
Expand Down Expand Up @@ -293,6 +294,7 @@ def __init__(self, datapackage):
self.datapackage = datapackage
self.data = validate_datapackage(self.read_datapackage())
self.mapping = self.get_mapping()
self.mapping.update(self.get_final_energy_mapping())
self.scenarios = self.get_scenarios()
self.classifications = load_classifications()

Expand All @@ -316,6 +318,47 @@ def read_datapackage(self) -> DataPackage:
"""
return DataPackage(self.datapackage)


def get_final_energy_mapping(self):
"""
Read the final energy mapping file, which is an Excel file
:return: dict
"""

def create_dict_for_specific_model(row, model):
# Construct the key from 'sector', 'variable', and 'fuel'
key = f"{row['sector']} {row['variable']} {row['fuel']}".replace(" ", "_")

# Check if the specific model's scenario variable is available
if pd.notna(row[model]):
# Create the dictionary structure for this row for the specific model
dict_structure = {
key: {
'dataset': {
'name': row['dataset name'],
'reference product': row['dataset reference product'],
'unit': row['unit']
},
'scenario variable': row[model]
}
}
return dict_structure
return None
def create_dict_with_specific_model(dataframe, model):
model_dict = {}
for index, row in dataframe.iterrows():
row_dict = create_dict_for_specific_model(row, model)
if row_dict:
model_dict.update(row_dict)
return model_dict

# Read the Excel file
df = pd.read_excel(
DATA_DIR / "data" / "final_energy_mapping.xlsx",
)
model = self.data.coords["model"].values[0]
return create_dict_with_specific_model(df, model)

def get_mapping(self) -> dict:
"""
Read the mapping file.
Expand Down

0 comments on commit 0eb96f7

Please sign in to comment.