Skip to content

Commit

Permalink
FIX: Fix an xarray issue when trying to compute percentiles when st…
Browse files Browse the repository at this point in the history
…acking bands
  • Loading branch information
remi-braun committed Nov 8, 2023
1 parent 0896216 commit 867f1d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- **ENH: Manage Sentinel-2 (currently L2A) as formatted on the cloud (Element84's way). ([#104](https://github.com/sertit/eoreader/issues/104)**
- **ENH: Handle Python 3.12. ([#113](https://github.com/sertit/eoreader/issues/113)**
- FIX: Fix jpg, png... quicklooks management when plotting
- FIX: Fix an `xarray` issue when trying to compute percentiles when stacking bands
- CI: Update pre-commit hooks
- CI: Revamping `test_satellites`
- DEPS: Remove as many mention as possible to `cloudpathlib`
Expand Down
6 changes: 5 additions & 1 deletion eoreader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,11 @@ def stack(
scale = 10000
round_nb = 1000
round_min = -0.1
stack_min = float(band_xds.to_array().quantile(0.001))
try:
stack_min = float(band_xds.to_array().quantile(0.001))
except ValueError:
stack_min = np.nanpercentile(band_xds.to_array(), 1)

if np.round(stack_min * round_nb) / round_nb < round_min:
LOGGER.warning(
f"Cannot convert the stack to uint16 as it has negative values ({stack_min} < {round_min}). Keeping it in float32."
Expand Down

0 comments on commit 867f1d1

Please sign in to comment.