Skip to content

Commit

Permalink
Merge pull request pypsa-meets-earth#919 from ekatef/load_hydrobasins
Browse files Browse the repository at this point in the history
Add load of hydrobasins data
  • Loading branch information
davide-f authored Nov 29, 2023
2 parents 35ada5e + 92e1fce commit 69d4064
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 36 deletions.
1 change: 1 addition & 0 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ if config["enable"].get("retrieve_databundle", True):
params:
countries=config["countries"],
tutorial=config["tutorial"],
hydrobasins_level=config["renewable"]["hydro"]["hydrobasins_level"],
output: #expand(directory('{file}') if isdir('{file}') else '{file}', file=datafiles)
expand("{file}", file=datafiles_retrivedatabundle(config)),
directory("data/landcover"),
Expand Down
3 changes: 2 additions & 1 deletion config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,10 @@ renewable:
extendable: true
hydro:
cutout: cutout-2013-era5
hydrobasins_level: 6
resource:
method: hydro
hydrobasins: data/hydrobasins/hybas_world_lev06_v1c.shp
hydrobasins: data/hydrobasins/hybas_world.shp
flowspeed: 1.0 # m/s
# weight_with_height: false
# show_progress: true
Expand Down
3 changes: 2 additions & 1 deletion config.tutorial.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ renewable:
extendable: true
hydro:
cutout: cutout-2013-era5-tutorial
hydrobasins_level: 4
resource:
method: hydro
hydrobasins: data/hydrobasins/hybas_world_lev04_v1c.shp
hydrobasins: data/hydrobasins/hybas_world.shp
flowspeed: 1.0 # m/s
# weight_with_height: false
# show_progress: true
Expand Down
47 changes: 35 additions & 12 deletions configs/bundle_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ databundles:
category: data
destination: "data"
urls:
zenodo: https://sandbox.zenodo.org/record/1223907/files/tutorial_data_NGBJ.zip?download=1
zenodo: https://sandbox.zenodo.org/records/3853/files/bundle_tutorial_NGBJ.zip?download=1
gdrive: https://drive.google.com/file/d/1Vb1ISjhy7iwTTZYeezGd6S4nLt-EDGme/view?usp=drive_link
output:
- data/gebco/GEBCO_2021_TID.nc
Expand All @@ -49,7 +49,7 @@ databundles:
category: data
destination: "data"
urls:
zenodo: https://sandbox.zenodo.org/record/1223907/files/tutorial_data_BW.zip?download=1
zenodo: https://sandbox.zenodo.org/records/3853/files/bundle_tutorial_BW.zip?download=1
gdrive: https://drive.google.com/file/d/19IXvTD8gVSzgTInL85ta7QjaNI8ZPCCY/view?usp=drive_link
output:
- data/gebco/GEBCO_2021_TID.nc
Expand All @@ -62,20 +62,34 @@ databundles:
category: data
destination: "data"
urls:
zenodo: https://sandbox.zenodo.org/record/1223907/files/tutorial_data_MA.zip?download=1
zenodo: https://sandbox.zenodo.org/records/3853/files/bundle_tutorial_MA.zip?download=1
gdrive: https://drive.google.com/file/d/1VGzE8ZJHAvAQ9X44QNSX4rH3QF7Yi37D/view?usp=drive_link
output:
- data/gebco/GEBCO_2021_TID.nc
- data/copernicus/PROBAV_LC100_global_v3.0.1_2019-nrt_Discrete-Classification-map_EPSG-4326.tif

# load tutorial hydrobasins bundle for Africa only
bundle_tutorial_hydrobasins:
countries: [Africa]
tutorial: true
category: hydrobasins
destination: "data/hydrobasins"
urls:
hydrobasins:
base_url: https://data.hydrosheds.org/file/HydroBASINS/standard/
suffixes: ["af"]
unzip: true
output:
- data/hydrobasins/hybas_world.shp

# tutorial bundle specific for Nigeria and Benin only
bundle_cutouts_tutorial_NGBJ:
countries: [NG, BJ]
tutorial: true
category: cutouts
destination: "cutouts"
urls:
zenodo: https://sandbox.zenodo.org/record/1223907/files/tutorial_cutouts_NGBJ.zip?download=1
zenodo: https://sandbox.zenodo.org/records/3853/files/bundle_cutouts_tutorial_NGBJ.zip?download=1
gdrive: https://drive.google.com/file/d/1xnomHdXf_c5STrf7jtDiuRlN2zW0FSVC/view?usp=drive_link
output: [cutouts/cutout-2013-era5-tutorial.nc]
disable_by_opt:
Expand All @@ -88,7 +102,7 @@ databundles:
category: cutouts
destination: "cutouts"
urls:
zenodo: https://sandbox.zenodo.org/record/1223907/files/tutorial_cutouts_BW.zip?download=1
zenodo: https://sandbox.zenodo.org/records/3853/files/bundle_cutouts_tutorial_BW.zip?download=1
gdrive: https://drive.google.com/file/d/1DDQAtnIDM0FNC3vCldfHeH__IpTbyIJt/view?usp=drive_link
output: [cutouts/cutout-2013-era5-tutorial.nc]
disable_by_opt:
Expand All @@ -101,7 +115,7 @@ databundles:
category: cutouts
destination: "cutouts"
urls:
zenodo: https://sandbox.zenodo.org/record/1223907/files/tutorial_cutouts_MA.zip?download=1
zenodo: https://sandbox.zenodo.org/records/3853/files/bundle_cutouts_tutorial_MA.zip?download=1
gdrive: https://drive.google.com/file/d/1j5v2f4E756jmDMa707QvdNJq3xM4bYUk/view?usp=drive_link
output: [cutouts/cutout-2013-era5-tutorial.nc]
disable_by_opt:
Expand All @@ -125,21 +139,30 @@ databundles:
category: common
destination: "data"
urls:
zenodo: https://sandbox.zenodo.org/record/1183583/files/tutorial_data_general.zip?download=1
zenodo: https://sandbox.zenodo.org/records/3853/files/tutorial_data_general.zip?download=1
gdrive: https://drive.google.com/file/d/1nRLrs_kP0qVl-IHC4BFLjpoKa3HLk2Py/view
output:
- data/costs.csv
- data/hydro_capacities.csv
- data/custom_powerplants.csv
- data/eez/eez_v11.gpkg
- data/ssp2-2.6/2030/era5_2013/Africa.nc
- data/ssp2-2.6/2030/era5_2013/Asia.nc
- data/ssp2-2.6/2030/era5_2013/Europe.nc
- data/ssp2-2.6/2030/era5_2013/NorthAmerica.nc
- data/ssp2-2.6/2030/era5_2013/SouthAmerica.nc
- data/ssp2-2.6/2030/era5_2013/Oceania.nc
- data/hydrobasins/hybas_world_lev04_v1c.shp
- data/hydrobasins/hybas_world_lev05_v1c.shp

# global data for hydrobasins
bundle_hydrobasins:
countries: [Earth]
tutorial: false
category: hydrobasins
destination: "data/hydrobasins"
urls:
hydrobasins:
base_url: https://data.hydrosheds.org/file/HydroBASINS/standard/
suffixes: ["af", "ar", "as", "au", "eu", "gr", "na", "sa", "si"]
unzip: true
output:
- data/hydrobasins/hybas_world.shp

# data bundle containing the data of the data folder common to all regions of the world
bundle_data_earth:
Expand Down
2 changes: 2 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ E.g. if a new rule becomes available describe how to use it `snakemake -j1 run_t

* Improve retrieve_databundle to prioritize smallest databundles `PR #911 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/911>`__

* Add functionality to load shapefiles for hydrobasins directly from the data source directly `PR #919 <https://github.com/pypsa-meets-earth/pypsa-earth/pull/919>`__


PyPSA-Earth 0.2.3
=================
Expand Down
15 changes: 11 additions & 4 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ def aggregate_costs(n, flatten=False, opts=None, existing_only=False):
return costs


def progress_retrieve(url, file, data=None, disable_progress=False, roundto=1.0):
def progress_retrieve(
url, file, data=None, headers=None, disable_progress=False, roundto=1.0
):
"""
Function to download data from a url with a progress bar progress in
retrieving data.
Expand Down Expand Up @@ -418,6 +420,11 @@ def dlProgress(count, blockSize, totalSize, roundto=roundto):
if data is not None:
data = urllib.parse.urlencode(data).encode()

if headers:
opener = urllib.request.build_opener()
opener.addheaders = headers
urllib.request.install_opener(opener)

urllib.request.urlretrieve(url, file, reporthook=dlProgress, data=data)


Expand Down Expand Up @@ -523,7 +530,7 @@ def make_accessable(*ios):
return snakemake


def getContinent(code):
def getContinent(code, world_iso=read_osm_config("world_iso")):
"""
Returns continent names that contains list of iso-code countries.
Expand All @@ -547,7 +554,6 @@ def getContinent(code):

continent_list = []
code_set = set(code)
world_iso = read_osm_config("world_iso")
for continent in world_iso.keys():
single_continent_set = set(world_iso[continent])
if code_set.intersection(single_continent_set):
Expand Down Expand Up @@ -787,9 +793,10 @@ def filter_codes(c_list, iso_coding=True):

full_codes_list = []

world_iso, continent_regions = read_osm_config("world_iso", "continent_regions")

for value1 in input:
codes_list = []
world_iso, continent_regions = read_osm_config("world_iso", "continent_regions")
# extract countries in world
if value1 == "Earth":
for continent in world_iso.keys():
Expand Down
Loading

0 comments on commit 69d4064

Please sign in to comment.