Skip to content

Instantly share code, notes, and snippets.

@bennyistanto
Created May 4, 2023 02:11
Show Gist options
  • Save bennyistanto/7cfdaedbbd91a89a80d069902b76059d to your computer and use it in GitHub Desktop.
Save bennyistanto/7cfdaedbbd91a89a80d069902b76059d to your computer and use it in GitHub Desktop.
Download ERA5 Agrometeorological Indicators and save as 1 month data in 1 netCDF file
"""
NAME
download_era5_agromet.py
DESCRIPTION
Download ERA5 Agrometeorological Indicators and save as 1 month data in 1 netCDF file.
REQUIREMENT
You must registered as CDS Copernicus user, and access your profile to get UID and Api Key
You need to install `cdsapi` python package
EXAMPLES
python download_era5_agromet.py
NOTES
Reference: data availability, time periods, variables name and dcoumentation are available
from https://cds.climate.copernicus.eu/cdsapp#!/dataset/sis-agrometeorological-indicators?tab=overview
CONTACT
Benny Istanto
Climate Geographer
GOST/DECAT/DECDG, The World Bank
LICENSE
This script is in the public domain, free from copyrights or restrictions.
VERSION
$Id$
TODO
xx
"""
import os
import cdsapi
# Replace UID:ApiKey with your UID and API key
# c = cdsapi.Client(key="UID:ApiKey")
c = cdsapi.Client()
years = list(range(1979, 2023))
months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
for year in years:
for month in months:
c.retrieve(
'sis-agrometeorological-indicators',
{
'variable': [
'2m_relative_humidity',
],
'year': str(year),
'month': month,
'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': [
'06_00', '09_00', '12_00',
'15_00', '18_00',
],
'area': [
11, 90, -13, 145, # Bounding box for Indonesia
],
'format': 'zip',
},
f'idn_cli_era5ag_rh2m_{year}{month}.zip'
)
print(f'idn_cli_era5ag_rh2m_{year}{month}.zip downloaded.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment