From c94c4cc2a3a418de45f7192226ba6f8c8ea99a92 Mon Sep 17 00:00:00 2001 From: BRAUN REMI Date: Wed, 4 Sep 2024 13:13:31 +0200 Subject: [PATCH] ROLLBACK: don't use "default (and optimized) predictor in `rasters.write` if SNAP is version 10 or higher" as it depends not on SNAP but on javax.imageio's version --- CHANGES.md | 1 - eoreader/products/optical/optical_product.py | 9 ++++++--- eoreader/products/sar/sar_product.py | 14 ++++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 07328c16..c346f711 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,7 +6,6 @@ - ENH: Add a `BandType` alias for any types that could be a band: a string, a `BandNames` or any of its children: Spectral, SAR, DEM or Cloud band names - FIX: Resolve the inversion of resolution and pixel size between `stripmap` and `sliding_spotlight` types for `Capella` products - FIX: Get better window name (if available) when writing bands on disk (in tmp folder) -- OPTIM: Use default (and optimized) predictor in `rasters.write` if SNAP is version 10 or higher ([#173](https://github.com/sertit/eoreader/issues/173)) - OPTIM: Save rasterized masks of DIMAP V2 products on disk to avoid recomputing them (`features.rasterize` could be a heavy computation that shouldn't be done twice) - COMPAT: EOReader works correctly with SNAP 10 ([#165](https://github.com/sertit/eoreader/issues/165)) diff --git a/eoreader/products/optical/optical_product.py b/eoreader/products/optical/optical_product.py index 5896c7dc..2f1eb62b 100644 --- a/eoreader/products/optical/optical_product.py +++ b/eoreader/products/optical/optical_product.py @@ -604,20 +604,23 @@ def _load_clouds( return band_dict def _create_mask( - self, xds: xr.DataArray, cond: np.ndarray, nodata: np.ndarray + self, xda: xr.DataArray, cond: np.ndarray, nodata: np.ndarray ) -> xr.DataArray: """ Create a mask from a conditional array and a nodata mask. Args: - xds (xr.DataArray): xarray to retrieve attributes + xda (xr.DataArray): xarray to retrieve attributes cond (np.ndarray): Conditional array nodata (np.ndarray): Nodata mask Returns: xr.DataArray: Mask as xarray """ - mask = xds.copy(data=np.where(cond, self._mask_true, self._mask_false)) + # Create mask + mask = xda.copy(data=np.where(cond, self._mask_true, self._mask_false)) + + # Set nodata to mask mask = mask.where(nodata == 0) return mask diff --git a/eoreader/products/sar/sar_product.py b/eoreader/products/sar/sar_product.py index ae6ca3d0..6dc6cb17 100644 --- a/eoreader/products/sar/sar_product.py +++ b/eoreader/products/sar/sar_product.py @@ -239,15 +239,21 @@ def _has_snap_10_or_higher(self) -> bool: def _get_predictor(self) -> int: """ - Set LZW predictor to 1 in order SNAP < 10.0.0 to be able to read this GeoTiff (in despeckle operations mostly). + Set LZW predictor to 1 in order to SNAP to be able to read this GeoTiff (in despeckle operations mostly). Else set to 3. Caused by: javax.imageio.IIOException: Illegal value for Predictor in TIFF file - Leave it to None if SNAP is 10 or higher + This is related to JAVA imageio library, not SNAP directly, so be sure to have imageio up-to-date to set 3. + For now, it is unknown to know if imageio handles predictor = 3, so live it to 1. + """ - # 3 for float if handled - return 3 if self._has_snap_10_or_higher() else 1 + # If we could know if imageio handles Predictor=3: + # # 3 for float if handled + # return 3 if xxx else 1 + + # But we cannot: + return 1 def _need_snap_to_pre_process(self): """This product needs SNAP for pre-process."""