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

Restyle Generalize retrieve databundle #270

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
e389c0f
Draft bundle file configurations
davide-f Feb 6, 2022
95da5a9
Revision bundle config
davide-f Feb 6, 2022
0c2cbf1
Modify Snakemake and draft of retrieve_databundle
davide-f Feb 6, 2022
403a0ba
First implementation of flexible bundles specified by config.yaml
davide-f Feb 6, 2022
8d09a20
Update release_notes
davide-f Feb 6, 2022
00dc1f4
Add bundle_config docstring and specify urls for selection of bundles
davide-f Feb 15, 2022
0aebc7b
Merge branch 'pypsa-meets-africa:main' into generalize-retrieve_datab…
davide-f Feb 15, 2022
333f31e
Set bundle_data countries according to world_iso
davide-f Feb 15, 2022
4029c74
contrib-readme-action has updated readme
Feb 15, 2022
8e8cf92
Re-enable comments in yaml format
davide-f Feb 15, 2022
92fd949
Improve bundle selection algorithm: select bundles till matching each…
davide-f Feb 15, 2022
b0f6da2
Add summary
davide-f Feb 15, 2022
f6958b5
Add debug notebook and revise downloading data_bundle
davide-f Feb 15, 2022
c06917d
Revise data_bundle.yaml
davide-f Feb 16, 2022
db01c1c
Typo
davide-f Feb 16, 2022
6c8fd4b
Remove typo
davide-f Feb 16, 2022
008e51f
Improve bundle_configs links and code; bug fixing
davide-f Feb 16, 2022
d3ae35e
Fixing tutorial data google drive
davide-f Feb 16, 2022
e4adb40
Update bundle data with sandbox zenodo
davide-f Feb 16, 2022
2b4dbd1
Standardization bundle_config and improvement zips
davide-f Feb 16, 2022
97c5cdb
Update tutorial google drive links
davide-f Feb 16, 2022
6ee6b96
Add test zenodo links for all bundles to bundle_configs
davide-f Feb 16, 2022
2ffd216
Add docstring and add hot_run parameter when downloading files for te…
davide-f Feb 16, 2022
42592ad
Typo zenodo link
davide-f Feb 16, 2022
f6d7149
Add and improve docstrings
davide-f Feb 16, 2022
9642699
Specify folder cutouts_africa
davide-f Feb 16, 2022
bc63019
Restyled by autopep8
restyled-commits Feb 16, 2022
074156b
Restyled by black
restyled-commits Feb 16, 2022
32a2a90
Restyled by isort
restyled-commits Feb 16, 2022
4eae550
Restyled by reorder-python-imports
restyled-commits Feb 16, 2022
e8073a5
Restyled by whitespace
restyled-commits Feb 16, 2022
aa57d6f
Restyled by yapf
restyled-commits Feb 16, 2022
ade6ad4
Merge https://github.com/davide-f/pypsa-africa into generalize-retrie…
davide-f Feb 16, 2022
5a21c69
Add retrieve_bundle outputs and adapt bundles
davide-f Feb 16, 2022
02d025f
Fix hydrobasins dependencies for general case
davide-f Feb 16, 2022
aa2c22f
Use tqdm instead of progressbar for progress_retrieve
davide-f Feb 16, 2022
53303ba
Generalize hydrobasins and minor edits
davide-f Feb 16, 2022
7e3d011
Round progress bar to the first 0.01
davide-f Feb 16, 2022
f53b72e
Revise hydro profiles to avoid computational issues with large hydrob…
davide-f Feb 16, 2022
4bac295
Revise hydro calculation
davide-f Feb 16, 2022
45066c4
Revise link common_data
davide-f Feb 16, 2022
c769953
Restyled by autopep8
restyled-commits Feb 16, 2022
f92e829
Restyled by black
restyled-commits Feb 16, 2022
cf95908
Restyled by isort
restyled-commits Feb 16, 2022
e472bf0
Restyled by reorder-python-imports
restyled-commits Feb 16, 2022
3abadf2
Restyled by yapf
restyled-commits Feb 16, 2022
0fd6feb
Update docstring and description retrieve_databundle
davide-f Feb 17, 2022
fab0918
Restyled by autopep8
restyled-commits Feb 17, 2022
4174e27
Restyled by black
restyled-commits Feb 17, 2022
17aa735
Restyled by isort
restyled-commits Feb 17, 2022
14ace7b
Restyled by reorder-python-imports
restyled-commits Feb 17, 2022
c1d1ba4
Restyled by whitespace
restyled-commits Feb 17, 2022
a541c85
Restyled by yapf
restyled-commits Feb 17, 2022
c9f4701
Revise docstring
davide-f Feb 17, 2022
851655c
Add comments in the hydrobasins calculation
davide-f Feb 17, 2022
c9bc250
Restyled by autopep8
restyled-commits Feb 17, 2022
c1d4dd0
Restyled by black
restyled-commits Feb 17, 2022
17991a0
Restyled by isort
restyled-commits Feb 17, 2022
11aef30
Restyled by reorder-python-imports
restyled-commits Feb 17, 2022
067f01a
Restyled by yapf
restyled-commits Feb 17, 2022
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
5 changes: 4 additions & 1 deletion Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ datafiles = [
"data/raw/gebco/GEBCO_2021_TID.nc",
"data/raw/eez/eez_v11.gpkg",
# "data/raw/landcover", # set as an explicit directory in the rule
"data/raw/hydrobasins/hybas_lake_af_lev04_v1c.shp",
"data/raw/hydrobasins/hybas_world_lev04_v1c.shp",
"data/custom_powerplants.csv",
"data/hydro_capacities.csv",
"data/costs.csv",
]

Expand All @@ -67,6 +69,7 @@ if config.get('tutorial')==True:

if config['enable'].get('retrieve_databundle', True):
rule retrieve_databundle_light:
input: "configs/bundle_config.yaml"
output: #expand(directory('{file}') if isdir('{file}') else '{file}', file=datafiles)
expand('{file}', file=datafiles),
directory("data/raw/landcover")
Expand Down
2 changes: 1 addition & 1 deletion config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ renewable:
cutout: africa-2013-era5
resource:
method: hydro
hydrobasins: data/raw/hydrobasins/hybas_lake_af_lev04_v1c.shp
hydrobasins: data/raw/hydrobasins/hybas_world_lev04_v1c.shp
# flowspeed: 1.0
# weight_with_height: false
# show_progress: true
Expand Down
2 changes: 1 addition & 1 deletion config.tutorial.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ renewable:
cutout: africa-2013-era5-tutorial
resource:
method: hydro
hydrobasins: data/raw/hydrobasins/hybas_lake_af_lev04_v1c.shp
hydrobasins: data/raw/hydrobasins/hybas_world_lev04_v1c.shp
# flowspeed: 1.0
# weight_with_height: false
# show_progress: true
Expand Down
113 changes: 113 additions & 0 deletions configs/bundle_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# SPDX-FileCopyrightText: : 2021 The PyPSA-Africa Authors
#
# SPDX-License-Identifier: CC0-1.0

# File describing the data bundle configurations that can be downloaded
# by using the retrieve_databundle fule

# Each bundle shall have the following structure:

# .. code:: yaml

# bundle_name: # name of the bundle
# countries: [country code, region code or country list] # list of countries represented in the databundle
# [tutorial: true/false] # (optional, default false) whether the bundle is a tutorial or not
# category: common/resources/data/cutouts # category of data contained in the bundle:
# destination: "." # folder where to unzip the files with respect to the repository root (\"\" or \".\")
# urls: # list of urls by source, e.g. zenodo or google
# zenodo: {zenodo url}
# google: {google url}


# tutorial bundle specific for Nigeria and Benin only
bundle_data_tutorial:
countries: [NG, BJ]
tutorial: true
category: data
destination: "data"
urls:
zenodo: https://sandbox.zenodo.org/record/1016522/files/tutorial_data.zip?download=1
google: https://drive.google.com/file/d/1Yd2iM892WFBRxh5NX22if6laRF1RxZKu/view?usp=sharing

# tutorial bundle specific for Nigeria and Benin only
bundle_resources_tutorial:
countries: [NG, BJ]
tutorial: true
category: resources
destination: "resources"
urls:
zenodo: https://sandbox.zenodo.org/record/1016001/files/tutorial_resources.zip?download=1
google: https://drive.google.com/file/d/1WWVyXHA2E7aGcg_OC1lN8Pb2tA8DgfU0/view?usp=sharing

# tutorial bundle specific for Nigeria and Benin only
bundle_cutouts_tutorial:
countries: [NG, BJ]
tutorial: true
category: cutouts
destination: "cutouts"
urls:
zenodo: https://sandbox.zenodo.org/record/1016015/files/tutorial_cutouts.zip?download=1
google: https://drive.google.com/file/d/1Lro4X92sVuD30C0B3sQ2jJU37uZ50DWi/view?usp=sharing

# data bundle containing the data of the data folder common to all regions of the world
bundle_data_world:
countries: [world]
category: common
destination: "data"
urls:
zenodo: https://sandbox.zenodo.org/record/1016540/files/common_data.zip?download=1
google: https://drive.google.com/file/d/1fo-YsyU2LKkVeg5Ea0JbcEx-zQ3kJKW7/view?usp=sharing

# resources bundle containing the resources folder for africa only
bundle_resources_africa:
countries: [africa]
category: resources
destination: "resources"
urls:
zenodo: https://sandbox.zenodo.org/record/1016042/files/resources_africa.zip?download=1
google: https://drive.google.com/file/d/1he31BBLtdemZt2dmBOwUCbP_jVuI3KS8/view?usp=sharing

# data bundle of the data folder for the african continent
bundle_landcover_africa:
countries: [africa]
category: landcover
destination: "data/raw/landcover"
urls:
zenodo: https://sandbox.zenodo.org/record/1016042/files/landcover_africa.zip?download=1
google: https://drive.google.com/file/d/1l6Xgr3PXyvgqWaXUbto9zvvMS_OgSjvG/view?usp=sharing

# data bundle of the data folder for the african continent
bundle_landcover_asiapacific:
countries: [asia, australia-oceania]
category: landcover
destination: "data/raw/landcover"
urls:
zenodo: https://sandbox.zenodo.org/record/1016042/files/landcover_asiapacific.zip?download=1
google: https://drive.google.com/file/d/1-bevGdoAltJ1useZAS9PqEMDJQLyBEn8/view?usp=sharing

# data bundle of the data folder for the african continent
bundle_landcover_latinamerica_caribbean:
countries: [latin_america, central_america]
category: landcover
destination: "data/raw/landcover"
urls:
zenodo: https://sandbox.zenodo.org/record/1016042/files/landcover_latinamerica_caribbean.zip?download=1
google: https://drive.google.com/file/d/16GiEqdUcX0juGHaAxk5q9XlgUl2T7eVf/view?usp=sharing

# data bundle of the data folder for the african continent
bundle_landcover_westasia:
countries: [WAS]
category: landcover
destination: "data/raw/landcover"
urls:
zenodo: https://sandbox.zenodo.org/record/1016042/files/landcover_westasia.zip?download=1
google: https://drive.google.com/file/d/1QDFn-USxTEToFrST8Iazj9Cz_mcXEwiP/view?usp=sharing

# cutouts bundle of the cutouts folder for the african continent
bundle_cutouts_africa:
countries: [africa]
category: cutouts
destination: "cutouts"
urls:
zenodo: https://sandbox.zenodo.org/record/1016042/files/cutouts_africa.zip?download=1
google: https://drive.google.com/file/d/1-Njs7BqG0YE5QwBHj0zgkdicb5IQvQCh/view
2 changes: 1 addition & 1 deletion doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Upcoming Release

* Rule build_shape extended to the world

* Replace google by zenodo data retrieval
* Generalized version of Data retrieval with google and zenodo hosting platforms

* Fix random state for kmean clustering, `adopted from PR <https://github.com/PyPSA/pypsa-eur/pull/313>`

Expand Down
1 change: 0 additions & 1 deletion envs/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ dependencies:
- networkx
- scipy
- shapely>=1.8a1
- progressbar2
- pre-commit
- pyomo
- matplotlib
Expand Down
244 changes: 244 additions & 0 deletions notebooks/old notebooks/address_hydrosheds.ipynb

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,14 @@ def aggregate_costs(n, flatten=False, opts=None, existing_only=False):
def progress_retrieve(url, file):
import urllib

from progressbar import ProgressBar
from tqdm import tqdm

pbar = ProgressBar(0, 100)
pbar = tqdm(total=100)

def dlProgress(count, blockSize, totalSize):
pbar.update(int(count * blockSize * 100 / totalSize))
pbar.n = round(
count * blockSize * 100 / totalSize * 100) / 100 # round to 0.01
pbar.refresh()

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

Expand Down
10 changes: 8 additions & 2 deletions scripts/build_renewable_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,19 @@

# filter plants for hydro
if snakemake.wildcards.technology.startswith("hydro"):
country_shapes = gpd.read_file(paths.country_shapes)
hydrobasins = gpd.read_file(resource["hydrobasins"])
merged_hydrobasin_shape = unary_union(hydrobasins.geometry)
hydrobasins = hydrobasins[[
any(country_shapes.geometry.intersects(geom))
for geom in hydrobasins.geometry
]] # exclude hydrobasins shapes that do not intersect the countries of interest
resource["plants"] = regions.rename(columns={
"x": "lon",
"y": "lat"
})[[
merged_hydrobasin_shape.intersects(p)
# select busbar whose location (p)
any(hydrobasins.geometry.intersects(p))
# belongs to at least one hydrobasin geometry
for p in gpd.points_from_xy(regions.x, regions.y, crs=regions.crs)
]] # TODO: filtering by presence of hydro generators should be the way to go

Expand Down
Loading