Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bm_raster #105

Open
emilytheok opened this issue Dec 2, 2024 · 3 comments
Open

bm_raster #105

emilytheok opened this issue Dec 2, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@emilytheok
Copy link

I am trying to run the guided exploration of the BlackMarblePy package but I get an error during COLLATING RESULTS which I have not been able to solve. See the error message below and the screenshot of the code I am trying to run - many thanks for your support!

KeyError Traceback (most recent call last)
File ~/BlackmarbleDev/venv_blackmarble/lib/python3.13/site-packages/xarray/backends/file_manager.py:211, in CachingFileManager._acquire_with_cache_info(self, needs_lock)
210 try:
--> 211 file = self._cache[self._key]
212 except KeyError:

File ~/BlackmarbleDev/venv_blackmarble/lib/python3.13/site-packages/xarray/backends/lru_cache.py:56, in LRUCache.getitem(self, key)
55 with self._lock:
---> 56 value = self._cache[key]
57 self._cache.move_to_end(key)

KeyError: [<function open at 0x11e6e1c60>, ('/vsimem/23d9c2da-ba8c-4ffe-8dd4-166e82686b8b/23d9c2da-ba8c-4ffe-8dd4-166e82686b8b.tif',), 'r', (('sharing', False),), '52a1c5b2-f217-4dcf-8aeb-db7e9d848406']

During handling of the above exception, another exception occurred:

CPLE_OpenFailedError Traceback (most recent call last)
File rasterio/_base.pyx:310, in rasterio._base.DatasetBase.init()

File rasterio/_base.pyx:221, in rasterio._base.open_dataset()

File rasterio/_err.pyx:359, in rasterio._err.exc_wrap_pointer()

CPLE_OpenFailedError: No such file or directory
...
359 )

File rasterio/_base.pyx:312, in rasterio._base.DatasetBase.init()

RasterioIOError: No such file or directory

Screenshot 2024-12-02 at 10 45 34
@emilytheok emilytheok added the bug Something isn't working label Dec 2, 2024
@russss
Copy link

russss commented Jan 9, 2025

I'm also seeing this issue - presumably this is the result of some dependency being updated, but it's tricky to work out what's at fault.

The issue is happening here:

ds = merge_arrays(da)
clipped_dataset = ds.rio.clip(
gdf.geometry.apply(mapping), gdf.crs, drop=True
)

Rasterio is trying to open the in-memory result of merge_arrays as if it's a file on disk. The value of path is actually _UnparsedPath(path='/vsimem/8ca17fb7-3a3e-4946-90ed-78b8b1c798a8/8ca17fb7-3a3e-4946-90ed-78b8b1c798a8.tif').

@russss
Copy link

russss commented Jan 9, 2025

I managed to make it work by changing the code to clip before merging. Still no idea what went wrong.

--- a/src/blackmarble/raster.py
+++ b/src/blackmarble/raster.py
@@ -360,16 +360,12 @@ def bm_raster(
                             drop_values_by_quality_flag=drop_values_by_quality_flag,
                             output_directory=d,
                         ),
-                    )
+                    ).rio.clip(gdf.geometry.apply(mapping), gdf.crs, drop=True)
                     for f in filenames
                 ]
                 ds = merge_arrays(da)
-                clipped_dataset = ds.rio.clip(
-                    gdf.geometry.apply(mapping), gdf.crs, drop=True
-                )
-                clipped_dataset["time"] = pd.to_datetime(date)
-
-                datasets.append(clipped_dataset.squeeze())
+                ds["time"] = pd.to_datetime(date)
+                datasets.append(ds.squeeze())
             except TypeError:
                 continue

@iled
Copy link

iled commented Jan 15, 2025

I am also having this issue. There are a few open issues, here in github, where users show some variation of error being thrown during the "collating results" step.

I have also tried @russss workaround to clip before merging and still got an error in the "collating" step.

This is even reproducible in the example notebook:

# Daily data: raster for February 5, 2021
VNP46A2_20210205 = bm_raster(
    gdf, product_id="VNP46A2", date_range="2021-02-05", bearer=bearer
)
VNP46A2_20210205
Captura de Tela 2025-01-15 às 1 59 20 AM

Note that data files are downloaded, but then it fails in the collating step, which, I think, suggests there is no issue with the authentication/token.

@russss are you able to run the example above in the notebook with your suggested modification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants