From 0d5ecfe864c230886ff689936603d2426a4b87f0 Mon Sep 17 00:00:00 2001 From: Hazem-IEG Date: Fri, 13 Sep 2024 15:33:31 +0200 Subject: [PATCH 1/4] small fix for custom industry --- config.bright.yaml | 9 +++++++++ config.default.yaml | 9 +++++++++ scripts/build_industry_demand.py | 33 +++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/config.bright.yaml b/config.bright.yaml index 45db307f..522bae1b 100644 --- a/config.bright.yaml +++ b/config.bright.yaml @@ -89,6 +89,15 @@ custom_data: custom_sectors: false gas_network: false # If "True" then a custom .csv file must be placed in "resources/custom_data/pipelines.csv" , If "False" the user can choose btw "greenfield" or Model built-in datasets. Please refer to ["sector"] below. + rename_industry_carriers: { + "Electricity": "electricity", + "Biofuels": "solid biomass", + "Heat": "low-temperature heat", + "Natural Gas": "gas", + "Coal": "coal", + "Hydrogen": "hydrogen", + "Oil": "oil", + } costs: # Costs used in PyPSA-Earth-Sec. Year depends on the wildcard planning_horizon in the scenario section version: v0.6.2 diff --git a/config.default.yaml b/config.default.yaml index 304b52d8..851686bf 100644 --- a/config.default.yaml +++ b/config.default.yaml @@ -88,6 +88,15 @@ custom_data: custom_sectors: false gas_network: false # If "True" then a custom .csv file must be placed in "resources/custom_data/pipelines.csv" , If "False" the user can choose btw "greenfield" or Model built-in datasets. Please refer to ["sector"] below. + rename_industry_carriers: { + "Electricity": "electricity", + "Biofuels": "solid biomass", + "Heat": "low-temperature heat", + "Natural Gas": "gas", + "Coal": "coal", + "Hydrogen": "hydrogen", + "Oil": "oil", + } costs: # Costs used in PyPSA-Earth-Sec. Year depends on the wildcard planning_horizon in the scenario section version: v0.6.2 diff --git a/scripts/build_industry_demand.py b/scripts/build_industry_demand.py index 9a4e865b..02906435 100644 --- a/scripts/build_industry_demand.py +++ b/scripts/build_industry_demand.py @@ -54,15 +54,25 @@ def country_to_nodal(industrial_production, keys): snakemake = mock_snakemake( "build_industry_demand", simpl="", - clusters=10, + clusters=11, planning_horizons=2030, - demand="AB", + demand="GH", ) sets_path_to_root("pypsa-earth-sec") countries = snakemake.params.countries + all_carriers = [ + "electricity", + "gas", + "coal", + "oil", + "hydrogen", + "biomass", + "heat", + ] + if snakemake.params.industry_demand: _logger.info( "Fetching custom industry demand data.. expecting file at 'data_custom/industry_demand_{0}_{1}.csv'".format( @@ -76,6 +86,9 @@ def country_to_nodal(industrial_production, keys): ), index_col=[0, 1], ) + + industry_demand = industry_demand * 1e6 #TWh -> MWh and MtCO2 to tCO2 + keys_path = snakemake.input.industrial_distribution_key dist_keys = pd.read_csv( @@ -97,6 +110,20 @@ def country_to_nodal(industrial_production, keys): nodal_df_co = nodal_production_tom_co.dot(industry_base_totals_co.T) nodal_df = pd.concat([nodal_df, nodal_df_co]) + + if snakemake.config["custom_data"]["rename_industry_carriers"]: + + nodal_df.rename(columns=snakemake.config["custom_data"]["rename_industry_carriers"], inplace=True) + + + missing_carriers = set(all_carriers) - set(nodal_df.columns) + if missing_carriers: + _logger.warning("The following carriers are missing in the industy custom data {}".format(missing_carriers)) + + if "process emissions" not in nodal_df.columns: + _logger.warning("No process emissions added to the custom industry data") + + else: no_years = int(snakemake.wildcards.planning_horizons) - int( snakemake.params.base_year @@ -277,7 +304,7 @@ def match_technology(df): "oil", "hydrogen", "biomass", - "low-temperature heat", + "heat", ] # Fill missing carriers with 0s From 211592b3e64a8896418007313426e7cccae05e52 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 14:34:07 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- config.bright.yaml | 10 +--------- config.default.yaml | 10 +--------- scripts/build_industry_demand.py | 17 ++++++++++------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/config.bright.yaml b/config.bright.yaml index 522bae1b..786d0577 100644 --- a/config.bright.yaml +++ b/config.bright.yaml @@ -89,15 +89,7 @@ custom_data: custom_sectors: false gas_network: false # If "True" then a custom .csv file must be placed in "resources/custom_data/pipelines.csv" , If "False" the user can choose btw "greenfield" or Model built-in datasets. Please refer to ["sector"] below. - rename_industry_carriers: { - "Electricity": "electricity", - "Biofuels": "solid biomass", - "Heat": "low-temperature heat", - "Natural Gas": "gas", - "Coal": "coal", - "Hydrogen": "hydrogen", - "Oil": "oil", - } + rename_industry_carriers: {"Electricity": "electricity", "Biofuels": "solid biomass", "Heat": "low-temperature heat", "Natural Gas": "gas", "Coal": "coal", "Hydrogen": "hydrogen", "Oil": "oil"} costs: # Costs used in PyPSA-Earth-Sec. Year depends on the wildcard planning_horizon in the scenario section version: v0.6.2 diff --git a/config.default.yaml b/config.default.yaml index 851686bf..be87a8c5 100644 --- a/config.default.yaml +++ b/config.default.yaml @@ -88,15 +88,7 @@ custom_data: custom_sectors: false gas_network: false # If "True" then a custom .csv file must be placed in "resources/custom_data/pipelines.csv" , If "False" the user can choose btw "greenfield" or Model built-in datasets. Please refer to ["sector"] below. - rename_industry_carriers: { - "Electricity": "electricity", - "Biofuels": "solid biomass", - "Heat": "low-temperature heat", - "Natural Gas": "gas", - "Coal": "coal", - "Hydrogen": "hydrogen", - "Oil": "oil", - } + rename_industry_carriers: {"Electricity": "electricity", "Biofuels": "solid biomass", "Heat": "low-temperature heat", "Natural Gas": "gas", "Coal": "coal", "Hydrogen": "hydrogen", "Oil": "oil"} costs: # Costs used in PyPSA-Earth-Sec. Year depends on the wildcard planning_horizon in the scenario section version: v0.6.2 diff --git a/scripts/build_industry_demand.py b/scripts/build_industry_demand.py index 02906435..d4f444f4 100644 --- a/scripts/build_industry_demand.py +++ b/scripts/build_industry_demand.py @@ -87,7 +87,7 @@ def country_to_nodal(industrial_production, keys): index_col=[0, 1], ) - industry_demand = industry_demand * 1e6 #TWh -> MWh and MtCO2 to tCO2 + industry_demand = industry_demand * 1e6 # TWh -> MWh and MtCO2 to tCO2 keys_path = snakemake.input.industrial_distribution_key @@ -110,20 +110,23 @@ def country_to_nodal(industrial_production, keys): nodal_df_co = nodal_production_tom_co.dot(industry_base_totals_co.T) nodal_df = pd.concat([nodal_df, nodal_df_co]) - if snakemake.config["custom_data"]["rename_industry_carriers"]: - - nodal_df.rename(columns=snakemake.config["custom_data"]["rename_industry_carriers"], inplace=True) - + nodal_df.rename( + columns=snakemake.config["custom_data"]["rename_industry_carriers"], + inplace=True, + ) missing_carriers = set(all_carriers) - set(nodal_df.columns) if missing_carriers: - _logger.warning("The following carriers are missing in the industy custom data {}".format(missing_carriers)) + _logger.warning( + "The following carriers are missing in the industy custom data {}".format( + missing_carriers + ) + ) if "process emissions" not in nodal_df.columns: _logger.warning("No process emissions added to the custom industry data") - else: no_years = int(snakemake.wildcards.planning_horizons) - int( snakemake.params.base_year From 5d4003912006500302f615ea733d597dda954c99 Mon Sep 17 00:00:00 2001 From: hazemakhalek Date: Fri, 13 Sep 2024 16:55:08 +0200 Subject: [PATCH 3/4] adapt test config --- test/config.test1.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/config.test1.yaml b/test/config.test1.yaml index 388f8a44..65a98972 100644 --- a/test/config.test1.yaml +++ b/test/config.test1.yaml @@ -88,6 +88,8 @@ custom_data: custom_sectors: false gas_network: false # If "True" then a custom .csv file must be placed in "resources/custom_data/pipelines.csv" , If "False" the user can choose btw "greenfield" or Model built-in datasets. Please refer to ["sector"] below. + rename_industry_carriers: {"Electricity": "electricity", "Biofuels": "solid biomass", "Heat": "low-temperature heat", "Natural Gas": "gas", "Coal": "coal", "Hydrogen": "hydrogen", "Oil": "oil"} + costs: # Costs used in PyPSA-Earth-Sec. Year depends on the wildcard planning_horizon in the scenario section version: v0.6.2 lifetime: 25 #default lifetime From 1ee6d59172c27595f2faf14c9bb62cc0c3fe35c8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 14:55:47 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test/config.test1.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/test/config.test1.yaml b/test/config.test1.yaml index 65a98972..aaf263a1 100644 --- a/test/config.test1.yaml +++ b/test/config.test1.yaml @@ -89,7 +89,6 @@ custom_data: gas_network: false # If "True" then a custom .csv file must be placed in "resources/custom_data/pipelines.csv" , If "False" the user can choose btw "greenfield" or Model built-in datasets. Please refer to ["sector"] below. rename_industry_carriers: {"Electricity": "electricity", "Biofuels": "solid biomass", "Heat": "low-temperature heat", "Natural Gas": "gas", "Coal": "coal", "Hydrogen": "hydrogen", "Oil": "oil"} - costs: # Costs used in PyPSA-Earth-Sec. Year depends on the wildcard planning_horizon in the scenario section version: v0.6.2 lifetime: 25 #default lifetime