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 (DataArray) – near-infrared band (Sentinel 2: Band 8) (Landsat 4-7: Band 4) (Landsat 8: Band 5)

  • swir1_agg (DataArray) – shortwave infrared band (Sentinel 2: Band 11) (Landsat 4-7: Band 5) (Landsat 8: Band 6)

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

Returns

  • xarray.DataArray – 2D array, of the same type as the input, of calculated ndmi values. All other input attributes are preserved.

  • Notes

  • ———-

  • Algorithm References

  • - USGS, Normalized Difference Moisture Index, https (//www.usgs.gov/land-resources/nli/landsat/normalized-difference-moisture-index, Accessed Apr. 21, 2021. # noqa)

  • Examples

  • ———-

  • Imports

  • >>> import numpy as np

  • >>> import xarray as xr

  • >>> import xrspatial

  • Create Sample Band Data

  • >>> np.random.seed(0)

  • >>> nir_agg = xr.DataArray(np.random.rand(4,4),

  • >>> dims = [“lat”, “lon”])

  • >>> height, width = nir_agg.shape

  • >>> _lat = np.linspace(0, height - 1, height)

  • >>> _lon = np.linspace(0, width - 1, width)

  • >>> nir_agg[“lat”] = _lat

  • >>> nir_agg[“lon”] = _lon

  • >>> np.random.seed(5)

  • >>> swir1_agg = xr.DataArray(np.random.rand(4,4),

  • >>> dims = [“lat”, “lon”])

  • >>> height, width = swir1_agg.shape

  • >>> _lat = np.linspace(0, height - 1, height)

  • >>> _lon = np.linspace(0, width - 1, width)

  • >>> swir1_agg[“lat”] = _lat

  • >>> swir1_agg[“lon”] = _lon

  • >>> print(nir_agg, swir1_agg)

  • <xarray.DataArray (lat (4, lon: 4)>)

  • array([[0.5488135 , 0.71518937, 0.60276338, 0.54488318], – [0.4236548 , 0.64589411, 0.43758721, 0.891773 ], [0.96366276, 0.38344152, 0.79172504, 0.52889492], [0.56804456, 0.92559664, 0.07103606, 0.0871293 ]])

  • Coordinates

    • lat (lat) float64 0.0 1.0 2.0 3.0

    • lon (lon) float64 0.0 1.0 2.0 3.0

  • <xarray.DataArray (lat (4, lon: 4)>)

  • array([[0.22199317, 0.87073231, 0.20671916, 0.91861091], – [0.48841119, 0.61174386, 0.76590786, 0.51841799], [0.2968005 , 0.18772123, 0.08074127, 0.7384403 ], [0.44130922, 0.15830987, 0.87993703, 0.27408646]])

  • Coordinates

    • lat (lat) float64 0.0 1.0 2.0 3.0

    • lon (lon) float64 0.0 1.0 2.0 3.0

  • Create NDMI DataArray

  • >>> data = xrspatial.multispectral.ndmi(nir_agg, swir1_agg)

  • >>> print(data)

  • <xarray.DataArray ‘ndmi’ (lat (4, lon: 4)>)

  • array([[ 0.4239978 , -0.09807732, 0.48925604, -0.25536675], – [-0.07099968, 0.02715428, -0.27280597, 0.26475493], [ 0.52906124, 0.34266992, 0.81491258, -0.16534329], [ 0.12556087, 0.70789018, -0.85060343, -0.51757753]])

  • Coordinates

    • lat (lat) float64 0.0 1.0 2.0 3.0

    • lon (lon) float64 0.0 1.0 2.0 3.0