Skip to content

Commit

Permalink
OPTIM: Save nodata of DIMAP V2 products on disk to avoid recomputing …
Browse files Browse the repository at this point in the history
…it (`features.rasetrize` could be a heavy computation that shouldn't be done twice)
  • Loading branch information
remi-braun committed Sep 3, 2024
1 parent e6c8af5 commit 22792f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- 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 nodata of DIMAP V2 products on disk to avoid recomputing it (`features.rasetrize` 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))

## 0.21.2 (2024-07-30)
Expand Down
28 changes: 20 additions & 8 deletions eoreader/products/optical/dimap_v2_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,10 @@ def _manage_nodata(
)

# Get detector footprint to deduce the outside nodata
LOGGER.debug("Load nodata")
nodata = self._load_nodata(width, height, vec_tr, **kwargs)

LOGGER.debug("Set nodata mask")
return self._set_nodata_mask(band_arr, nodata)

@cache
Expand Down Expand Up @@ -1086,15 +1088,25 @@ def _load_nodata(
if all(nodata_det.is_empty):
return np.zeros((1, height, width), dtype=np.uint8)
else:
# Rasterize nodata
return features.rasterize(
nodata_det.geometry,
out_shape=(height, width),
fill=self._mask_true, # Outside ROI = nodata (inverted compared to the usual)
default_value=self._mask_false, # Inside ROI = not nodata
transform=trf,
dtype=np.uint8,
nodata_path, nodata_exists = self._get_out_path(
f"{self.condensed_name}_nodata_{int(width)}x{int(height)}.npy"
)
if not nodata_exists:
LOGGER.debug("Rasterizing ROI mask to the extent of ")
# Rasterize nodata
nodata = features.rasterize(
nodata_det.geometry,
out_shape=(height, width),
fill=self._mask_true, # Outside ROI = nodata (inverted compared to the usual)
default_value=self._mask_false, # Inside ROI = not nodata
transform=trf,
dtype=np.uint8,
)
np.save(str(nodata_path), nodata)
else:
nodata = np.load(str(nodata_path))

return nodata

def _get_tile_path(self) -> AnyPathType:
"""
Expand Down

0 comments on commit 22792f7

Please sign in to comment.