get_data_mask#
- get_data_mask(xds: DataArray | Dataset) ndarray [source]#
Get nodata mask from a xarray.
Warning
Sets 1 where the data is valid and 0 where it is not!
- Parameters:
xds (AnyXrDataStructure) – Array to evaluate
- Returns:
Pixelwise nodata array
- Return type:
np.ndarray
Example
>>> diag_arr = xr.DataArray(data=np.diag([1, 2, 3])) >>> diag_arr.rio.write_nodata(0, inplace=True) <xarray.DataArray (dim_0: 3, dim_1: 3)> array([[1, 0, 0], [0, 2, 0], [0, 0, 3]]) Dimensions without coordinates: dim_0, dim_1 >>> >>> # Get the data mask from this array >>> get_data_mask(diag_arr) array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=uint8)