get_data_mask

Contents

get_data_mask#

get_data_mask(array: ndarray | MaskedArray, has_nodata: bool, default_nodata: int = 0) ndarray[source]#

Get nodata mask from a masked array.

The nodata may not be set before, then pass a nodata value that will be evaluated on the array.

Warning

Sets 1 where the data is valid and 0 where it is not!

Example

>>> diag_arr = np.diag([1,2,3])
array([[1, 0, 0],
       [0, 2, 0],
       [0, 0, 3]])
>>>
>>> get_data_mask(diag_arr, has_nodata=False)
array([[1, 0, 0],
       [0, 1, 0],
       [0, 0, 1]], dtype=uint8)
>>>
>>> get_data_mask(diag_arr, has_nodata=False, default_nodata=1)
array([[0, 1, 1],
       [1, 1, 1],
       [1, 1, 1]], dtype=uint8)
Parameters:
  • array (np.ma.masked_array) – Array to evaluate

  • has_nodata (bool) – If the array as its nodata specified. If not, using default_nodata.

  • default_nodata (int) – Default nodata used if the array’s nodata is not set

Returns:

Pixelwise nodata array

Return type:

np.ndarray