English | Deutsch

True-colour image (Sentinel-2)

A picture of the area as the eye would see it: red, green and blue light. The image is the mean of all cloud-free observations of the period, not a photo of one day, so it looks calmer than a single satellite image, and clouds are replaced by the data of other days.

At a glance

Download function

download_true_color_image(), short download_tci

Plot function

plot_true_color_image(), short plot_tci

Source

Sentinel-2 Level-2A (collection SENTINEL2_L2A), bands B04 (red), B03 (green) and B02 (blue)

Pixel size

10 m

Result

by default an 8-bit colour picture (three bands, 0 … 255); with enhance_color=False three bands of reflectance (floating point, about 0 … 1)

Clouds

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

Period

mean of all observations of temporal_extent

Example

from cdec import download_tci, plot_tci

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_tci("data/tci_bremen.tif", spatial_extent, temporal_extent)
plot_tci(path)
True-colour image of Bremen in June 2024: green fields, grey roads and buildings, a dark river, white patches without data.

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

Things to know

  • A picture, not a measurement. The default file holds colours for the eye. The reflectance is recalculated into 0 … 255 with a fixed brightness, saturation and gamma curve. For calculations download with enhance_color=False (Calculate with reflectance).

  • Comparable colours. The curve does not look at the image, so the same reflectance always gets the same colour, in every image (Colours and values).

  • Pixels without data are black in the numbers, but the file stores a mask. GIS programs and the plot function show them as transparent.

  • Water is kept by default (scl_classes=(4, 5, 6)), clouds and shadows are removed. Pixels that stay empty are the ones where every observation of the period was removed.

  • The reflectance version can contain a few values above 1 (the example up to 1.8): bright clouds or snow that were not masked.

  • Plot a reflectance file with plot_true_color_image() as well: it enhances the colours for the picture only.

See also

False-colour urban image (Sentinel-2), Compare images, Filter clouds

Download

cdec.download_true_color_image(file_path, spatial_extent, temporal_extent, max_cloud_cover=20, scl_classes=(4, 5, 6), enhance_color=True, *, create_cog=True, overview_resampling='average')[source]

Short alias: download_tci

Download mean Sentinel-2 true-colour reflectance with SCL masking.

The output retains the 10 m reflectance grid; SCL classification detail remains 20 m.

Parameters:
  • file_path (str | Path) – Destination GeoTIFF path. Missing parent directories are created.

  • 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_AND_WATER = (4, 5, 6) keeps vegetation, non-vegetated land and water and drops clouds, cirrus, shadows, snow/ice, unclassified and defective pixels. Add 11 to keep snow/ice, or use 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, also after colour enhancement.

  • enhance_color (bool) – If True, enhance reflectance to an 8-bit RGB image. The enhancement uses fixed constants and does not look at the values of the image, so the same reflectance always gets the same colour. If False, retain the three bands as floating-point reflectance values (use this for calculations).

  • 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. By default (enhance_color=True) it is a colour picture: three bands of 8-bit integers from 0 to 255, in the order red, green, blue (B04, B03, B02). Pixels without data are 0 in all bands; the file marks them with a mask, so GIS programs and rasterio treat them as empty. With enhance_color=False the file holds the measurement instead: three float32 bands of reflectance (0 = black, about 1 = white), with NaN where there is no data. The pixel size is 10 m, in the UTM zone of the area (EPSG:32632 for Bremen).

Return type:

Path

Plot

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

Short alias: plot_tci

Draw the picture of download_true_color_image.

A file downloaded with the default enhance_color=True already holds 8-bit colours and is drawn as it is. A file downloaded with enhance_color=False holds reflectance; it is given the same colour enhancement as the download would have applied, for the picture only. The file keeps its reflectance values. Pixels without data are transparent.

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

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

  • title (str | None) – Title of the plot. Default: “True colour (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.

Return type:

matplotlib.axes.Axes

Raises:

ValueError – If the file does not have exactly three bands, or if they are neither 8-bit nor floating-point.