Hi,


Since ERA-5 does not provide daily mean data (at least I couldn't find it), I am trying to use the toolbox to calculate and download the data that I need. 

Below is the code I wrote (based on the examples). I have met some issues, which seem related to the function ct.climate.daily_mean().

I use Matlab, and am very new to Python. If any one could kindly give me some suggestions, I would greatly appreciate it.


The code:

import cdstoolbox as ct

@ct.application(title='Download data')
@ct.output.download()
def download_application():
data = ct.catalogue.retrieve(
'reanalysis-era5-single-levels',
{
'product_type': 'reanalysis',
'variable': [
'10m_u_component_of_wind', '10m_v_component_of_wind',
],
'year': ['1979','1980'],
'month': ['01'],
'day': ['01','02'],
'time': ['00:00', '06:00', '12:00','18:00'],
}
)

# daily_mean = ct.climate.climatology_mean(data, frequency='dayofyear')
data_daily = ct.climate.daily_mean(data)

return data_daily


The error message:

Traceback (most recent call last):
  File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 49, in handle_request
    result = cached(context.method, proc, context, context.args, context.kwargs)
  File "/opt/cdstoolbox/cdscompute/cdscompute/caching.py", line 108, in cached
    result = proc(context, *context.args, **context.kwargs)
  File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 118, in __call__
    return p(*args, **kwargs)
  File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 59, in __call__
    return self.proc(context, *args, **kwargs)
  File "/home/cds/cdsservices/services/python_service.py", line 38, in execute
    raise exceptions.InternalError(logging + traceback, '')
cdsclient.exceptions.InternalError: Traceback (most recent call last):
  File "/opt/cdstoolbox/jsonrequest/jsonrequest/requests.py", line 71, in jsonrequestcall
    resp = coding.encode(req.callable(*req.args, **req.kwargs), register=encoders, **context)
  File "/opt/cdstoolbox/cdstools/cdstools/season.py", line 188, in daily_mean
    mean = util.resample(data, freq='D', **kwargs)
  File "/opt/cdstoolbox/cdstools/cdstools/util.py", line 350, in resample
    resample = data.resample(label=label, closed=closed, keep_attrs=keep_attrs,
AttributeError: 'list' object has no attribute 'resample'


Thank you!

Lei

3 Comments

  1. Dear Lei,

    When you retrieve multiple data the retrieve function return a list of data objects so 'data' in your code is a list. 

    I suggest you to retrieve the data as follows

    u, v = ct.catalogue.retrieve(
    	'reanalysis-era5-single-levels',
    	{
    		'product_type': 'reanalysis',
    		'variable': [
    		'10m_u_component_of_wind', '10m_v_component_of_wind',
    		],
    		'year': ['1979','1980'],
    		'month': ['01'],
    		'day': ['01','02'],
    		'time': ['00:00', '06:00', '12:00','18:00'],
    	}
    )

    u and v are then data objects as they are meant to be to be manipulated with the CDS Toolbox.

    I hope this helps. Let me know if you have any further question.

    Regards.

    Vivien 

  2. Dear Vivien,


    Thank you very much for your kind help. I really appreciate it.

    It works perfect now!


    Best regards,

    Lei

  3. import cdstoolbox as ct

    @ct.application(title='Download data')
    @ct.output.download()
    def download_application():
        count=1
        for yr in ['2019']:
            for mn in [ '01', '02', '03',
                    '04', '05', '06',
                    '07', '08', '09',
                    '10', '11', '12'
                      ]:
                 t, u, v = ct.catalogue.retrieve(
                 'reanalysis-era5-pressure-levels',
                 {
                 'product_type': 'reanalysis',
                 'variable': [

                 'temperature',  'u_component_of_wind',  'v_component_of_wind'
                ],
                'pressure_level': [
                '1', '2', '3',
                '5', '7', '10',
                '20', '30', '50',
                '70', '100', '125',
                '150', '175', '200',
                '225', '250', '300',
                '350', '400', '450',
                '500', '550', '600',
                '650', '700', '750',
                '775', '800', '825',
                '850', '875', '900',
                '925', '950', '975',
                '1000',
                ],
                 'year': yr,
                 'month': mn,
                 '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',
                         ],
                 }
                 )
                 day_mean=ct.climate.daily_mean(????,keep_attrs=True)
                 if count == 1:
                     day_mean_all=day_mean
                 else:       
                     day_mean_all=ct.cube.concat([day_mean_all, day_mean], dim='time')
                 count = count + 1
        return day_mean_all

    Sir, i m unable to download data by using above code.  here i m not able to get how can i get multiple variables in one file

    how can i use data object in line of  day_mean=ct.climate.daily_mean(????,keep_attrs=True) when it is for multiple variable download (like t,u,v)