English | Deutsch
NDMI (Sentinel-2)¶
The Normalized Difference Moisture Index shows how much water the vegetation holds. Water in the leaves absorbs
short-wave infrared light, while the structure of the leaves reflects near-infrared light, so
NDMI = (NIR - SWIR) / (NIR + SWIR) is high for moist, leafy vegetation and falls when plants dry out. The result
is one number per pixel, between -1 and 1.
Download function |
|
|---|---|
Plot function |
|
Source |
Sentinel-2 Level-2A (collection |
Pixel size |
10 m (both bands have 20 m detail) |
Result |
one band of floating-point numbers, no unit, -1 … 1 |
Clouds |
scenes above |
Period |
mean of all observations of |
Example¶
from cdec import download_ndmi, plot_ndmi
spatial_extent = {"west": 8.721771, "south": 53.025027, "east": 8.904419, "north": 53.114965} # Bremen
temporal_extent = ["2024-06-01", "2024-07-01"] # June 2024, the end date is not included
path = download_ndmi("data/ndmi_bremen.tif", spatial_extent, temporal_extent)
plot_ndmi(path)
Bremen, June 2024. Green-blue: moist, beige: dry. White: no data, and water. Contains modified Copernicus Sentinel data 2024.¶
Things to know¶
20 m detail. Both bands have 20 m pixels. The backend puts them on the 10 m grid of Sentinel-2, so the file has 10 m pixels like the NDVI (Sentinel-2), but no finer detail than 20 m.
Moisture of the plants, not of the soil. The index describes the leaves. For the water in the soil use the Soil water index, which is much coarser (1 km).
Compare the same kind of vegetation. A meadow and a forest have different values even when both are healthy. The index is most useful for comparing one place at different times, for example a dry and a wet summer (Compare images).
Water is empty by default. The default
scl_classesis(4, 5). Water has no meaningful moisture value here; usescl_classes=cdec.SCL_LAND_AND_WATERif you want to see it anyway.The name. The same formula is called NDWI in some books (Gao’s index). In this package NDWI (Sentinel-2) is the index of McFeeters, made to find open water.
The index is calculated from the mean reflectance of the period, not as the mean of the index of every date.
The plot uses brown-white-blue-green colours and a fixed range of -1 to 1: brown for dry, blue-green for moist.
See also¶
NDVI (Sentinel-2), NDWI (Sentinel-2), Soil water index, Filter clouds
Download¶
- cdec.download_normalized_difference_moisture_index(file_path, spatial_extent, temporal_extent, max_cloud_cover=20, scl_classes=(4, 5), *, create_cog=True, overview_resampling='average')[source]¶
Short alias:
download_ndmiDownload a Sentinel-2 NDMI (moisture index) raster.
Near-infrared (B8A) and short-wave infrared (B11) reflectance from Sentinel-2 Level-2A are masked using the Scene Classification Layer (SCL), then averaged over the requested period before calculating the Normalized Difference Moisture Index:
NDMI = (NIR - SWIR) / (NIR + SWIR)It is high for vegetation that holds much water and low for dry vegetation and bare ground. Both bands have a pixel size of 20 m; the backend delivers them on the 10 m grid of Sentinel-2, so the file has 10 m pixels with 20 m detail. As with
cdec.download_normalized_difference_vegetation_index(), the index is calculated from mean reflectance, rather than averaging indices from individual dates.- Parameters:
file_path (str | Path) – Destination path of the GeoTIFF file. Missing parent directories are created automatically.
spatial_extent (SpatialExtent) – Area to download: an openEO bounding-box dictionary such as
{"west": 8.7, "south": 53.0, "east": 8.9, "north": 53.1}(degrees, WGS 84), a Shapely geometry, or the path to a GeoJSON file.temporal_extent (TemporalExtent) – Start and end of the observation period, e.g.
["2024-06-01", "2024-07-01"]. The end date itself is not included, so this example covers all of June.max_cloud_cover (int) – Maximum cloud cover of a whole scene in percent. Scenes that are cloudier are not used at all. This scene filter complements
scl_classes, which removes single pixels.scl_classes (Sequence[int] | None) – Scene Classification Layer (SCL) classes to keep, as a tuple of class IDs. The default
SCL_LAND=(4, 5)keeps vegetation and non-vegetated land and drops water, clouds, cirrus, shadows, snow/ice, unclassified and defective pixels. UseSCL_LAND_AND_WATER=(4, 5, 6)to also keep water, orNoneto switch SCL masking off. Runcdec.show_scl_classes()to see what each class means. Pixels without any retained observation remain no data.create_cog (bool) – If
True, write a Cloud Optimized GeoTIFF.overview_resampling (OverviewResampling) – Resampling method used to build COG overview levels.
- Returns:
Absolute path of the GeoTIFF that was written. The file has one band of floating-point numbers (
float32): the NDMI, a number without unit between -1 and 1 (high for plants that hold much water). Pixels without data are NaN, which the file declares as its no-data value. The pixel size is 10 m, in the UTM zone of the area (EPSG:32632 for Bremen); both bands have only 20 m detail.- Return type:
Path
Plot¶
- cdec.plot_normalized_difference_moisture_index(file_path, *, ax=None, title=None, cmap='BrBG', vmin=-1.0, vmax=1.0, colorbar=True, show=None)[source]¶
Short alias:
plot_ndmiDraw the NDMI of
download_normalized_difference_moisture_index.NDMI lies between -1 and 1: dry vegetation and bare ground are low, vegetation that holds much water is high. The colour map goes from brown (dry) over white to blue-green (moist). The range is fixed to -1 … 1, so two images always have the same colours and can be compared.
- Parameters:
file_path (str | Path) – The GeoTIFF written by
download_ndmi.ax (Axes | None) – A matplotlib
Axesto draw into.Nonecreates a new figure.title (str | None) – Title of the plot. Default: “NDMI (Sentinel-2)”. Use
""for no title.cmap (str) – Name of a matplotlib colour map.
vmin (float | None) – Values at the two ends of the colour map.
Nonetakes the smallest and largest value of the image instead.vmax (float | None) – Values at the two ends of the colour map.
Nonetakes the smallest and largest value of the image instead.colorbar (bool) – Draw a colour bar.
show (bool | None) – Call
plt.show()at the end. The default (None) shows the figure only if this function created it.
- Returns:
The axes with the plot, for further changes.
- Return type:
matplotlib.axes.Axes
- Raises:
ValueError – If the file does not have exactly one band.