Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove duplicated config entry #1288

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,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"],
Expand Down Expand Up @@ -1824,7 +1824,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:
Expand Down
2 changes: 0 additions & 2 deletions config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,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

Expand All @@ -672,7 +671,6 @@ sector:
NZ_2050: 0.36
DF_2050: 0.12

gadm_level: 1
h2_cavern: true
marginal_cost_storage: 0
methanation: true
Expand Down
6 changes: 3 additions & 3 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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[
Expand Down
8 changes: 4 additions & 4 deletions scripts/add_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions scripts/build_industrial_distribution_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
)
Expand Down
6 changes: 3 additions & 3 deletions scripts/cluster_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"]

Expand Down
18 changes: 9 additions & 9 deletions scripts/prepare_sector_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down Expand Up @@ -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"]

Expand All @@ -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"])
Expand Down
1 change: 0 additions & 1 deletion test/config.sector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions test/config.test_myopic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,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

Expand All @@ -302,7 +301,6 @@ sector:
NZ_2050: 0.36
DF_2050: 0.12

gadm_level: 1
h2_cavern: true
marginal_cost_storage: 0
methanation: true
Expand Down
Loading