Repository navigation
Fix the inverted all-masked cell guard - #83
Merged
Merged
Conversation
marlens123
reviewed
Aug 12, 2026
Collaborator
just to explain why we always do |
Both Stage-2 inference entry points guarded against predicting on a cell with no
observations, and both read the loader's masks with the wrong polarity. The loader
emits 1 = masked (landsat_eval.py:630-631), the guard's comment claimed 1 = valid, so
`all(not mask.any() ...)` asked "is this cube perfect?" instead of "is it empty?".
It was worse than inverted: it was a constant False. `mask_prediction_era5` forces a 1
into `t_m` on every cube, so the generator short-circuited before reading anything else,
and `st_m` (location, derived from the cell centre) is never nodata, so flipping the
comparison alone would have left it equally unreachable. A 100%-nodata cell therefore
received a finite, plausible FSC derived from its coordinates alone, written to the COG
as a measurement and counted in `aoi_coverage_fraction`. No NaN, no exception, no log.
Existing outputs are unaffected: measured over all 7300 cubes on disk, zero would have
triggered the guard. The bug was latent.
The replacement, `_loader_bridge.has_no_spacetime_observation`, fires when all three
space-time masks are 1 everywhere. Static ancillary (DEM, WorldCover), non-spatial time
bands (coarse VIIRS, ERA5) and derived geometry (location) are excluded: none can support
a spatially-resolved FSC patch on its own, and including location would make the
condition unsatisfiable. It reads named `MaskedOutput` fields rather than positional
indices, because a positional lookup with a comment asserting the opposite polarity is
exactly what failed here.
One definition in `_loader_bridge.py`, shared by the driver and the script, replacing two
copies. The per-cell "cell_fully_masked" warning becomes a per-day count; at grid scale
the condition it reports would fire for every cell of a sparsely-covered AOI.
Tests: all three fakes in test_inference_driver.py encoded the inverted convention, one
of them labelling all-ones masks "all-valid". Left alone, five tests would have stayed
green while silently writing empty mosaics. They now build real `MaskedOutput`s, so a
double that disagrees with the loader raises instead of answering wrong. The placeholder
end-to-end test becomes the empty-cell regression test, and a new positive-path test
derives a real cube from tests/fixtures/gee_reference_patches, since a placeholder cube
can no longer reach the predict-and-write path.
AC-28 and TASK-015-PLAN.md are amended: the original wording ("all input groups masked")
was unsatisfiable for every possible input, and the plan deferred the polarity to "the
existing mask convention" rather than stating it.
Assisted by Claude Code.
The AC-28 guard fix cited `docs/agents/bugs/MASK_CHECK_BUG.md` from seven places in committed files. That path is not in the repository, so every one of them was a dead link for anyone but its author. The surrounding docstrings already say what the defect was and why the current shape avoids it, so the citations carried no information the reader could not get in place. Docstrings and comments only; no behaviour change. Assisted by Claude Code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both Stage-2 inference entry points refuse to predict on a cell with no observations — in theory. The guard read the
loader's masks as
1 = valid; the loader emits1 = masked. Two quirks (t_malways carries a forced1,st_misnever nodata) made it a constant
False: it has never fired, in either direction. A cell with zero observationstherefore received a finite, plausible FSC derived from its coordinates alone, written to the COG as a measurement and
counted as covered — no
NaN, no exception, no log line.No existing output is affected. Measured over all 7300 cubes on disk: zero would have fired. Latent, not active —
no reprocessing.
_loader_bridge.has_no_spacetime_observation— one shared definition replacing two copies. Fires when all threespace-time masks are
1everywhere. Reads namedMaskedOutputfields, not indices, because a positional lookupunder a comment asserting the opposite polarity is exactly what failed.
space(DEM/WorldCover),time(coarse VIIRS/ERA5) andstatic(location) are excluded: none can support aspatially-resolved FSC patch alone, and
staticis never nodata, so including it keeps the guard dead.Now real
MaskedOutputs, so a double that disagrees with the loader raises instead of answering wrong.tests/fixtures/gee_reference_patches— the placeholder cube now(correctly) takes the nodata branch and can no longer reach the predict-and-write path.
Tests: 359 passed, 2 skipped (pre-existing, SNAP output absent).
ruff,mdformat,mypyclean.Illustration of dataflow :
Channel-group membership of each mask tensor, from
src/snow_galileo/data/earthengine/eo.py:s_t_h_m(100,100,8,7)s_t_m_m(5,5,8,1)s_t_l_m(2,2,8,7)sp_m(100,100,2)t_m(8,4)st_m(1,)Which Tensors count as input?
s_t_h_m(6)s_t_m_m(7)s_t_l_m(8)t_m(10) — VIIRS coarset_m(10) — ERA5sp_m(9) — DEM, WCst_m(11) — locationAssisted by Claude Code