English | Deutsch
False-colour urban image (Sentinel-2)¶
A picture that uses invisible light. Two short-wave infrared bands and the red band are shown as red, green and blue, so that surfaces which look alike to the eye get different colours: vegetation, bare soil, built-up areas and water. In the example below vegetation is green, water is black and the built-up areas of the city are grey. Compare it with the true-colour image of the same area to learn the colours.
Download function |
|
|---|---|
Plot function |
|
Source |
Sentinel-2 Level-2A (collection |
Pixel size |
10 m (B11 and B12 have 20 m detail) |
Result |
by default an 8-bit colour picture (three bands, 0 … 255); with |
Clouds |
scenes above |
Period |
mean of all observations of |
Example¶
from cdec import download_urban, plot_urban
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_urban("data/urban_bremen.tif", spatial_extent, temporal_extent)
plot_urban(path)
Bremen, June 2024. White: no data. Contains modified Copernicus Sentinel data 2024.¶
Things to know¶
A fixed stretch. The reflectance 0 to 0.4 becomes 0 to 255, and the brightest values are compressed instead of clipped. No statistics of the image are used, so the same reflectance always gets the same colour and images of different dates or places 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).Not identical to the Copernicus Browser. The stretch is the one of the Sentinel Hub “false colour (urban)” layer, but that layer shows one acquisition date, and this one the cloud-masked mean of a period.
Pixels without data are masked in the file and transparent in the plot, as in the true-colour image.
See also¶
True-colour image (Sentinel-2), Colours and values, Filter clouds
Download¶
- cdec.download_false_color_urban(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_urbanDownload a Sentinel-2 false-colour urban composite.
B12, B11 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; B11, B12 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. Add11to keep snow/ice, or useNoneto switch SCL masking off. Runcdec.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. IfFalse, 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, B11, B04). Pixels without data are 0 in all bands; the file marks them with a mask, so GIS programs andrasteriotreat them as empty. Withenhance_contrast=Falsethe file holds the measurement instead: threefloat32bands 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). B11 and B12 have only 20 m detail.- Return type:
Path
Plot¶
- cdec.plot_false_color_urban(file_path, *, ax=None, title=None, show=None)[source]¶
Short alias:
plot_urbanDraw the picture of
download_false_color_urban.Bands B12, B11 and B04 are shown as red, green and blue. In this false colour image built-up areas look in shades of grey and brown-red, vegetation green and water dark. A file downloaded with the default
enhance_contrast=Truealready holds 8-bit colours and is drawn as it is. A file downloaded withenhance_contrast=Falseholds 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_urban.ax (Axes | None) – A matplotlib
Axesto draw into.Nonecreates a new figure.title (str | None) – Title of the plot. Default: “False colour urban (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.