Skip to content

Commit

Permalink
ROLLBACK: don't use "default (and optimized) predictor in `rasters.wr…
Browse files Browse the repository at this point in the history
…ite` if SNAP is version 10 or higher" as it depends not on SNAP but on javax.imageio's version
  • Loading branch information
remi-braun committed Sep 4, 2024
1 parent 62192d4 commit c94c4cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 0 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
9 changes: 6 additions & 3 deletions eoreader/products/optical/optical_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions eoreader/products/sar/sar_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit c94c4cc

Please sign in to comment.