ecmwf / earthkit

Python tools to work with weather and climate data
https://earthkit.readthedocs.io/
Apache License 2.0
55 stars 3 forks source link

AttributeError: 'Results' object has no attribute 'location' #57

Open ClaudioValletta92 opened 4 months ago

ClaudioValletta92 commented 4 months ago

What happened?

Hello, I am simply running the first example on the website:

`import earthkit as ek

data = ek.data.from_source( 'cds', 'reanalysis-era5-single-levels', { 'product_type': 'reanalysis', 'variable': '2m_temperature', 'year': '2023', 'month': '07', 'day': '3', 'time': '12:00', }, )

ek.plots.globe(data)`

but it does not work, on my jupyter and on google collab as well

What are the steps to reproduce the bug?

Can you simply try:

`import earthkit as ek

data = ek.data.from_source( 'cds', 'reanalysis-era5-single-levels', { 'product_type': 'reanalysis', 'variable': '2m_temperature', 'year': '2023', 'month': '07', 'day': '3', 'time': '12:00', }, )

ek.plots.globe(data)`

And see if you can reproduce it?

Version

Latest

Platform (OS and architecture)

M1

Relevant log output

2024-08-01 01:11:37,429 INFO Request ID is 6ee28b96-6aef-458c-a44e-711f0fd777fa
2024-08-01 01:11:37,459 INFO status has been updated to accepted
2024-08-01 01:11:38,998 INFO status has been updated to running
2024-08-01 01:11:41,285 INFO Creating download object as as_source with files:
['data.grib']
2024-08-01 01:11:44,721 INFO status has been updated to successful
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[11], line 3
      1 import earthkit as ek
----> 3 data = ek.data.from_source(
      4     'cds',
      5     'reanalysis-era5-single-levels',
      6     {
      7         'product_type': 'reanalysis',
      8         'variable': '2m_temperature',
      9         'year': '2024',
     10         'month': '07',
     11         'day': '3',
     12         'time': '12:00',
     13     },
     14 )
     16 ek.plots.globe(data)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/earthkit/data/sources/__init__.py:150, in from_source(name, lazily, *args, **kwargs)
    147     return from_source_lazily(name, *args, **kwargs)
    149 prev = None
--> 150 src = get_source(name, *args, **kwargs)
    151 while src is not prev:
    152     prev = src

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/earthkit/data/sources/__init__.py:131, in SourceMaker.__call__(self, name, *args, **kwargs)
    128     klass = find_plugin(os.path.dirname(__file__), name, loader)
    129     self.SOURCES[name] = klass
--> 131 source = klass(*args, **kwargs)
    133 if getattr(source, "name", None) is None:
    134     source.name = name

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/earthkit/data/core/__init__.py:22, in MetaBase.__call__(cls, *args, **kwargs)
     20 obj = cls.__new__(cls, *args, **kwargs)
     21 args, kwargs = cls.patch(obj, *args, **kwargs)
---> 22 obj.__init__(*args, **kwargs)
     23 return obj

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/earthkit/data/sources/cds.py:126, in CdsRetriever.__init__(self, dataset, prompt, *args, **kwargs)
    123 nthreads = min(self.settings("number-of-download-threads"), len(self.requests))
    125 if nthreads < 2:
--> 126     self.path = [self._retrieve(dataset, r) for r in self.requests]
    127 else:
    128     with SoftThreadPool(nthreads=nthreads) as pool:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/earthkit/data/sources/cds.py:126, in <listcomp>(.0)
    123 nthreads = min(self.settings("number-of-download-threads"), len(self.requests))
    125 if nthreads < 2:
--> 126     self.path = [self._retrieve(dataset, r) for r in self.requests]
    127 else:
    128     with SoftThreadPool(nthreads=nthreads) as pool:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/earthkit/data/sources/cds.py:140, in CdsRetriever._retrieve(self, dataset, request)
    137     self.source_filename = cds_result.location.split("/")[-1]
    138     cds_result.download(target=target)
--> 140 return_object = self.cache_file(
    141     retrieve,
    142     (dataset, request),
    143     extension=EXTENSIONS.get(request.get("format"), ".cache"),
    144 )
    145 return return_object

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/earthkit/data/sources/__init__.py:68, in Source.cache_file(self, create, args, **kwargs)
     65 if owner is None:
     66     owner = re.sub(r"(?!^)([A-Z]+)", r"-\1", self.__class__.__name__).lower()
---> 68 return cache_file(owner, create, args, **kwargs)

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/earthkit/data/core/caching.py:1053, in cache_file(owner, create, args, hash_extra, extension, force, replace)
   1051 with FileLock(lock):
   1052     if not os.path.exists(path):  # Check again, another thread/process may have created the file
-> 1053         owner_data = create(path + ".tmp", args)
   1054         os.rename(path + ".tmp", path)
   1055 try:

File /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/earthkit/data/sources/cds.py:137, in CdsRetriever._retrieve.<locals>.retrieve(target, args)
    135 def retrieve(target, args):
    136     cds_result = self.client().retrieve(args[0], args[1])
--> 137     self.source_filename = cds_result.location.split("/")[-1]
    138     cds_result.download(target=target)

AttributeError: 'Results' object has no attribute 'location'

Accompanying data

I am using the new copernicu beta api

Organisation

No response

sandorkertesz commented 3 months ago

@ClaudioValletta92, thank you for reporting this issue. You seem to be using CDS beta. I suggest you update your environment to use this package versions:

I hope it will sort out your problem. earthkit/earthkit-data will be updated to use these minimum versions.