Improved debug output.
This commit is contained in:
parent
12578dd1f2
commit
6b7395b617
2 changed files with 17 additions and 11 deletions
17
5-metrics.py
17
5-metrics.py
|
|
@ -82,6 +82,14 @@ PHENOCAM_IMAGE_URL = (
|
|||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _window_mean(data: np.ndarray) -> float | None:
|
||||
"""Mean of a pixel window; ``None`` when every value is NaN."""
|
||||
valid = data[~np.isnan(data)]
|
||||
if valid.size == 0:
|
||||
return None
|
||||
return float(np.mean(valid))
|
||||
|
||||
|
||||
def _read_center_pixel(path: Path, lat: float, lon: float) -> float | None:
|
||||
"""Return the 3×3 mean GCC value at (lat, lon) from a single-band raster.
|
||||
|
||||
|
|
@ -103,9 +111,7 @@ def _read_center_pixel(path: Path, lat: float, lon: float) -> float | None:
|
|||
if nodata is not None:
|
||||
data = np.where(data == nodata, np.nan, data)
|
||||
data[data == 0] = np.nan
|
||||
with np.errstate(all="ignore"):
|
||||
val = np.nanmean(data)
|
||||
return None if np.isnan(val) else float(val)
|
||||
return _window_mean(data)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
|
@ -334,9 +340,8 @@ def _read_multiband_center(
|
|||
if nodata is not None:
|
||||
data = np.where(data == nodata, np.nan, data)
|
||||
data[data == 0] = np.nan
|
||||
with np.errstate(all="ignore"):
|
||||
val = np.nanmean(data)
|
||||
result[name] = None if np.isnan(val) else round(float(val), 6)
|
||||
val = _window_mean(data)
|
||||
result[name] = None if val is None else round(val, 6)
|
||||
return result
|
||||
except Exception:
|
||||
return {name: None for name in band_names}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue