Addressed negative reflectance values from fusion.

This commit is contained in:
Felix Delattre 2026-06-11 23:36:54 +02:00
parent e58719f18b
commit 2ca1a808d2

View file

@ -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"))