I'm having trouble understanding the way dimensions are aggregated with toolbox functions. I'm trying to calculate a simple daily max/min temperature from hourly data, then take a 20-year mean for each day of the month (ideally year, but my dataset is too large). The best I can do currently is this:


import cdstoolbox as ct

@ct.application(title='Download data')
@ct.output.download()
@ct.output.download()


def download_application():
tas = ct.catalogue.retrieve(
'reanalysis-era5-single-levels',
{
'product_type': 'reanalysis',
'variable': [
'2m_temperature',
],
'month': [
'01',
],
'year': [
'2000', '2001', '2002',
'2003', '2004', '2005',
'2006', '2007', '2008',
'2009', '2010', '2011',
'2012', '2013', '2014',
'2015', '2016', '2017',
'2018', '2019',

'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', '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': [
30, 68, 11,
80,
],
}
)
tas = ct.cdm.convert_units(tas, 'celsius', source_units='K')

daily_max = ct.cube.resample(tas, freq='D', how='max')
daily_min = ct.cube.resample(tas, freq='D', how='min')

#tas_min = (
#ct.climate.climatology_mean(daily_min),'dayofyear')
#tas_max = (
#ct.climate.climatology_mean(daily_max), 'dayofyear')


return  daily_max, daily_min


However, this returns  an array of size (20 x 365, lat, lon) where there is only data for the first 31 days in each year. That at least is manageable, because I can deal with the results with post-processing in Python.

Also, It seems like if I uncomment the last lines, I should get what I want - an array of size (20 x 31, lat, lon). But the request returns an error.

I have had the same problem using ct.climate.daily_max, which as I understand should be identical to ct.cube.resample(tas, freq='D', how='max')