From 2ca1a808d203683b04d7eff3ce19580f9af2159e Mon Sep 17 00:00:00 2001 From: Felix Delattre Date: Thu, 11 Jun 2026 23:36:54 +0200 Subject: [PATCH] Addressed negative reflectance values from fusion. --- 4-fusion.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/4-fusion.py b/4-fusion.py index cdcc4bc..5950c44 100644 --- a/4-fusion.py +++ b/4-fusion.py @@ -117,7 +117,11 @@ def compute_gcc_from_refl(refl_dir: Path, gcc_dir: Path) -> None: """Derive GCC from ``REFL_YYYYMMDD.tif`` files (BtI fusion output). Reads every ``REFL_*.tif`` and writes a co-located single-band - ``GCC_YYYYMMDD.tif``. Zero pixels remain zero. + ``GCC_YYYYMMDD.tif``. Pixels where any reflectance band is negative (which + can arise from EFAST's temporal correction) are written as NaN; the GCC + ratio is undefined there because the denominator B+G+R is near-zero or + negative due to band cancellation. All-zero pixels (cloud mask) remain + zero. """ gcc_dir.mkdir(parents=True, exist_ok=True) for src_path in sorted(refl_dir.glob("REFL_*.tif")): @@ -128,9 +132,10 @@ def compute_gcc_from_refl(refl_dir: Path, gcc_dir: Path) -> None: b, g, r = src.read(1), src.read(2), src.read(3) profile = src.profile total = b + g + r - gcc = g / (total + 1e-10) - gcc[total == 0] = 0 - profile.update(count=1) + invalid = (b < 0) | (g < 0) | (r < 0) + gcc = np.where(invalid, np.nan, g / (total + 1e-10)) + gcc[total == 0] = np.nan + profile.update(count=1, dtype="float32") with rasterio.open(out_path, "w", **profile) as dst: dst.write(gcc[np.newaxis].astype("float32"))