# Keeping source time units with "climate.daily\_mean"

**URL:** <https://forum.ecmwf.int/t/keeping-source-time-units-with-climate-daily-mean/1760>\
**Category:** Other - Software and tools\
**Tags:** c3s, toolbox\
**Created:** [18 April 2020 18:23 UTC](https://forum.ecmwf.int/t/keeping-source-time-units-with-climate-daily-mean/1760 "2020-04-18T18:23:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axel\_Schweiger](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@Axel\_Schweiger](https://forum.ecmwf.int/u/Axel_Schweiger)\
**Post date:** [18 April 2020 18:23 UTC](https://forum.ecmwf.int/t/keeping-source-time-units-with-climate-daily-mean/1760/1 "2020-04-18T18:23:52Z")

</div>

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).

Thanks

Axel&nbsp;

---

<div class="post-metadata">

**Author:** ![Vivien\_MAVEL](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/v/ecccb3/32.png) [@Vivien\_MAVEL](https://forum.ecmwf.int/u/Vivien_MAVEL)\
**Post date:** [20 April 2020 06:42 UTC](https://forum.ecmwf.int/t/keeping-source-time-units-with-climate-daily-mean/1760/2 "2020-04-20T06:42:39Z")

</div>

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'})`

Regards.

Vivien

---

<div class="post-metadata">

**Author:** ![Axel\_Schweiger](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@Axel\_Schweiger](https://forum.ecmwf.int/u/Axel_Schweiger)\
**Post date:** [20 April 2020 16:20 UTC](https://forum.ecmwf.int/t/keeping-source-time-units-with-climate-daily-mean/1760/3 "2020-04-20T16:20:17Z")

</div>

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

cdo.setreftime('1900-01-01,00:00:00,1day',input=outname[0],output=temp)

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.

daily\_mean=ct.climate.daily\_mean(data,keep\_attrs=True)

Axel

import cdstoolbox as ct

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

@ct.output.download()

def application(month,year):

print("Month to retrieve",month)

data = ct.catalogue.retrieve(

'reanalysis-era5-single-levels',

{

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

'31'],

'time': [

'00:00',

'03:00',

'06:00',

'09:00',

'12:00',

'15:00',

'18:00',

'21:00',

],

}

)

# fig = ct.cdsplot.figure(subplot\_kw={'projection': ct.cdsplot.crs.Robinson()})

# ct.cdsplot.geomap(

# data, pcolormesh\_kwargs={'cmap': 'RdBu\_r'}, fig=fig,

# title='Mean {long\_name}'

# )

daily\_mean=ct.climate.daily\_mean(data,keep\_attrs=True)

return daily\_mean

---

<div class="post-metadata">

**Author:** ![Vivien\_MAVEL](https://forum.ecmwf.int/letter_avatar_proxy/v4/letter/v/ecccb3/32.png) [@Vivien\_MAVEL](https://forum.ecmwf.int/u/Vivien_MAVEL)\
**Post date:** [29 April 2020 06:38 UTC](https://forum.ecmwf.int/t/keeping-source-time-units-with-climate-daily-mean/1760/4 "2020-04-29T06:38:34Z")

</div>

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:&nbsp;[https://cds.climate.copernicus.eu/toolbox-editor/168/forum\_daily\_mean](https://cds.climate.copernicus.eu/toolbox-editor/168/forum_daily_mean)  
  
 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:&nbsp;[https://cds.climate.copernicus.eu/toolbox/doc/tools/cdstoolbox.cube.resample.html](https://cds.climate.copernicus.eu/toolbox/doc/tools/cdstoolbox.cube.resample.html)

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.

Regards.

Vivien
