English | Deutsch

Scene classification (Sentinel-2)

A map of what every pixel probably shows: vegetation, bare ground, water, cloud, cloud shadow, snow and so on. It is the Scene Classification Layer (SCL) that the other Sentinel-2 downloads use to mask clouds (Sentinel-2 scene classification). Download it to see why pixels are missing in an NDVI or a true-colour image, and to choose scl_classes for them.

At a glance

Download function

download_scene_classification_map(), short download_scl

Plot function

plot_scene_classification_map(), short plot_scl

Source

Sentinel-2 Level-2A (collection SENTINEL2_L2A), band SCL

Pixel size

10 m (the classes have 20 m detail)

Result

one band of class numbers (0 … 11) with the colours of the classes attached to the file; 0 means no data

Clouds

all scenes are used (max_cloud_cover=100), because the clouds are what the map should show; no pixel is masked

Period

the most recent observation of every pixel in temporal_extent

Example

from cdec import download_scl, plot_scl

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_scl("data/scl_bremen.tif", spatial_extent, temporal_extent)
plot_scl(path)
Scene classification of Bremen: vegetation green, not vegetated yellow, water blue, cloud shadows brown, clouds white and grey.

Bremen, most recent observation of every pixel in June 2024. Contains modified Copernicus Sentinel data 2024.

The legend of the plot lists only the classes that occur in the picture. cdec.show_scl_classes() prints all 12 classes with a hint for each one.

Things to know

  • No average. Class numbers have no mean: the average of “vegetation” (4) and “cloud” (9) is not a class. Each pixel keeps the class of its most recent observation in the period.

  • One date per pixel, not one date for the picture. Neighbouring pixels can come from different days. For the classification of one day use a period of one day.

  • Use it to choose scl_classes. If a pixel is missing in your NDVI, look up its class here. A river that is missing is class 6 (water), which NDVI drops by default; a patch that is missing in summer is probably cloud or cloud shadow (Filter clouds).

  • It is a guess of a computer program. The classification is not perfect: thin clouds, haze and cloud edges are sometimes labelled as land, and snow is sometimes labelled as cloud (Sentinel-2 scene classification).

  • The colours are the ones of cdec.SCL_COLORS. The plot takes them from there, not from the colour table inside the file, so every file looks the same.

  • Class 0 (no data) is transparent in the plot, as are pixels without any observation.

See also

Sentinel-2 scene classification, Filter clouds, Clouds and masking, Land cover (ESA WorldCover)

Download

cdec.download_scene_classification_map(file_path, spatial_extent, temporal_extent, max_cloud_cover=100, *, create_cog=True, overview_resampling='nearest')[source]

Short alias: download_scl

Download the Sentinel-2 scene classification map.

The Scene Classification Layer (SCL) says for every 20 m pixel what it probably shows: vegetation, water, cloud, snow and so on (see cdec.show_scl_classes()). Class numbers cannot be averaged, so every pixel keeps the class of its most recent observation in the requested period. The result contains the class IDs 1 to 11; 0 means no data. The colour table of the map is attached to the GeoTIFF.

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. The default of 100 uses every scene, because the clouds are what a classification map should show.

  • create_cog (bool) – If True, write a Cloud Optimized GeoTIFF.

  • overview_resampling (OverviewResampling) – Resampling method used to build COG overview levels. "nearest" keeps the class IDs and should normally not be changed.

Returns:

Absolute path of the GeoTIFF that was written. The file has one band of 8-bit integers (uint8): the SCL class of every pixel, 1 to 11. 0 means no data and is declared as the no-data value. The colours of the classes are stored in the file as a colour table, and cdec.show_scl_classes() explains the numbers. The pixel size is 10 m, in the UTM zone of the area (EPSG:32632 for Bremen); the classes themselves have 20 m detail.

Return type:

Path

Plot

cdec.plot_scene_classification_map(file_path, *, ax=None, title=None, show=None)[source]

Short alias: plot_scl

Draw the classes of download_scene_classification_map.

Every pixel is one of the SCL classes (cdec.SCL_CLASSES) and is drawn in the colour of its class (cdec.SCL_COLORS). The legend lists only the classes that occur in the image. Pixels of class 0 (no data) are transparent and are not in the legend.

The colours are not read from the colour table inside the file but from cdec.SCL_COLORS, so the picture looks the same for every file.

Parameters:
  • file_path (str | Path) – The GeoTIFF written by download_scl.

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

  • title (str | None) – Title of the plot. Default: “Scene classification (Sentinel-2)”. Use "" for no title.

  • 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. The legend is placed to the right of the plot; to save it in a picture file use plt.savefig("scene_classification.png", bbox_inches="tight").

Return type:

matplotlib.axes.Axes

Raises:

ValueError – If the file does not have exactly one band.