English | Deutsch
Developer reference¶
Every download_* function follows the same recipe: connect, describe the data as an openEO
data cube, hand the cube to download_raster_cube(). These are the helpers
behind it. They are not meant to be called by users of the package.
Shared helpers¶
Shared helpers used by all download_* functions.
Every download function in this package follows the same recipe:
connect to the openEO backend,
describe the wanted data as an openEO data cube (load, mask, average, …),
hand the cube to
download_raster_cube(), which downloads it and writes the final GeoTIFF / Cloud Optimized GeoTIFF.
Steps 1 and 3 live here. Step 2 is deliberately kept inside each
download_* function so that it can be read from top to bottom.
- cdec.eo.util.get_connection()[source]¶
Connect to the Copernicus Data Space openEO backend and log in.
The first call opens a login (device code flow). The openEO client stores a refresh token, so later calls log in silently.
- cdec.eo.util.prepare_output_path(file_path)[source]¶
Return the absolute output path and create missing parent folders.
- cdec.eo.util.download_raster_cube(cube, file_path, create_cog=True, overview_resampling='average', postprocess=None)[source]¶
Download an openEO data cube as GeoTIFF and return the final path.
The cube is first downloaded into a hidden temporary folder next to the target file. Only when everything succeeded (download, optional
postprocess, optional COG conversion) is the finished file moved tofile_path. A failed download therefore never leaves a half-written file behind and never overwrites an existing good file.- Parameters:
cube – openEO data cube that already contains the final result.
file_path (str | Path) – Destination path. Missing parent folders are created.
create_cog (bool) – If
True, convert the download to a Cloud Optimized GeoTIFF.overview_resampling (OverviewResampling) – Resampling method for the COG overview levels. Use
"nearest"for categorical data such as land cover.postprocess (Callable[[Path], None] | None) – Optional function that receives the path of the downloaded GeoTIFF and rewrites it in place (e.g. colour enhancement).
- cdec.eo.util.BACKEND_URL = 'https://openeo.dataspace.copernicus.eu/'¶
Address of the Copernicus Data Space openEO backend.
- cdec.eo.util.SENTINEL2_REFLECTANCE_SCALE = 0.0001¶
Sentinel-2 L2A is stored as integers. Multiplying by this factor gives reflectance between 0 (black) and 1 (perfectly white).
- cdec.eo.util.DEFAULT_DEM_TEMPORAL_EXTENT: tuple[str, str] = ('2010-12-12T00:00:00Z', '2015-01-16T00:00:00Z')¶
Static data sets (they do not change over time) still need a temporal extent in openEO. This is the acquisition period of the elevation model.
Scene classification helpers¶
Sentinel-2 Scene Classification Layer (SCL): what the classes mean.
Every Sentinel-2 L2A scene comes with an extra band, the Scene Classification Layer. For each 20 m pixel it contains one number from 0 to 11 that says what the pixel probably shows (vegetation, water, cloud, …). The Sentinel-2 download functions use it to throw away unusable pixels before they average the scenes of your period:
cdec.download_ndvi(path, area, period, scl_classes=(4, 5))
scl_classes is the list of classes you want to keep. Everything else is
treated as no data. If you want to see which classes exist and what they
mean, run:
import cdec
cdec.show_scl_classes() # the whole table
cdec.show_scl_classes((4, 5)) # the table, with your choice marked
The classification is calculated automatically (by ESA’s Sen2Cor processor) and is not perfect. Thin clouds, haze and cloud edges are sometimes labelled as land, and snow is sometimes labelled as cloud. Look at your result before you trust it.
max_cloud_cover and scl_classes are two different filters:
max_cloud_coverdrops whole scenes that are too cloudy overall.scl_classesdrops single pixels that are cloudy, shadowed, …
- cdec.eo.scl.check_scl_classes(scl_classes)[source]¶
Validate the
scl_classesargument of the Sentinel-2 download functions.Returns
Noneif masking is switched off (scl_classes=None), otherwise the class IDs as a list of plainint. RaisesValueErrorfor an empty selection or for anything that is not an ID fromSCL_CLASSES.The download functions call this before connecting to the backend, so that a typo fails immediately instead of after the login.