English | Deutsch

NDVI (Sentinel-2)

The Normalized Difference Vegetation Index tells how green and dense the plants are. Healthy plants reflect much near-infrared light and absorb red light, so NDVI = (NIR - red) / (NIR + red) is high for them. The result is one number per pixel: close to 1 for dense green vegetation, around 0.1 to 0.2 for bare soil, and low or negative for water, built-up surfaces and clouds.

At a glance

Download function

download_normalized_difference_vegetation_index(), short download_ndvi

Plot function

plot_normalized_difference_vegetation_index(), short plot_ndvi

Source

Sentinel-2 Level-2A (collection SENTINEL2_L2A), bands B04 (red) and B08 (near-infrared)

Pixel size

10 m

Result

one band of floating-point numbers, no unit, -1 … 1

Clouds

scenes above max_cloud_cover (20 %) are not used; pixels are masked with scl_classes (default: vegetation and not vegetated)

Period

mean of all observations of temporal_extent

Example

from cdec import download_ndvi, plot_ndvi

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_ndvi("data/ndvi_bremen.tif", spatial_extent, temporal_extent)
plot_ndvi(path)
NDVI of Bremen in June 2024: green fields and parks, yellow-green built-up areas, white patches without data.

Bremen, June 2024. White: no data. Contains modified Copernicus Sentinel data 2024.

Things to know

  • The index is calculated from the mean reflectance of the period, not as the mean of the NDVI of every date.

  • Holes. A pixel without a single usable observation stays empty. In the example about a quarter of the pixels are empty. A longer period or a higher max_cloud_cover fills holes (Filter clouds).

  • Water is empty by default. The default scl_classes is (4, 5), which keeps vegetation and not vegetated pixels only. Use scl_classes=cdec.SCL_LAND_AND_WATER to keep water.

  • Values outside -1 … 1. A few pixels can lie slightly outside, for example when the red reflectance is close to zero. The example file ranges from -0.66 to 1.26. Treat them as noise or clip them with numpy.clip(ndvi, -1, 1). The other indices (EVI, NDWI, NDMI, NDSI) can do the same.

  • The plot uses red-yellow-green colours and a fixed range of -1 to 1, so the same colour always means the same NDVI and two maps can be compared by eye.

  • For a longer time series (1997-2025) at a coarser resolution use NDVI (Landsat).

See also

Filter clouds, Choose the period, Clouds and masking

Download

cdec.download_normalized_difference_vegetation_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_ndvi

Download a Sentinel-2 NDVI raster.

Red and near-infrared reflectance from Sentinel-2 Level-2A are masked using the Scene Classification Layer (SCL), then averaged over the requested period before calculating NDVI. Use cdec.download_landsat_ndvi() for the historical Landsat mosaic. The output retains the 10 m reflectance grid; SCL classification detail remains 20 m.

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. Use SCL_LAND_AND_WATER = (4, 5, 6) to also keep water, or None to switch SCL masking off. Run cdec.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 NDVI, a number without unit between -1 and 1 (dense green vegetation is close to 1). 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).

Return type:

Path

Plot

cdec.plot_normalized_difference_vegetation_index(file_path, *, ax=None, title=None, cmap='RdYlGn', vmin=-1.0, vmax=1.0, colorbar=True, show=None)[source]

Short alias: plot_ndvi

Draw the NDVI of download_normalized_difference_vegetation_index.

NDVI lies between -1 and 1: water and bare ground are around or below 0, dense green vegetation is above 0.6. The colour map goes from red (low) over yellow to green (high). 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_ndvi.

  • ax (Axes | None) – A matplotlib Axes to draw into. None creates a new figure.

  • title (str | None) – Title of the plot. Default: “NDVI (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. None takes the smallest and largest value of the image instead.

  • vmax (float | None) – Values at the two ends of the colour map. None takes 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.