Addressed negative reflectance values from fusion.
This commit is contained in:
parent
e58719f18b
commit
2ca1a808d2
1 changed files with 9 additions and 4 deletions
13
4-fusion.py
13
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).
|
"""Derive GCC from ``REFL_YYYYMMDD.tif`` files (BtI fusion output).
|
||||||
|
|
||||||
Reads every ``REFL_*.tif`` and writes a co-located single-band
|
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)
|
gcc_dir.mkdir(parents=True, exist_ok=True)
|
||||||
for src_path in sorted(refl_dir.glob("REFL_*.tif")):
|
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)
|
b, g, r = src.read(1), src.read(2), src.read(3)
|
||||||
profile = src.profile
|
profile = src.profile
|
||||||
total = b + g + r
|
total = b + g + r
|
||||||
gcc = g / (total + 1e-10)
|
invalid = (b < 0) | (g < 0) | (r < 0)
|
||||||
gcc[total == 0] = 0
|
gcc = np.where(invalid, np.nan, g / (total + 1e-10))
|
||||||
profile.update(count=1)
|
gcc[total == 0] = np.nan
|
||||||
|
profile.update(count=1, dtype="float32")
|
||||||
with rasterio.open(out_path, "w", **profile) as dst:
|
with rasterio.open(out_path, "w", **profile) as dst:
|
||||||
dst.write(gcc[np.newaxis].astype("float32"))
|
dst.write(gcc[np.newaxis].astype("float32"))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue