Hi


I have tried several methods to extract climate data for a given coordinate, but I only seem to get run time errors. My code is working fine without me trying to specify coordinates.

I have tried also putting the  ct.geo.extract_point(data, lat, lon) at the end without any luck.

Anyone have any idea on how I can modify my code to get data only for my desired location?

Would really appreciate any tips!












import cdstoolbox as ct


variables = {
'Near-Surface Air Temperature': '2m_temperature',
'Eastward Near-Surface Wind 10': '10m_u_component_of_wind',
'Northward Near-Surface Wind': '10m_v_component_of_wind',
'Sea Level Pressure': 'mean_sea_level_pressure',
'Sea Surface Temperature': 'sea_surface_temperature',
'Sea Surface Temperature': 'sea_surface_temperature',
'Eastward Near-Surface Wind 100': '100m_u_component_of_wind',
'Northward Near-Surface Wind 100': '100m_v_component_of_wind',
'Mean wave direction': 'mean_wave_direction',
'Mean wave period': 'mean_wave_period',
'Sea surface temperature': 'sea_surface_temperature',
'Significant height of combined wind waves and swell': 'significant_height_of_combined_wind_waves_and_swell'



}

@ct.input.dropdown('variable', label='Variable', values=variables.keys())
@ct.application(title='ERA5 dataset')
@ct.output.download()
def application(variable):

data = ct.catalogue.retrieve(
'reanalysis-era5-single-levels',
{
'product_type':'reanalysis',
'variable': variables[variable],
'lon': ['55'],
'lat': ['7'],
'year':['2009', '2010', '2011'],
'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', '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' ]

} )

return data






6 Comments

  1. Dear Olav,

    Here is you modified workflow with a functioning point extraction and plot of the extracted time series.

    https://cds.climate.copernicus.eu/toolbox-editor/168/forum_extract_point

    Note that I added 'grid': [3, 3] in the retrieve function to reduce the resolution and have a quicker retrieve. You can change this if you need a higher resolution.

    You don't need to specify 'lat' and 'lon' in the retrieve function. These inputs are ignored and have no effect on the retrieve.

    I hope this helps and do not hesitate to ask further question on this forum.

    Vivien

  2. Thank you so much! My goal is to download the file and get a string of data, so I tried implementing the download function. I am getting the error when trying to run it..


    import cdstoolbox as ct


    variables = {
    'Near-Surface Air Temperature': '2m_temperature',
    'Eastward Near-Surface Wind 10': '10m_u_component_of_wind',
    'Northward Near-Surface Wind': '10m_v_component_of_wind',
    'Sea Level Pressure': 'mean_sea_level_pressure',
    'Sea Surface Temperature': 'sea_surface_temperature',
    'Sea Surface Temperature': 'sea_surface_temperature',
    'Eastward Near-Surface Wind 100': '100m_u_component_of_wind',
    'Northward Near-Surface Wind 100': '100m_v_component_of_wind',
    'Mean wave direction': 'mean_wave_direction',
    'Mean wave period': 'mean_wave_period',
    'Sea surface temperature': 'sea_surface_temperature',
    'Significant height of combined wind waves and swell': 'significant_height_of_combined_wind_waves_and_swell'
    }

    @ct.input.dropdown('variable', label='Variable', values=variables.keys())
    @ct.application(title='ERA5 dataset')
    @ct.output.download()
    def application(variable):

    data = ct.catalogue.retrieve(
    'reanalysis-era5-single-levels',
    {
    'product_type':'reanalysis',
    'variable': variables[variable],
    'year':['2009', '2010', '2011'],
    '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', '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'
    ],
    }
    )

    data_loc = ct.geo.extract_point(data, lon=7.16, lat=55.18)


    return data_loc

  3. Could you possibly share the error message you get?

    A general comment I would make is to try and reduce the data retrieval to the resolution and the area you are interested in.

    I showed you how to reduce the resolution with 'grid': [3, 3] .

    You can also define the area to retrieve by using : 'area': [75-153042.5], # [North, West, South, East]

    This will accelerate the whole process.

    Regards.

    Vivien

  4. This is 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/retrieve.py", line 145, in execute data = context.call("cds.services.cdm_translate", remote, product, obs) File "/opt/cdstoolbox/cdscompute/cdscompute/context.py", line 245, in call return c.call(service, *args, **kwargs).value File "/opt/cdstoolbox/cdsworkflows/cdsworkflows/future.py", line 76, in value raise self._result cdsworkflows.error.ClientError: {'traceback': 'Traceback (most recent call last):\n File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 49, in handle_request\n result = cached(context.method, proc, context, *context.args, **context.kwargs)\n File "/opt/cdstoolbox/cdscompute/cdscompute/caching.py", line 108, in cached\n result = proc(context, *context.args, **context.kwargs)\n File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 118, in __call__\n return p(*args, **kwargs)\n File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 59, in __call__\n return self.proc(context, *args, **kwargs)\n File "/home/cds/cdsservices/services/cdm_translate.py", line 33, in execute\n dataset.to_netcdf(out.path)\n File "/usr/local/lib/python3.6/site-packages/xarray/core/dataset.py", line 1547, in to_netcdf\n invalid_netcdf=invalid_netcdf,\n File "/usr/local/lib/python3.6/site-packages/xarray/backends/api.py", line 1081, in to_netcdf\n writes = writer.sync(compute=compute)\n File "/usr/local/lib/python3.6/site-packages/xarray/backends/common.py", line 204, in sync\n regions=self.regions,\n File "/usr/local/lib/python3.6/site-packages/dask/array/core.py", line 923, in store\n result.compute(**kwargs)\n File "/usr/local/lib/python3.6/site-packages/dask/base.py", line 165, in compute\n (result,) = compute(self, traverse=False, **kwargs)\n File "/usr/local/lib/python3.6/site-packages/dask/base.py", line 436, in compute\n results = schedule(dsk, keys, **kwargs)\n File "/usr/local/lib/python3.6/site-packages/dask/threaded.py", line 81, in get\n **kwargs\n File "/usr/local/lib/python3.6/site-packages/dask/local.py", line 486, in get_async\n raise_exception(exc, tb)\n File "/usr/local/lib/python3.6/site-packages/dask/local.py", line 316, in reraise\n raise exc\n File "/usr/local/lib/python3.6/site-packages/dask/local.py", line 222, in execute_task\n result = _execute_task(task, data)\n File "/usr/local/lib/python3.6/site-packages/dask/core.py", line 118, in _execute_task\n args2 = [_execute_task(a, cache) for a in args]\n File "/usr/local/lib/python3.6/site-packages/dask/core.py", line 118, in <listcomp>\n args2 = [_execute_task(a, cache) for a in args]\n File "/usr/local/lib/python3.6/site-packages/dask/core.py", line 119, in _execute_task\n return func(*args2)\n File "/usr/local/lib/python3.6/site-packages/dask/array/core.py", line 106, in getter\n c = np.asarray(c)\n File "/usr/local/lib64/python3.6/site-packages/numpy/core/_asarray.py", line 85, in asarray\n return array(a, dtype, copy=False, order=order)\n File "/usr/local/lib/python3.6/site-packages/xarray/core/indexing.py", line 481, in __array__\n return np.asarray(self.array, dtype=dtype)\n File "/usr/local/lib64/python3.6/site-packages/numpy/core/_asarray.py", line 85, in asarray\n return array(a, dtype, copy=False, order=order)\n File "/usr/local/lib/python3.6/site-packages/xarray/core/indexing.py", line 643, in __array__\n return np.asarray(self.array, dtype=dtype)\n File "/usr/local/lib64/python3.6/site-packages/numpy/core/_asarray.py", line 85, in asarray\n return array(a, dtype, copy=False, order=order)\n File "/usr/local/lib/python3.6/site-packages/xarray/core/indexing.py", line 547, in __array__\n return np.asarray(array[self.key], dtype=None)\n File "/usr/local/lib/python3.6/site-packages/xarray/backends/cfgrib_.py", line 24, in __getitem__\n key, self.shape, indexing.IndexingSupport.OUTER, self._getitem\n File "/usr/local/lib/python3.6/site-packages/xarray/core/indexing.py", line 827, in explicit_indexing_adapter\n result = raw_indexing_method(raw_key.tuple)\n File "/usr/local/lib/python3.6/site-packages/xarray/backends/cfgrib_.py", line 29, in _getitem\n return self.array[key]\n File "/usr/local/lib/python3.6/site-packages/cfgrib/dataset.py", line 319, in __getitem__\n array_field = np.full(array_field_shape, fill_value=np.nan, dtype=\'float32\')\n File "/usr/local/lib64/python3.6/site-packages/numpy/core/numeric.py", line 332, in full\n a = empty(shape, dtype, order)\nMemoryError: Unable to allocate array with shape (26280, 721, 1440) and data type float32\n'}



    I understand that by removing the grid command, default 0,25x0,25 is chosen? My goal is to get data as close as possible to my given coordinate, and just for that one point.


  5. Actually it seems like its now working with the download.

    I kept the "area to retrieve" function, 'area': [75-153042.5], # [North, West, South, East].

    But I don't understand exactly what this command does? 

  6. Hi Olav, glad to hear it works with "area".

    What it does is that instead of retrieving data for the whole world it retrieves data only between latitude 30 and 75 and longitude -15 and 42.5. Reducing the retrieved data avoids the memory error.

    Since you are interested in a single point only you could reduce this area even further. for example:

    'area': [50, 06010]