from netCDF4 import Dataset
import xarray as xr
Can someone confirm how to use new API,
import cdsapi
client = cdsapi.Client()
dataset = ‘reanalysis-era5-single-levels’
request = {
‘product_type’: [‘reanalysis’],
‘variable’:[‘2m_temperature’,‘total_precipitation’],
‘year’: [‘2024’],
‘month’: [‘03’],
‘day’: [‘01’],
‘time’: [‘13:00’],
‘pressure_level’: [‘1000’],
‘data_format’: ‘netcdf’,
}
target = ‘download.nc’
file_path = client.retrieve(dataset, request, target)
file_path.download(“./output.nc”)
ds = xr.open_dataset(f.read())
now I am tring to calculate daily total precipitation
daily_precipitation = (ds.tp.resample(time=‘24H’).sum(‘time’) * 1000).to_dataset() # calculate sum with frequency of 24h and multiply by 1000
daily_temperature = (ds.t2m.resample(time=‘24H’).sum(‘time’) / 24).to_dataset()
I am getting this error, KeyError: ‘time’