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

Fix ci #322

Merged
merged 5 commits into from
Apr 10, 2022
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
6 changes: 6 additions & 0 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ wildcard_constraints:
opts="[-+a-zA-Z0-9\.]*",


rule run_test:
run:
shell("cp test/config.test1.yaml config.yaml")
shell("snakemake --cores all solve_all_networks --forceall")


rule solve_all_networks:
input:
expand(
Expand Down
1 change: 0 additions & 1 deletion configs/bundle_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ databundles:
gdrive: https://drive.google.com/file/d/1WWVyXHA2E7aGcg_OC1lN8Pb2tA8DgfU0/view?usp=sharing
output:
- resources/ssp2-2.6/2030/era5_2013/Africa.nc
- resources/natura.tiff

# tutorial bundle specific for Nigeria and Benin only
bundle_cutouts_tutorial:
Expand Down
2 changes: 1 addition & 1 deletion doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Upcoming Release

**New Features and major Changes**


* Bug fixing (script retrieve_databundle) and rule run_test to ease testing `PR #322 <https://github.com/pypsa-meets-africa/pypsa-africa/pull/322>`__

PyPSA-Africa 0.0.2 (6th April 2022)
=====================================
Expand Down
73 changes: 73 additions & 0 deletions scripts/retrieve_databundle_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,79 @@ def download_and_unzip_zenodo(config, rootpath, hot_run=True, disable_progress=F
return True


def download_and_unzip_gdrive(config, rootpath, hot_run=True, disable_progress=False):
"""
download_and_unzip_gdrive(config, rootpath, dest_path, hot_run=True, disable_progress=False)

Function to download and unzip the data from google drive

Inputs
------
config : Dict
Configuration data for the category to download
rootpath : str
Absolute path of the repository
hot_run : Bool (default True)
When true the data are downloaded
When false, the workflow is run without downloading and unzipping
disable_progress : Bool (default False)
When true the progress bar to download data is disabled

Outputs
-------
True when download is successful, False otherwise

"""
resource = config["category"]
file_path = os.path.join(rootpath, "tempfile.zip")

url = config["urls"]["gdrive"]

# retrieve file_id from path
# cut the part before the ending \view
partition_view = re.split(r"/view|\\view", str(url), 1)
if len(partition_view) < 2:
logger.error(
f'Resource {resource} cannot be downloaded: "\\view" not found in url {url}'
)
return False

# split url to get the file_id
code_split = re.split(r"\\|/", partition_view[0])

if len(code_split) < 2:
logger.error(
f'Resource {resource} cannot be downloaded: character "\\" not found in {partition_view[0]}'
)
return False

# get file id
file_id = code_split[-1]

# if hot run enabled
if hot_run:
# remove file
if os.path.exists(file_path):
os.remove(file_path)
# download file from google drive
gdd.download_file_from_google_drive(
file_id=file_id,
dest_path=file_path,
showsize=True,
unzip=False,
)
with ZipFile(file_path, "r") as zipObj:
# Extract all the contents of zip file in current directory
zipObj.extractall(path=config["destination"])

logger.info(f"Download resource '{resource}' from cloud '{url}'.")

return True
else:
logger.error(f"Host {host} not implemented")
return False


def download_and_unzip_protectedplanet(
config, rootpath, hot_run=True, disable_progress=False
):
Expand Down