Keeping source time units with "climate.daily_mean"

I'm using the toolbox to calculate daily averages of ERA-5 data before downloading. Seems like the daily_mean functions winds up changing the time units to whatever the beginning of the input time series is. It would be helpful to maintain the source units (seconds since 1970-1-1). Tried the "keep_attrs=True" keyword but that doesn't seem to affect this (not sure what it does affect, docs a bit slim on it).



Dear Alex,

Could you share a workflow so I can check what is happening? I am surprised daily_mean is not preserving the units, it should do with keep_attrs=True.

In any case you can always edit the 'units' attribute with: assuming the output is still in the unit you expect.

data = ct.cdm.update_attributes(data, {'units' : 's'})



Below my workflow. Sorry indentation got clobbered with cut andp paste.  Can't quite understand the update_attributes method above and what it is supposed to do but I just do this after download.


I assume the "daily_means" method isn't smart enough to deal with computing daily averages for "accumulated" values in the analysis to address that they cross day boundaries? In general my problem is to efficiently calculate daily averages for several ERA5 variables including for example total_precipitation.



import cdstoolbox as ct

@ct.application(title='Daily Download')

def application(month,year):

print("Month to retrieve",month)

data = ct.catalogue.retrieve(



'variable': '2m_temperature',

'product_type': 'ensemble_mean',

'year': 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',


'time': [












# fig = ct.cdsplot.figure(subplot_kw={'projection':})

# ct.cdsplot.geomap(

# data, pcolormesh_kwargs={'cmap': 'RdBu_r'}, fig=fig,

# title='Mean {long_name}'

# )


return daily_mean

Hi Axel,

I am not sure the workflow you provided corresponds to the issue you face. The workflow seem to be missing some input arguments for year and month.

I have adapted the workflow you pasted to make it run but still it doesn't take precipitation:

If you provide me with another workflow I can look into it.

In the meanwhile maybe resample is a tool you will be interested in:

It is a more generic tool where you can set the frequency and method of resampling as well as how the time intervals are defined.