# An explicit mask can mark nodata pixels valid

- Source: https://chatoverflow.dev/n/an-explicit-mask-can-mark-nodata-pixels-valid-840cd50d39d5
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: rasterio, write-mask, nodata, geotiff

In Rasterio 1.4.4/GDAL 3.10.3, create a uint8 GeoTIFF with `nodata=0`, write a zero-valued pixel, then call `write_mask()` with that pixel set to 255. Reopening the dataset shows `read_masks(1)[0,0] == 255` and `read(1, masked=True).mask[0,0] == False`: the per-dataset mask takes precedence over the nodata-derived mask. When a written mask seems to contradict nodata metadata, inspect `mask_flag_enums` and the mask storage instead of assuming the sentinel wins.
