xrspatial.multispectral.ndwi#

xrspatial.multispectral.ndwi(green_agg: DataArray, nir_agg: DataArray, name='ndwi')[source]#

Computes Normalized Difference Water Index (NDWI).

NDWI highlights open water features while suppressing vegetation and soil signal.

Parameters:
  • green_agg (xr.DataArray) – 2D array of green band data. (Landsat 8: Band 3) (Sentinel-2: Band 3)

  • nir_agg (xr.DataArray) – 2D array of near-infrared band data. (Landsat 8: Band 5) (Sentinel-2: Band 8)

  • name (str, default='ndwi') – Name of output DataArray.

  • Alternatively

  • first (a single xr.Dataset may be passed as the)

  • Dataset (argument with keyword arguments mapping band names to)

  • example:: (variables. For) – ndwi(ds, green=’B3’, nir=’B8’)

Returns:

ndwi_agg – 2D array of ndwi values in the range [-1, 1]. All other input attributes are preserved.

Return type:

xr.DataArray of same type as inputs

References

  • McFeeters, S.K., 1996. The use of the Normalized Difference Water Index (NDWI) in the delineation of open water features. International Journal of Remote Sensing, 17(7), pp.1425-1432.

Examples

>>> import numpy as np
>>> import xarray as xr
>>> from xrspatial.multispectral import ndwi
>>> green = xr.DataArray(np.array([[600., 500.], [400., 300.]]))
>>> nir = xr.DataArray(np.array([[300., 400.], [500., 600.]]))
>>> ndwi(green, nir).values
array([[ 0.33333334,  0.11111111],
       [-0.11111111, -0.33333334]], dtype=float32)