From a337071b05f6280483348b53c90683046e6f3ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= <49512274+ludwigVonKoopa@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:49:09 +0000 Subject: [PATCH 1/3] add import rioxarray where readers actually need them some readers use rasterio engine from xarray, but it actually use rioxarray in the backend, without stating it in the dependencies --- satpy/readers/generic_image.py | 4 ++++ satpy/readers/sar_c_safe.py | 1 + 2 files changed, 5 insertions(+) diff --git a/satpy/readers/generic_image.py b/satpy/readers/generic_image.py index f6c983e8d5..32102cf7c9 100644 --- a/satpy/readers/generic_image.py +++ b/satpy/readers/generic_image.py @@ -31,6 +31,7 @@ import dask.array as da import numpy as np import rasterio +import rioxarray # noqa: F401, need by xarray with the engine rasterio import xarray as xr from pyresample import utils @@ -76,6 +77,9 @@ def read(self): if hasattr(dataset, "crs") and dataset.crs is not None: self.area = utils.get_area_def_from_raster(dataset) + # xarray use the engine 'rasterio' to open the file, but + # its actually rioxarray used in the backend. + # however, error is not explicit enough (see https://github.com/pydata/xarray/issues/7831) data = xr.open_dataset(self.finfo["filename"], engine="rasterio", chunks={"band": 1, "y": CHUNK_SIZE, "x": CHUNK_SIZE}, mask_and_scale=False)["band_data"] if hasattr(dataset, "nodatavals"): diff --git a/satpy/readers/sar_c_safe.py b/satpy/readers/sar_c_safe.py index a5ec535462..b121399920 100644 --- a/satpy/readers/sar_c_safe.py +++ b/satpy/readers/sar_c_safe.py @@ -46,6 +46,7 @@ import defusedxml.ElementTree as ET import numpy as np import rasterio +import rioxarray # noqa F401 : xarray open_dataset use engine rasterio, which use rioxarray import xarray as xr from dask import array as da from geotiepoints.geointerpolator import lonlat2xyz, xyz2lonlat From 580b74152a32f3d421e3c8c794e69d631e726287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= <49512274+ludwigVonKoopa@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:25:53 +0000 Subject: [PATCH 2/3] adding dependencies in pyproject.toml --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c2ae1a890d..d988737746 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,7 @@ avhrr_l1b_gaclac = ["pygac >= 1.3.0"] modis_l1b = ["pyhdf", "python-geotiepoints >= 1.1.7"] geocat = ["pyhdf"] goci2 = ["netCDF4 >= 1.1.8"] +generic_image = ["rasterio", "rioxarray"] acspo = ["netCDF4 >= 1.1.8"] clavrx = ["netCDF4 >= 1.1.8"] viirs_l1b = ["netCDF4 >= 1.1.8"] @@ -66,7 +67,7 @@ gms5-vissr_l1b = ["numba"] # Writers: cf = ["h5netcdf >= 0.7.3"] awips_tiled = ["netCDF4 >= 1.1.8"] -geotiff = ["rasterio", "trollimage[geotiff]"] +geotiff = ["rasterio", "rioxarray", "trollimage[geotiff]"] ninjo = ["pyninjotiff", "pint"] units = ["pint-xarray"] # Composites/Modifiers: From 76e6b825ef397696cc0b1714ff78003319b8f628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= <49512274+ludwigVonKoopa@users.noreply.github.com> Date: Tue, 18 Jun 2024 08:13:17 +0000 Subject: [PATCH 3/3] correct geotiff reader dependencies, and standardize noqa comments --- pyproject.toml | 2 +- satpy/readers/generic_image.py | 2 +- satpy/readers/sar_c_safe.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d988737746..673405cfb1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,7 @@ gms5-vissr_l1b = ["numba"] # Writers: cf = ["h5netcdf >= 0.7.3"] awips_tiled = ["netCDF4 >= 1.1.8"] -geotiff = ["rasterio", "rioxarray", "trollimage[geotiff]"] +geotiff = ["rasterio", "trollimage[geotiff]"] ninjo = ["pyninjotiff", "pint"] units = ["pint-xarray"] # Composites/Modifiers: diff --git a/satpy/readers/generic_image.py b/satpy/readers/generic_image.py index 32102cf7c9..5032b7bbb8 100644 --- a/satpy/readers/generic_image.py +++ b/satpy/readers/generic_image.py @@ -31,7 +31,7 @@ import dask.array as da import numpy as np import rasterio -import rioxarray # noqa: F401, need by xarray with the engine rasterio +import rioxarray # noqa: F401 # need by xarray with the engine rasterio import xarray as xr from pyresample import utils diff --git a/satpy/readers/sar_c_safe.py b/satpy/readers/sar_c_safe.py index b121399920..f04656bfe9 100644 --- a/satpy/readers/sar_c_safe.py +++ b/satpy/readers/sar_c_safe.py @@ -46,7 +46,7 @@ import defusedxml.ElementTree as ET import numpy as np import rasterio -import rioxarray # noqa F401 : xarray open_dataset use engine rasterio, which use rioxarray +import rioxarray # noqa F401 # xarray open_dataset use engine rasterio, which use rioxarray import xarray as xr from dask import array as da from geotiepoints.geointerpolator import lonlat2xyz, xyz2lonlat