I'm trying to compute number of frost days from era5 daily data. However i'm getting  following error message. Has anyone managed to use compute_extreme_index function, and how it should be used

Traceback (most recent call last):
  File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 55, 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 "/usr/local/lib/python3.6/site-packages/cfgrib/messages.py", line 239, in __iter__
    yield self.message_from_file(file, errors=self.errors)
  File "/usr/local/lib/python3.6/site-packages/cfgrib/messages.py", line 255, in message_from_file
    return self.message_class.from_file(file, offset, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/cfgrib/messages.py", line 102, in from_file
    raise EOFError("End of file: %r" % file)
EOFError: End of file: <_io.BufferedReader name='/cache/tmp/data-76ec3c2d-0841-49e0-9911-703b1a6017cd.nc'>

During handling of the above exception, another exception occurred:

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/cdscdo/cdscdo/cdo.py", line 499, in _compute_extreme_index
    paths = gridded.make_compliant(output_path)
  File "/opt/cdstoolbox/cdscdm/cdscdm/gridded.py", line 881, in make_compliant
    datasets = open_dataset(netcdf, product, strict=strict, **kwargs)
  File "/opt/cdstoolbox/cdscdm/cdscdm/gridded.py", line 732, in open_dataset
    read_attributes=retrieve_kwargs.get('read_attributes', []),
  File "/opt/cdstoolbox/cdscdm/cdscdm/gridded.py", line 91, in update_xarray_backend_kwargs
    time_dims = xarray_backend_time_dims(wpath, product, time_dimensions, default_backend_kwargs.get('time_dims', []))
  File "/opt/cdstoolbox/cdscdm/cdscdm/gridded.py", line 67, in xarray_backend_time_dims
    if check_lagged_starts(path):
  File "/opt/cdstoolbox/cdscdm/cdscdm/gridded.py", line 54, in check_lagged_starts
    msg0 = cfgrib.FileStream(path).first()
  File "/usr/local/lib/python3.6/site-packages/cfgrib/messages.py", line 258, in first
    for message in self:
  File "/usr/local/lib/python3.6/site-packages/cfgrib/messages.py", line 243, in __iter__
    raise EOFError("No valid message found in file: %r" % self.path)
EOFError: No valid message found in file: '/cache/tmp/data-76ec3c2d-0841-49e0-9911-703b1a6017cd.nc'


import cdstoolbox as ct

layout = {
    'output_align': 'bottom'
}


@ct.application(title='Use CDO functions', layout=layout)
@ct.input.dropdown('year', label='Year', values=range(2010, 2020))
@ct.output.figure()
@ct.output.figure()
def csu_app(year):
    """
    Application main steps:

    - retrieve a variable over a defined time range
    - compute the daily mean
    - compute the "Consecutive Summer Days" indexes (the number of consecutive days and the number
      of summer periods of more than 5 days)
    - show the result on a map

    """

    data = ct.catalogue.retrieve(
        'reanalysis-era5-single-levels',
        {
            'variable': '2m_temperature',
            'grid': ['3', '3'],
            'product_type': 'reanalysis',
            'year': str(year),
            'month': [
                '01', '02', '03', '04', '05', '06',
                '07', '08', '09', '10', '11', '12'
            ],
            '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', '06:00', '12:00', '18:00'],
        }
    )

    data_daily = ct.climate.daily_min(data)
    data_daily = ct.cube.select(data_daily, time=year)
    print(data_daily)
    map_data = ct.climate.compute_extreme_index(data_daily, 'eca_fd')
    print(map)
    title = 'test'

    # Plot retrieved data on a map
    fig = ct.map.plot(map_data, title=title)

    return fig
   


1 Comment

  1. Hi Kalle,

    I have the same problem and I wonder if you figure it out?

    Xie