Yes, sure, this is the traceback:
KeyError Traceback (most recent call last)
File ~/.local/lib/python3.10/site-packages/xarray/backends/file_manager.py:209, in CachingFileManager._acquire_with_cache_info(self, needs_lock)
208 try:
--> 209 file = self._cache[self._key]
210 except KeyError:
File ~/.local/lib/python3.10/site-packages/xarray/backends/lru_cache.py:55, in LRUCache.__getitem__(self, key)
54 with self._lock:
---> 55 value = self._cache[key]
56 self._cache.move_to_end(key)
KeyError: [<function open at 0x7f7889eace50>, ('MYD09A1.A2018361.h20v03.006.2019010171535.hdf',), 'r', (('engine', 'rasterio'), ('sharing', False)), '7f094700-6d53-41a7-9cb8-0e7015ae5031']
During handling of the above exception, another exception occurred:
CPLE_OpenFailedError Traceback (most recent call last)
File rasterio/_base.pyx:307, in rasterio._base.DatasetBase.__init__()
File rasterio/_base.pyx:218, in rasterio._base.open_dataset()
File rasterio/_err.pyx:221, in rasterio._err.exc_wrap_pointer()
CPLE_OpenFailedError: 'MYD09A1.A2018361.h20v03.006.2019010171535.hdf' not recognized as a supported file format.
During handling of the above exception, another exception occurred:
RasterioIOError Traceback (most recent call last)
Input In [138], in <cell line: 1>()
----> 1 data = rioxarray.open_rasterio('MYD09A1.A2018361.h20v03.006.2019010171535.hdf', engine = 'rasterio', masked=True)
File ~/.local/lib/python3.10/site-packages/rioxarray/_io.py:1087, in open_rasterio(filename, parse_coordinates, chunks, cache, lock, masked, mask_and_scale, variable, group, default_name, decode_times, decode_timedelta, band_as_variable, **open_kwargs)
1085 else:
1086 manager = URIManager(file_opener, filename, mode="r", kwargs=open_kwargs)
-> 1087 riods = manager.acquire()
1088 captured_warnings = rio_warnings.copy()
1090 if band_as_variable:
File ~/.local/lib/python3.10/site-packages/xarray/backends/file_manager.py:191, in CachingFileManager.acquire(self, needs_lock)
176 def acquire(self, needs_lock=True):
177 """Acquire a file object from the manager.
178
179 A new file is only opened if it has expired from the
(...)
189 An open file object, as returned by ``opener(*args, **kwargs)``.
190 """
--> 191 file, _ = self._acquire_with_cache_info(needs_lock)
192 return file
File ~/.local/lib/python3.10/site-packages/xarray/backends/file_manager.py:215, in CachingFileManager._acquire_with_cache_info(self, needs_lock)
213 kwargs = kwargs.copy()
214 kwargs["mode"] = self._mode
--> 215 file = self._opener(*self._args, **kwargs)
216 if self._mode == "w":
217 # ensure file doesn't get overridden when opened again
218 self._mode = "a"
File ~/.local/lib/python3.10/site-packages/rasterio/env.py:444, in ensure_env_with_credentials.<locals>.wrapper(*args, **kwds)
441 session = DummySession()
443 with env_ctor(session=session):
--> 444 return f(*args, **kwds)
File ~/.local/lib/python3.10/site-packages/rasterio/__init__.py:304, in open(fp, mode, driver, width, height, count, crs, transform, dtype, nodata, sharing, **kwargs)
301 path = _parse_path(raw_dataset_path)
303 if mode == "r":
--> 304 dataset = DatasetReader(path, driver=driver, sharing=sharing, **kwargs)
305 elif mode == "r+":
306 dataset = get_writer_for_path(path, driver=driver)(
307 path, mode, driver=driver, sharing=sharing, **kwargs
308 )
File rasterio/_base.pyx:309, in rasterio._base.DatasetBase.__init__()
RasterioIOError: 'MYD09A1.A2018361.h20v03.006.2019010171535.hdf' not recognized as a supported file format.
I’m accessing the data using modis_tools library:
from modis_tools.auth import ModisSession
from modis_tools.resources import CollectionApi, GranuleApi
from modis_tools.granule_handler import GranuleHandler
username = ""
password = ""
session = ModisSession(username=username, password=password)
collection_client = CollectionApi(username=username, password=password)
collections = collection_client.query(short_name="MYD09A1")
granule_client = GranuleApi.from_collection(collections[0], session=session)
coordinates = [57.024, 57.043, 59.529, 59.578]
granules = granule_client.query(start_date="2018-12-30", end_date="2018-12-31", bounding_box = coordinates)
GranuleHandler.download_from_granules(granules, session)
Hmmm, it seems the problem is due to the way I get the file, because your script works for me fine, it’s strange…