From 1792ef0704b2cc0e45a94b6c0c2c893c2be8869d Mon Sep 17 00:00:00 2001 From: ekatef Date: Thu, 5 Dec 2024 14:42:37 +0100 Subject: [PATCH 1/3] Add check for export ports being empty --- scripts/add_export.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/add_export.py b/scripts/add_export.py index 5da2e2940..d30875e06 100644 --- a/scripts/add_export.py +++ b/scripts/add_export.py @@ -43,10 +43,11 @@ def select_ports(n): # ports.loc[:, "fraction"] = ports.fraction.round(1) ports = ports[ports.country.isin(countries)] - if len(ports) < 1: - logger.error( + if ports.empty: + logger.warning( "No export ports chosen, please add ports to the file data/export_ports.csv" ) + return ports gadm_level = snakemake.params.gadm_level ports["gadm_{}".format(gadm_level)] = ports[["x", "y", "country"]].apply( @@ -238,8 +239,10 @@ def create_export_profile(): # get hydrogen export buses/ports hydrogen_buses_ports = select_ports(n) - # add export value and components to network - add_export(n, hydrogen_buses_ports, export_profile) + # depending on the region, there may be hydrogen ports available (or not) + if not hydrogen_buses_ports.empty: + # add export value and components to network + add_export(n, hydrogen_buses_ports, export_profile) n.export_to_netcdf(snakemake.output[0]) From a25465cfc1407f9922054c89593cc8ce65d8cf57 Mon Sep 17 00:00:00 2001 From: ekatef Date: Thu, 5 Dec 2024 14:43:05 +0100 Subject: [PATCH 2/3] Add a short docstring --- scripts/add_export.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/add_export.py b/scripts/add_export.py index d30875e06..cd1caf26a 100644 --- a/scripts/add_export.py +++ b/scripts/add_export.py @@ -71,6 +71,9 @@ def select_ports(n): def add_export(n, hydrogen_buses_ports, export_profile): + """ + Adds H2 exports for ports + """ country_shape = gpd.read_file(snakemake.input["shapes_path"]) # Find most northwestern point in country shape and get x and y coordinates country_shape = country_shape.to_crs( From 70eda4e84b6d6db0eea5ddb125e4dd827f6d8ae8 Mon Sep 17 00:00:00 2001 From: ekatef Date: Thu, 5 Dec 2024 14:43:48 +0100 Subject: [PATCH 3/3] Skip adding export ports for landlock countries --- scripts/prepare_sector_network.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 01ab70a7b..b40ab653b 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -1287,6 +1287,9 @@ def add_shipping(n, costs): ).squeeze() ports = ports[ports.country.isin(countries)] + if ports.empty: + return + gadm_level = options["gadm_level"] all_navigation = ["total international navigation", "total domestic navigation"]