viz.visualize_nan_handling_modes
viz.visualize_nan_handling_modes(
modes_root_dir,
source_tiff,
*,
band='B04',
qa_band='SCL',
decode_qa=None,
min_nan_pct=1.0,
figsize=(12, 9.5),
)Render the canonical 3-row ‘how do the NaN modes differ?’ figure.
The earlier inline notebook version had three real bugs that this function fixes:
- It picked tiles without checking whether they actually had any NaN. A 0 % NaN tile cannot demonstrate any of the modes.
- It plotted
np.isnan(b04)on the kept tile – but by the time the tiler writes the tile, the NaN has already been resolved (dropped, filled, or zeroed-and-masked). So the “NaN map” panel was always empty (white) regardless of mode. - The colour-map / title pairing was backwards:
cmap="Greys"maps True to black but the title said “white = NaN”.
The fix is to reconstruct the before-state by reading the source TIFF window for each picked tile (so we have the original pixel values) and re-applying the same QA-band cloud decode the tiler used. Then for each mode we show what’s distinctive:
drop | source band w/ NaN in red | – | (drop has no positive output to show) interpolate | source band w/ NaN in red | post-handling band | filled pixels in green mask | source band w/ NaN in red | post-handling band | valid_mask band
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| modes_root_dir | path - like | Folder containing drop/, interpolate/, mask/ subdirectories (one per NaN-handling mode). Each subdirectory is the output_dir of a tile_geotiff call. |
required |
| source_tiff | path - like | Path to the TIFF that was passed to tile_geotiff as input_tiff. Read in windows to recover the source values + QA band for each picked tile. |
required |
| band | str | Band name (in source_tiff’s descriptions) to display. The same band is read from the post-handling tile for the “after” column. |
'B04' |
| qa_band | str | QA-band name in source_tiff’s descriptions. "SCL" for Sentinel-2 L2A, "BQA" for Landsat. When this is None or absent from the source, the before-state shows only the pixels with literal NaN in the source – typically very few, so the figure will look mostly empty. |
'SCL' |
| decode_qa | callable | Decoder for the QA band (e.g. :func:decode_scl for SCL or :func:decode_bqa for BQA). Required when qa_band is set. |
None |
| min_nan_pct | float | Minimum NaN fraction (in percent) required for a tile to be picked for any row. Defaults to 1 % so the figure is always informative; rows with no qualifying tile in their pool show a “no demo tile available” caption instead of being silently blank. | 1.0 |