Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…r-data Add function to download cleaned MaStR data from Zenodo. Post-processing of this data will happen in #134
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from urllib.request import urlretrieve | ||
import os | ||
|
||
import egon.data.config | ||
|
||
|
||
def download_mastr_data(data_stages=None): | ||
""" | ||
Download MaStR data from Zenodo | ||
Parameters | ||
---------- | ||
data_stages: list | ||
Select data stages you want to download data for. Possible values: | ||
'raw', 'cleaned'. Defaults to 'cleaned' if omitted. | ||
""" | ||
# Process inputs | ||
if not data_stages: | ||
data_stages = ["cleaned"] | ||
|
||
# Get parameters from config and set download URL | ||
data_config = egon.data.config.datasets()["mastr"] | ||
zenodo_files_url = ( | ||
f"https://sandbox.zenodo.org/record/{data_config['deposit_id']}/files/" | ||
) | ||
|
||
files = [] | ||
for technology in data_config["technologies"]: | ||
# Download raw data | ||
if "raw" in data_stages: | ||
files.append( | ||
f"{data_config['file_basename']}_{technology}_raw.csv" | ||
) | ||
# Download cleaned data | ||
if "cleaned" in data_stages: | ||
files.append( | ||
f"{data_config['file_basename']}_{technology}_cleaned.csv" | ||
) | ||
files.append("datapackage.json") | ||
|
||
# Retrieve specified files | ||
for filename in files: | ||
if not os.path.isfile(filename): | ||
urlretrieve(zenodo_files_url + filename, filename) |