-
Notifications
You must be signed in to change notification settings - Fork 85
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
Segfault when using MemoryFile objects #550
Comments
I suspect this is due to gdal's memory file object being disposed off before dask can make use of it... |
Just for clarification and some context: The opening of the file and reading to put the data in the MemoryFile is of course contrived, and just comes from the fact that I need to be able to pass open files to rioxarray. In my case, I want to use fsspec in the background (https://filesystem-spec.readthedocs.io/en/latest/) so as to be able to read remote files on the fly. |
See: rasterio/rasterio#2517 (comment) for an example of using MemoryFile using @mraspaud, with this addition to rasterio 1.3 (recently released), I believe you should be able to use fsspec files directly (related #246): def read_file(filename):
with open(filename, "rb") as src:
proj = rioxarray.open_rasterio(src, chunks=2048)
return proj.squeeze("band") |
I tried using the context, but that resulted in an empty data array being returned (which I think is quite logical this the context will be closed at the time of plotting). The example you provide does not seem to work (so passing a regular open file to
Also rasterio seems to be having problems with opened jp2 files (tif works fine), so I'll be reporting an issue for that on rasterio when I get a minimal case. |
But thanks a lot for the heads up on @djhoese 's amazing contribution :) |
Haven't tested that feature with dask ... looks like we need a patch to handle that. |
Sounds like you may need to add a .load() call after |
I think using |
Yes exactly. |
Edited for brevity, "reproducible" code, and a possible solution: Regarding @snowman2's suggestion to use Using
Note the file successfully opens but when I try to do
As a work around to this I've found the following pattern does what I want:
Note that this solution fails when trying to pass any size for I can understand how the use of Is this just something rioxarray currently does not support? |
#558 should address this: #550 (comment) |
From what I can tell, calling with open(filename, "rb") as of:
data = of.read() Since the data is lazily loaded by Ideas to improve this behavior are definitely welcome. It may be worth looking into how xarray handles this scenario as they may have found a solution for this. |
Yes, it is, however, the In the real case, we want to keep things lazy as much as possible. I believe with your example here: #550 (comment) and the fix in #550 I'm good.
Yes, I think they do, but I don't remember how. |
I think this is resolved. If something is missing still, please comment. |
Opening the GeoTIFF in a with statement, and loading the RGB image data fully into memory using `image.load()` as suggested in corteva/rioxarray#550 (comment), which should fix the segfault hopefully.
Code Sample, a copy-pastable example if possible
Problem description
The above results in a segmentation fault every time (at least on my laptop)
Expected Output
I expect the display of my data.
Environment Information
rioxarray (0.11.2.dev0) deps:
rasterio: 1.2.10
xarray: 2022.3.0
GDAL: 3.4.2
GEOS: None
PROJ: None
PROJ DATA: None
GDAL DATA: None
Other python deps:
scipy: 1.8.0
pyproj: 3.3.1
System:
python: 3.10.2 | packaged by conda-forge | (main, Feb 1 2022, 19:28:35) [GCC 9.4.0]
executable: /home/a001673/mambaforge/envs/satpy/bin/python
machine: Linux-4.18.0-372.16.1.el8_6.x86_64-x86_64-with-glibc2.28
Installation method
pip install -e .
The text was updated successfully, but these errors were encountered: