English | Deutsch

False-colour SWIR image (Sentinel-2)

A picture made of invisible light that separates snow, clouds, water and vegetation. A short-wave infrared band is shown as red, a near-infrared band as green and the red band as blue. Vegetation looks green, bare soil and built-up areas look brown to orange, and water looks black. Snow and ice absorb short-wave infrared light and look cyan (light blue), while clouds stay white. Compare it with the true-colour image of the same area to learn the colours.

At a glance

Download function

download_false_color_swir(), short download_swir

Plot function

plot_false_color_swir(), short plot_swir

Source

Sentinel-2 Level-2A (collection SENTINEL2_L2A), bands B12 (shown as red), B8A (green) and B04 (blue)

Pixel size

10 m (B12 and B8A have 20 m detail)

Result

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

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_swir, plot_swir

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_swir("data/swir_bremen.tif", spatial_extent, temporal_extent)
plot_swir(path)
Short-wave infrared image of Bremen: vegetation bright green, built-up areas brown and grey, rivers and lakes black, white patches without data.

Bremen, June 2024. Green: vegetation, brown and grey: built-up, black: water. White: no data. Contains modified Copernicus Sentinel data 2024.

Things to know

  • Clouds and snow are removed by default, so you do not see the colours that tell them apart. To see snow use scl_classes=(4, 5, 6, 11); to see clouds next to it use scl_classes=None. Choose a short period, so that the picture is not a mean of days with and without snow (Filter clouds, NDSI (Sentinel-2)).

  • A fixed stretch. It is the stretch of the false-colour urban image: the reflectance 0 to 0.4 becomes 0 to 255, and the brightest values are compressed instead of clipped. The same reflectance always gets the same colour, so images can be compared by eye (Compare images).

  • Do not calculate with the picture. For differences and thresholds download with enhance_contrast=False (Calculate with reflectance).

  • Similar to the urban image. Both use short-wave infrared bands. The urban image shows vegetation in green and the city in grey; this one has brown built-up areas and separates snow from cloud.

  • Pixels without data are masked in the file and transparent in the plot, as in the other pictures.

See also

True-colour image (Sentinel-2), False-colour urban image (Sentinel-2), False-colour infrared image (Sentinel-2), NDSI (Sentinel-2), Colours and values

Download

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

Short alias: download_swir

Download a Sentinel-2 false-colour SWIR composite.

B12, B8A and B04 are displayed as red, green and blue, respectively. Observations are masked using SCL, averaged over the requested period, and then enhanced for display by stretching contrast and compressing highlights. The output grid is 10 m; B12, B8A and SCL retain their native 20 m detail.

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 contrast enhancement.

  • enhance_contrast (bool) – If True, create an 8-bit RGB image using a reflectance stretch of 0..0.4 with highlight compression. The stretch is fixed: it does not look at the values of the image, so the same reflectance always gets the same colour, and images of different dates or places can be compared by eye. 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_contrast=True) it is a colour picture: three bands of 8-bit integers from 0 to 255, in the order red, green, blue (B12, B8A, B04). 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_contrast=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). B12 and B8A have only 20 m detail.

Return type:

Path

Plot

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

Short alias: plot_swir

Draw the picture of download_false_color_swir.

Bands B12, B8A and B04 are shown as red, green and blue. In this false colour image vegetation looks green, bare ground and built-up areas brown to orange, water black, and snow cyan while clouds stay white. A file downloaded with the default enhance_contrast=True already holds 8-bit colours and is drawn as it is. A file downloaded with enhance_contrast=False holds reflectance; it gets the same contrast stretch (0 … 0.4) as the download would have applied, for the picture only. Pixels without data are transparent.

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

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

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