⚠️ Our 0.1 release refactored several early-development functions for long-term stability, to update your code see here. ⚠️
Future changes will come with deprecation warnings! 🙂



Raster.set_nodata(new_nodata, update_array=True, update_mask=True)[source]#

Set a new nodata value for all bands. This updates the old nodata into a new nodata value in the metadata, replaces the nodata values in the data of the masked array, and updates the mask of the masked array.

Careful! If the new nodata value already exists in the array, the related grid cells will be masked by default.

If the nodata value was not defined in the raster, run this function with a new nodata value corresponding to the value of nodata that exists in the data array and is not yet accounted for. All those values will be masked.

If a nodata value was correctly defined in the raster, and you wish to change it to a new value, run this function with that new value. All values having either the old or new nodata value will be masked.

If the nodata value was wrongly defined in the raster, and you wish to change it to a new value without affecting data that might have the value of the old nodata, run this function with the update_array argument as False. Only the values of the new nodata will be masked.

If you wish to set nodata value without updating the mask, run this function with the update_mask argument as False.

If None is passed as nodata, only the metadata is updated and the mask of old nodata unset.

  • new_nodata (int | float | None) – New nodata value.

  • update_array (bool) – Update the old nodata values into new nodata values in the data array.

  • update_mask (bool) – Update the old mask by unmasking old nodata and masking new nodata (if array is updated, old nodata are changed to new nodata and thus stay masked).

Return type: