Created
March 23, 2023 02:58
-
-
Save bennyistanto/893a5faaa72367b9ab1d433e72965858 to your computer and use it in GitHub Desktop.
Download ERA5-Land daily total precipitation and save as 1 year data in 1 netCDF file
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
# -*- coding: utf-8 -*- | |
""" | |
NAME | |
download_era5land_precipitation.py | |
DESCRIPTION | |
Download ERA5-Land daily total precipitation and save as 1 year data in 1 netCDF file. | |
REQUIREMENT | |
You must registered as CDS Copernicus user, and access your profile to get UID and Api Key | |
EXAMPLES | |
python download_era5land_precipitation.py | |
NOTES | |
This script only download for time 00:00, as ERA5-Land Hourly the precipitation values | |
are totals since the beginning of each day. This means that daily totals from ERA5-Land Hourly | |
are not the sum of the precipitation values for each hour, but is the precipitation value for | |
the 00:00 hour of the next day. | |
Reference: https://confluence.ecmwf.int/pages/viewpage.action?pageId=197702790 see row 5 col 7. | |
So the result from this script for each day actually shifted for +1 day. To get the correct date, | |
You can do further process using CDO with command: cdo -shifttime,-1day in.nc out.nc | |
CONTACT | |
Benny Istanto | |
Climate Geographer | |
GOST, The World Bank | |
LICENSE | |
This script is in the public domain, free from copyrights or restrictions. | |
VERSION | |
$Id$ | |
TODO | |
xx | |
""" | |
import os | |
import cdsapi | |
c = cdsapi.Client(key = "UID:ApiKey") #Replace UID:ApiKey with you UID and Api Key | |
years = list(range(1950, 2023)) | |
for year in years: | |
c.retrieve( | |
'reanalysis-era5-land', | |
{ | |
'variable': [ | |
'total_precipitation', | |
], | |
'year': str(year), | |
'month': [ | |
'01', '02', '03', | |
'04', '05', '06', | |
'07', '08', '09', | |
'10', '11', '12', | |
], | |
'day': [ | |
'01', '02', '03', | |
'04', '05', '06', | |
'07', '08', '09', | |
'10', '11', '12', | |
'13', '14', '15', | |
'16', '17', '18', | |
'19', '20', '21', | |
'22', '23', '24', | |
'25', '26', '27', | |
'28', '29', '30', | |
'31', | |
], | |
'time': [ | |
'00:00', | |
], | |
'area': [ | |
11, 90, -13, 145, # Bounding box for Indonesia | |
], | |
'format': 'netcdf', | |
}, | |
'era5land_' + str(year) + '.nc') | |
print('era5land_' + str(year) + '.nc' + ' downloaded.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment