From d37cd49f7d3b765d4c74cd182a9ed91118f07f69 Mon Sep 17 00:00:00 2001 From: virio-andreyana Date: Wed, 14 Dec 2022 12:19:44 +0100 Subject: [PATCH] add script for retrieving lng terminals --- Snakefile | 5 ++- scripts/build_gas_input_locations.py | 26 +------------ scripts/retrieve_gas_input_locations.py | 50 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 scripts/retrieve_gas_input_locations.py diff --git a/Snakefile b/Snakefile index 468783e1..4011dee0 100644 --- a/Snakefile +++ b/Snakefile @@ -128,10 +128,13 @@ if config["sector"]["gas_network"] or config["sector"]["H2_retrofit"]: resources: mem_mb=4000 script: "scripts/build_gas_network.py" + rule retrieve_gas_input_locations: + output: "data/gas_network/Europe-Gas-Tracker-August-2022.geojson" + script: 'scripts/retrieve_gas_input_locations.py' rule build_gas_input_locations: input: - lng="data/gas_network/Europe-Gas-Tracker-August-2022.xlsx", + lng="data/gas_network/Europe-Gas-Tracker-August-2022.geojson", entry="data/gas_network/scigrid-gas/data/IGGIELGN_BorderPoints.geojson", production="data/gas_network/scigrid-gas/data/IGGIELGN_Productions.geojson", regions_onshore=pypsaeur("resources/regions_onshore_elec_s{simpl}_{clusters}.geojson"), diff --git a/scripts/build_gas_input_locations.py b/scripts/build_gas_input_locations.py index 22529193..c6e3d634 100644 --- a/scripts/build_gas_input_locations.py +++ b/scripts/build_gas_input_locations.py @@ -18,34 +18,10 @@ def read_scigrid_gas(fn): df.drop(["param", "uncertainty", "method"], axis=1, inplace=True) return df -def read_lng_gem(fn): - df = pd.read_excel(fn, sheet_name = 'LNG terminals - data') - df = df.set_index("ComboID") - - remove_status = ['Cancelled'] - remove_country = ['Cyprus','Turkey'] - remove_terminal = ['Puerto de la Luz LNG Terminal','Gran Canaria LNG Terminal'] - - for index in df.index: - if df.Status[index] in remove_status: - df = df.drop([index]) - elif df.Country[index] in remove_country: - df = df.drop([index]) - elif df.TerminalName[index] in remove_terminal: - df = df.drop([index]) - elif df.CapacityInMtpa[index] == "--": - df = df.drop([index]) - else: - continue - - geometry = gpd.points_from_xy(df['Longitude'], df['Latitude']) - gdf = gpd.GeoDataFrame(df, geometry=geometry, crs="EPSG:4326") - return gdf - def build_gas_input_locations(lng_fn, entry_fn, prod_fn, countries): # LNG terminals - lng = read_lng_gem(lng_fn) + lng = gpd.read_file(lng_fn) # Entry points from outside the model scope entry = read_scigrid_gas(entry_fn) diff --git a/scripts/retrieve_gas_input_locations.py b/scripts/retrieve_gas_input_locations.py new file mode 100644 index 00000000..82840196 --- /dev/null +++ b/scripts/retrieve_gas_input_locations.py @@ -0,0 +1,50 @@ +""" +Retrieve gas infrastructure data fro +""" + +import logging +from helper import progress_retrieve + +import zipfile +from pathlib import Path + +logger = logging.getLogger(__name__) + + +if __name__ == "__main__": + if 'snakemake' not in globals(): + from helper import mock_snakemake + snakemake = mock_snakemake('retrieve_gas_network_data') + rootpath = '..' + else: + rootpath = '.' + +# LNG terminals + + lng_url="https://globalenergymonitor.org/wp-content/uploads/2022/09/Europe-Gas-Tracker-August-2022.xlsx", + + storage_options = {'User-Agent': 'Mozilla/5.0'} + df = pd.read_excel(lng_url, storage_options=storage_options, sheet_name = 'LNG terminals - data') + #df = pd.read_excel(fn, sheet_name = 'LNG terminals - data') + df = df.set_index("ComboID") + + remove_status = ['Cancelled'] + remove_country = ['Cyprus','Turkey'] + remove_terminal = ['Puerto de la Luz LNG Terminal','Gran Canaria LNG Terminal'] + + for index in df.index: + if df.Status[index] in remove_status: + df = df.drop([index]) + elif df.Country[index] in remove_country: + df = df.drop([index]) + elif df.TerminalName[index] in remove_terminal: + df = df.drop([index]) + elif df.CapacityInMtpa[index] == "--": + df = df.drop([index]) + else: + continue + + geometry = gpd.points_from_xy(df['Longitude'], df['Latitude']) + lng = gpd.GeoDataFrame(df, geometry=geometry, crs="EPSG:4326") + + lng.to_file(snakemake.output[0]) \ No newline at end of file