From e32f71c01b00f411ff46fcfdad5b0f127c626ee3 Mon Sep 17 00:00:00 2001 From: "anton.achhammer" Date: Fri, 10 Jan 2025 09:09:32 +0100 Subject: [PATCH 1/3] remove duplicated config entry --- config.default.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/config.default.yaml b/config.default.yaml index ed8554002..c67335c5e 100644 --- a/config.default.yaml +++ b/config.default.yaml @@ -658,7 +658,6 @@ sector: co2_network: true co2_sequestration_potential: 200 #MtCO2/a sequestration potential for Europe co2_sequestration_cost: 10 #EUR/tCO2 for sequestration of CO2 - hydrogen_underground_storage: true shipping_hydrogen_liquefaction: false shipping_average_efficiency: 0.4 #For conversion of fuel oil to propulsion in 2011 From 9479e27859f49eb85ac1ce8aecb7b6b9d6a9be60 Mon Sep 17 00:00:00 2001 From: "anton.achhammer" Date: Fri, 10 Jan 2025 09:14:18 +0100 Subject: [PATCH 2/3] remove duplicated entry in config.test_myopic --- test/config.test_myopic.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/test/config.test_myopic.yaml b/test/config.test_myopic.yaml index 382def55f..f1c210212 100644 --- a/test/config.test_myopic.yaml +++ b/test/config.test_myopic.yaml @@ -288,7 +288,6 @@ sector: co2_network: true co2_sequestration_potential: 200 #MtCO2/a sequestration potential for Europe co2_sequestration_cost: 10 #EUR/tCO2 for sequestration of CO2 - hydrogen_underground_storage: true shipping_hydrogen_liquefaction: false shipping_average_efficiency: 0.4 #For conversion of fuel oil to propulsion in 2011 From be42f1d7c48fa7b7b232eb92c3322b7135870f41 Mon Sep 17 00:00:00 2001 From: "anton.achhammer" Date: Mon, 13 Jan 2025 10:10:02 +0100 Subject: [PATCH 3/3] remove duplicated gadm_level --- Snakefile | 4 ++-- config.default.yaml | 1 - scripts/_helpers.py | 6 +++--- scripts/add_export.py | 8 ++++---- scripts/build_industrial_distribution_key.py | 12 ++++++------ scripts/cluster_network.py | 6 +++--- scripts/prepare_sector_network.py | 18 +++++++++--------- test/config.sector.yaml | 1 - test/config.test_myopic.yaml | 1 - 9 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Snakefile b/Snakefile index 5002fe2c5..2170b4607 100644 --- a/Snakefile +++ b/Snakefile @@ -1153,7 +1153,7 @@ rule build_ship_profile: rule add_export: params: - gadm_level=config["sector"]["gadm_level"], + gadm_layer_id=config["build_shape_options"]["gadm_layer_id"], alternative_clustering=config["cluster_options"]["alternative_clustering"], store=config["export"]["store"], store_capital_costs=config["export"]["store_capital_costs"], @@ -1836,7 +1836,7 @@ rule prepare_db: rule build_industrial_distribution_key: #default data params: countries=config["countries"], - gadm_level=config["sector"]["gadm_level"], + gadm_layer_id=config["build_shape_options"]["gadm_layer_id"], alternative_clustering=config["cluster_options"]["alternative_clustering"], industry_database=config["custom_data"]["industry_database"], input: diff --git a/config.default.yaml b/config.default.yaml index c67335c5e..057a81989 100644 --- a/config.default.yaml +++ b/config.default.yaml @@ -672,7 +672,6 @@ sector: NZ_2050: 0.36 DF_2050: 0.12 - gadm_level: 1 h2_cavern: true marginal_cost_storage: 0 methanation: true diff --git a/scripts/_helpers.py b/scripts/_helpers.py index ddb6fda5f..79a2ca028 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -1273,7 +1273,7 @@ def get_GADM_layer(country_list, layer_id, update=False, outlogging=False): def locate_bus( coords, co, - gadm_level, + gadm_layer_id, path_to_gadm=None, gadm_clustering=False, col="name", @@ -1305,8 +1305,8 @@ def locate_bus( lambda name: three_2_two_digits_country(name[:3]) + name[3:] ) else: - gdf = get_GADM_layer(co, gadm_level) - col = "GID_{}".format(gadm_level) + gdf = get_GADM_layer(co, gadm_layer_id) + col = "GID_{}".format(gadm_layer_id) # gdf.set_index("GADM_ID", inplace=True) gdf_co = gdf[ diff --git a/scripts/add_export.py b/scripts/add_export.py index ba7b2442e..d8a860b82 100644 --- a/scripts/add_export.py +++ b/scripts/add_export.py @@ -47,13 +47,13 @@ def select_ports(n): logger.error( "No export ports chosen, please add ports to the file data/export_ports.csv" ) - gadm_level = snakemake.params.gadm_level + gadm_layer_id = snakemake.params.gadm_layer_id - ports["gadm_{}".format(gadm_level)] = ports[["x", "y", "country"]].apply( + ports["gadm_{}".format(gadm_layer_id)] = ports[["x", "y", "country"]].apply( lambda port: locate_bus( port[["x", "y"]], port["country"], - gadm_level, + gadm_layer_id, snakemake.input["shapes_path"], snakemake.params.alternative_clustering, ), @@ -62,7 +62,7 @@ def select_ports(n): # TODO: revise if ports quantity and property by shape become relevant # drop duplicated entries - gcol = "gadm_{}".format(gadm_level) + gcol = "gadm_{}".format(gadm_layer_id) ports_sel = ports.loc[~ports[gcol].duplicated(keep="first")].set_index(gcol) # Select the hydrogen buses based on nodes with ports diff --git a/scripts/build_industrial_distribution_key.py b/scripts/build_industrial_distribution_key.py index 48d7ed8c6..02a650150 100644 --- a/scripts/build_industrial_distribution_key.py +++ b/scripts/build_industrial_distribution_key.py @@ -21,7 +21,7 @@ gpd_version = StrictVersion(gpd.__version__) -def map_industry_to_buses(df, countries, gadm_level, shapes_path, gadm_clustering): +def map_industry_to_buses(df, countries, gadm_layer_id, shapes_path, gadm_clustering): """ Load hotmaps database of industrial sites and map onto bus regions. Build industrial demand... Change name and add other functions. @@ -31,18 +31,18 @@ def map_industry_to_buses(df, countries, gadm_level, shapes_path, gadm_clusterin Change hotmaps to more descriptive name, etc. """ df = df[df.country.isin(countries)] - df["gadm_{}".format(gadm_level)] = df[["x", "y", "country"]].apply( + df["gadm_{}".format(gadm_layer_id)] = df[["x", "y", "country"]].apply( lambda site: locate_bus( site[["x", "y"]].astype("float"), site["country"], - gadm_level, + gadm_layer_id, shapes_path, gadm_clustering, ), axis=1, ) - return df.set_index("gadm_" + str(gadm_level)) + return df.set_index("gadm_" + str(gadm_layer_id)) def build_nodal_distribution_key( @@ -131,7 +131,7 @@ def match_technology(df): regions = gpd.read_file(snakemake.input.regions_onshore) shapes_path = snakemake.input.shapes_path - gadm_level = snakemake.params.gadm_level + gadm_layer_id = snakemake.params.gadm_layer_id countries = snakemake.params.countries gadm_clustering = snakemake.params.alternative_clustering @@ -178,7 +178,7 @@ def match_technology(df): industrial_database = map_industry_to_buses( geo_locs[geo_locs.quality != "unavailable"], countries, - gadm_level, + gadm_layer_id, shapes_path, gadm_clustering, ) diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 63ae6556c..d98c69221 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -378,7 +378,7 @@ def n_bounds(model, *n_id): ) -def busmap_for_gadm_clusters(inputs, n, gadm_level, geo_crs, country_list): +def busmap_for_gadm_clusters(inputs, n, gadm_layer_id, geo_crs, country_list): gdf = gpd.read_file(inputs.gadm_shapes) def locate_bus(coords, co): @@ -394,12 +394,12 @@ def locate_bus(coords, co): ]["GADM_ID"].item() buses = n.buses - buses["gadm_{}".format(gadm_level)] = buses[["x", "y", "country"]].apply( + buses["gadm_{}".format(gadm_layer_id)] = buses[["x", "y", "country"]].apply( lambda bus: locate_bus(bus[["x", "y"]], bus["country"]), axis=1 ) buses["gadm_subnetwork"] = ( - buses["gadm_{}".format(gadm_level)] + "_" + buses["carrier"].astype(str) + buses["gadm_{}".format(gadm_layer_id)] + "_" + buses["carrier"].astype(str) ) busmap = buses["gadm_subnetwork"] diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 880dafef7..cc1dc099b 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -1022,23 +1022,23 @@ def add_aviation(n, cost): airports = pd.read_csv(snakemake.input.airports, keep_default_na=False) airports = airports[airports.country.isin(countries)] - gadm_level = options["gadm_level"] + gadm_layer_id = snakemake.config["build_shape_options"]["gadm_layer_id"] - airports["gadm_{}".format(gadm_level)] = airports[["x", "y", "country"]].apply( + airports["gadm_{}".format(gadm_layer_id)] = airports[["x", "y", "country"]].apply( lambda airport: locate_bus( airport[["x", "y"]], airport["country"], - gadm_level, + gadm_layer_id, snakemake.input.shapes_path, snakemake.config["cluster_options"]["alternative_clustering"], ), axis=1, ) # To change 3 country code to 2 - # airports["gadm_{}".format(gadm_level)] = airports["gadm_{}".format(gadm_level)].apply( + # airports["gadm_{}".format(gadm_layer_id)] = airports["gadm_{}".format(gadm_layer_id)].apply( # lambda cocode: three_2_two_digits_country(cocode[:3]) + " " + cocode[4:-2]) - airports = airports.set_index("gadm_{}".format(gadm_level)) + airports = airports.set_index("gadm_{}".format(gadm_layer_id)) ind = pd.DataFrame(n.buses.index[n.buses.carrier == "AC"]) @@ -1290,7 +1290,7 @@ def add_shipping(n, costs): ).squeeze() ports = ports[ports.country.isin(countries)] - gadm_level = options["gadm_level"] + gadm_layer_id = snakemake.config["build_shape_options"]["gadm_layer_id"] all_navigation = ["total international navigation", "total domestic navigation"] @@ -1307,18 +1307,18 @@ def add_shipping(n, costs): options["shipping_hydrogen_share"], demand_sc + "_" + str(investment_year) ) - ports["gadm_{}".format(gadm_level)] = ports[["x", "y", "country"]].apply( + ports["gadm_{}".format(gadm_layer_id)] = ports[["x", "y", "country"]].apply( lambda port: locate_bus( port[["x", "y"]], port["country"], - gadm_level, + gadm_layer_id, snakemake.input["shapes_path"], snakemake.config["cluster_options"]["alternative_clustering"], ), axis=1, ) - ports = ports.set_index("gadm_{}".format(gadm_level)) + ports = ports.set_index("gadm_{}".format(gadm_layer_id)) ind = pd.DataFrame(n.buses.index[n.buses.carrier == "AC"]) ind = ind.set_index(n.buses.index[n.buses.carrier == "AC"]) diff --git a/test/config.sector.yaml b/test/config.sector.yaml index 670344b0a..16d23fb75 100644 --- a/test/config.sector.yaml +++ b/test/config.sector.yaml @@ -43,7 +43,6 @@ existing_capacities: sector: solid_biomass_potential: 10 # TWh/a, Potential of whole modelled area - gadm_level: 2 snapshots: # arguments to pd.date_range start: "2013-03-1" diff --git a/test/config.test_myopic.yaml b/test/config.test_myopic.yaml index f1c210212..013574d69 100644 --- a/test/config.test_myopic.yaml +++ b/test/config.test_myopic.yaml @@ -302,7 +302,6 @@ sector: NZ_2050: 0.36 DF_2050: 0.12 - gadm_level: 1 h2_cavern: true marginal_cost_storage: 0 methanation: true