#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Tue Apr 30 16:39:22 EDT 2019 import os, os.path, sys import cdsapi c = cdsapi.Client() # params data_name = 'vorticity' plev = '850' years = range(1979,2019) # function def download(data_name, year): '''download data from ERA5 in the specified year''' ofile = f'era5.{data_name}.{plev}.{year}.nc' if os.path.exists(ofile): print('[exists]:', ofile) return c.retrieve( 'reanalysis-era5-pressure-levels', { 'product_type':'reanalysis', 'format':'netcdf', 'pressure_level':plev, 'variable':data_name, 'year':f'{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', '06:00', '12:00', '18:00', ] }, ofile) # run the script if __name__ == '__main__': for year in years: download(data_name, year)