def select_point(filepath,year, lon, lat):
# lon = 123.88
# lat = 34.88
# North = 34.88 + 0.1
# South = 34.88 - 0.1
# West = 123.88 - 0.1
# East = 123.88 + 0.1
# #
c = cdsapi.Client()
code = """
import cdstoolbox as ct
@ct.application(title='Extract a time series and plot graph')
@ct.output.download()
def application(var, year, lon , lat ):
data = ct.catalogue.retrieve(
'reanalysis-era5-land',# reanalysis-era5-single-levels # reanalysis-era5-land
{
'variable': var,
'grid': ['0.1', '0.1'],
#'product_type': 'reanalysis',
'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',
# '06:00',
# '12:00',
# '18:00',
# ],
'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',
],
'area':[53.560860,73.557701,13.159306,134.773926]
}
)
tem = ct.geo.extract_point(data[0], lon=lon, lat=lat)
pre = ct.geo.extract_point(data[1], lon=lon, lat=lat)
data_daily_max = ct.climate.daily_max(tem)
data_daily_min = ct.climate.daily_min(tem)
sf = ct.geo.extract_point(data[2], lon=lon, lat=lat)
#ct.units.convert_units(pre, 'mm h-1', source_units='m s-1')
data = ([tem, pre,sf])
return data
"""
kwargs = {
'var': ['2m_temperature','total_precipitation','snowfall'],
'year': year,
'lon': lon,
'lat': lat,
}
df = c.workflow(code, **kwargs)
c.download(df,filepath)