-
Notifications
You must be signed in to change notification settings - Fork 3
Adapt ERA5 atmospheric forcing generation script #22
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
Open
s-poll
wants to merge
21
commits into
main
Choose a base branch
from
dev-atmforcing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1f3804d
rewrite download ERA5 based on new CDSAPI
s-poll f331c9e
adapt ERA5 meteocloud script and wrapper
s-poll 95c1b66
Rewrite prepare ERA5 script
s-poll ba833bb
update README and clean-up
s-poll 1ec7e5c
enhance extract_ERA5_meteocloud.sh
s-poll 926d4b9
add download_ERA5 wrapper
s-poll 75a1755
add year/month info to download_era5
s-poll 05cca5c
replace unzip with python command
s-poll a737522
fix hr loop in extract_ERA5_meteocloud.sh
s-poll 02dcd7f
use ncks for global attributes
s-poll 858634d
add OpenMP threads to CDO remap in prepare_ERA5_input.sh
s-poll 898b539
Cleaned up scripts
mvhulten 4ee3f8d
Linked to information and clarified
mvhulten 62961e7
Corrected info on access to ERA5 data
mvhulten 7fd7b35
README updates for `mkforcing/`
jjokella fcc3bea
`devel` does not allow for 12h-job
jjokella dcb4c22
`seq -w`: month string with width 2 (e.g. 03)
jjokella 46647a5
make directory and pass inputs to script
jjokella aee694e
remove option `e` from `set` command
jjokella e6ede36
README: usage of extract_ERA5_meteocloud wrapper script
jjokella 4a3a8e7
README: fix, no command for `cdo griddes` command
jjokella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,80 @@ | ||
#!/usr/bin/env python3 | ||
import calendar | ||
import cdsapi | ||
import sys | ||
import os | ||
|
||
def generate_days(year, month): | ||
# Get the number of days in the given month | ||
num_days = calendar.monthrange(year, month)[1] | ||
|
||
# Generate the list of days as integers | ||
days = [day for day in range(1, num_days + 1)] | ||
|
||
return days | ||
|
||
def generate_datarequest(year, monthstr, days): | ||
|
||
# active download client for climate data service (cds) | ||
client = cdsapi.Client() | ||
mvhulten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# dataset to download rom cds | ||
dataset = "reanalysis-era5-single-levels" | ||
# request for cds | ||
request = { | ||
"product_type": ["reanalysis"], | ||
"variable": [ | ||
"surface_pressure", | ||
"mean_surface_downward_long_wave_radiation_flux", | ||
"mean_surface_downward_short_wave_radiation_flux", | ||
"mean_total_precipitation_rate" | ||
], | ||
"year": [str(year)], | ||
"month": [monthstr], | ||
"day": days, | ||
"time": [ | ||
"00:00", "01:00", "02:00", | ||
"03:00", "04:00", "05:00", | ||
"06:00", "07:00", "08:00", | ||
"09:00", "10:00", "11:00", | ||
"12:00", "13:00", "14:00", | ||
"15:00", "16:00", "17:00", | ||
"18:00", "19:00", "20:00", | ||
"21:00", "22:00", "23:00" | ||
], | ||
"data_format": "netcdf", | ||
"download_format": "unarchived", | ||
"area": [74, -42, 20, 69] | ||
} | ||
# filename of downloaded file | ||
target = 'download_era5_'+str(year)+'_'+monthstr+'.zip' | ||
|
||
# Get the data from cds | ||
client.retrieve(dataset, request, target) | ||
|
||
if __name__ == "__main__": | ||
# Check if the correct number of arguments are provided | ||
if len(sys.argv) != 4: | ||
print("Usage: python download_ERA5_input.py <year> <month> <output_directory>") | ||
sys.exit(1) | ||
|
||
# Get the year and month from command-line arguments | ||
year = int(sys.argv[1]) | ||
month = int(sys.argv[2]) | ||
dirout = sys.argv[3] | ||
|
||
# Ensure the output directory exists, if not, create it | ||
if not os.path.exists(dirout): | ||
os.makedirs(dirout) | ||
|
||
# change to output directory | ||
os.chdir(dirout) | ||
|
||
# Format the month with a leading zero if needed | ||
monthstr = f"{month:02d}" | ||
|
||
# Get the list of days for the request | ||
days = generate_days(year, month) | ||
|
||
# do download request | ||
generate_datarequest(year, monthstr, days) |
This file contains hidden or 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,50 @@ | ||
#!/usr/bin/env bash | ||
# Before using this script CDSAPI has to be configured (see README) | ||
# Needs to be executed at LOGIN node as connection to "outside" is required | ||
set -eo pipefail | ||
|
||
# load environment | ||
module load Python | ||
|
||
# Settings | ||
start_date="2017-07" # yyyy-mm | ||
end_date="2018-08" # yyyy-mm + 1 | ||
out_dir="cdsapidwn" | ||
|
||
# Function to parse input | ||
parse_arguments() { | ||
for arg in "$@"; do | ||
key="${arg%%=*}" | ||
value="${arg#*=}" | ||
|
||
case "$key" in | ||
start_date) start_date="$value" ;; | ||
end_date) end_date="$value" ;; | ||
out_dir) out_dir="$value" ;; | ||
*) echo "Warning: Unknown parameter: $key" ;; | ||
esac | ||
done | ||
} | ||
|
||
# Call the function to parse the input arguments | ||
# Users needs to make sure for consistent input | ||
parse_arguments "$@" | ||
|
||
|
||
# create output directory | ||
mkdir -p $out_dir | ||
|
||
# loop over months | ||
current_date=$start_date | ||
while [[ "$current_date" < "$end_date" ]]; do | ||
echo "Processing month: $current_date" | ||
|
||
year="${current_date%%-*}" | ||
month="${current_date#*-}" | ||
|
||
# start download script with data request | ||
./download_ERA5_input.py $year $month $out_dir | ||
|
||
# Increment the month | ||
current_date=$(date -I -d "$current_date-01 + 1 month" | cut -d'-' -f1,2) | ||
done |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we include a
pip install cdsapi
in the README?This would be the first time that this is needed (the rest we relied on modules).
edit: ah, except for the NCL script they need to evben do a
conda install ncl
!To some extend, mess must maybe be accepted…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed; it is written in the linked documentation.