xrspatial.multispectral.ndmi#

xrspatial.multispectral.ndmi(nir_agg: xarray.core.dataarray.DataArray, swir1_agg: xarray.core.dataarray.DataArray, name='ndmi')[source]#

Computes Normalized Difference Moisture Index. Used to determine vegetation water content.

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

  • swir1_agg (xr.DataArray) – 2D array of shortwave infrared band. (Landsat 4-7: Band 5) (Landsat 8: Band 6)

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

Returns

ndmi_agg – 2D array of ndmi values. All other input attributes are preserved.

Return type

xr.DataArray of same type as inputs

References

Examples

>>> from xrspatial.datasets import get_data
>>> data = get_data('sentinel-2')  # Open Example Data
>>> nir = data['NIR']
>>> swir1 = data['SWIR1']
>>> from xrspatial.multispectral import ndmi
>>> # Generate NDMI Aggregate Array
>>> ndmi_agg = ndmi(nir_agg=nir, swir1_agg=swir1)
>>> nir.plot(aspect=2, size=4)
>>> swir1.plot(aspect=2, size=4)
>>> ndmi_agg.plot(aspect=2, size=4)
../../_images/xrspatial-multispectral-ndmi-1_00.png

(png, hires.png, pdf)#

../../_images/xrspatial-multispectral-ndmi-1_01.png

(png, hires.png, pdf)#

../../_images/xrspatial-multispectral-ndmi-1_02.png

(png, hires.png, pdf)#

>>> y1, x1, y2, x2 = 100, 100, 103, 104
>>> print(nir[y1:y2, x1:x2].data)
[[1519. 1504. 1530. 1589.]
 [1491. 1473. 1542. 1609.]
 [1479. 1461. 1592. 1653.]]
>>> print(swir1[y1:y2, x1:x2].data)
[[2092. 2242. 2333. 2382.]
 [2017. 2150. 2303. 2344.]
 [2124. 2244. 2367. 2452.]]
>>> print(ndmi_agg[y1:y2, x1:x2].data)
[[-0.15868181 -0.19701014 -0.20786953 -0.1996978 ]
 [-0.149943   -0.18686172 -0.19791937 -0.18593474]
 [-0.17901748 -0.21133603 -0.19575651 -0.19464068]]