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 

3 Comments

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


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

    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

  3. 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: 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: 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