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

import matplotlib.pyplot as plt
from xrspatial.multispectral import ndmi
from xrspatial.datasets import get_data

# Open Example Data
data = get_data('sentinel-2')

nir = data['NIR']
swir1 = data['SWIR1']

# Generate NDMI Aggregate Array
ndmi_agg = ndmi(nir_agg = nir,
                swir1_agg = swir1)

# Plot NIR Band
nir.plot(cmap = 'Greys', aspect = 2, size = 4)
plt.title("NIR Band")
plt.ylabel("latitude")
plt.xlabel("longitude")

# Plot SWIR1 Band
swir1.plot(cmap = 'Greys', aspect = 2, size = 4)
plt.title("SWIR1 Band")
plt.ylabel("latitude")
plt.xlabel("longitude")

# Plot NDMI
ndmi_agg.plot(cmap = 'Greys', aspect = 2, size = 4)
plt.title("NDMI")
plt.ylabel("latitude")
plt.xlabel("longitude")
../../_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)

>> print(ndmi_agg[100:103, 100: 102])
<xarray.DataArray 'ndmi' (y: 3, x: 2)>
array([[-0.15868181, -0.19701014],
       [-0.14994299, -0.18686172],
       [-0.17901749, -0.21133603]])
Coordinates:
  * x        (x) float64 6.01e+05 6.01e+05
  * y        (y) float64 4.699e+06 4.699e+06 4.699e+06
    band     int32 ...
Attributes: (12/13)
    transform:                [ 1.00000e+01  0.00000e+00  6.00000e+05  0.0000... # noqa
    crs:                      +init=epsg:32719
    res:                      [10. 10.]
    is_tiled:                 1
    nodatavals:               nan
    scales:                   1.0
    ...                       ...
    instrument:               Sentinel-2
    Band:                     07
    Name:                     NIR
    Bandwidth (µm):           115
    Nominal Wavelength (µm):  0.842
    Resolution (m):            10