diff --git a/dev/final_energy_mapping.xlsx b/dev/final_energy_mapping.xlsx new file mode 100644 index 0000000..b57f5b8 Binary files /dev/null and b/dev/final_energy_mapping.xlsx differ diff --git a/dev/sample/mapping/mapping.yaml b/dev/sample/mapping/mapping.yaml index d2af6a9..fccc4ab 100644 --- a/dev/sample/mapping/mapping.yaml +++ b/dev/sample/mapping/mapping.yaml @@ -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 diff --git a/pathways/data/final_energy_mapping.xlsx b/pathways/data/final_energy_mapping.xlsx new file mode 100644 index 0000000..170392c Binary files /dev/null and b/pathways/data/final_energy_mapping.xlsx differ diff --git a/pathways/pathways.py b/pathways/pathways.py index cb91ce0..5b86225 100644 --- a/pathways/pathways.py +++ b/pathways/pathways.py @@ -37,6 +37,7 @@ load_classifications, load_units_conversion, ) +from . import DATA_DIR # if pypardiso is installed, use it try: @@ -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() @@ -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.