From 3e3c302e3ea9d5593d82ae7f437145dc2814740f Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Tue, 28 May 2024 17:58:53 +0200 Subject: [PATCH] Add classification:classes to SCL asset #165 --- CHANGELOG.MD | 6 ++++++ src/stactools/sentinel2/stac.py | 27 +++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index fb7fa04..ccd8511 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project attempts to match the major and minor versions of [stactools](https://github.com/stac-utils/stactools) and increments the patch number as needed. +## [Unreleased] + +### Added + +- Added a `classification:classes` field to the `scl` asset (SCL). + ## [0.6.4] - 2024-04-04 ### Added diff --git a/src/stactools/sentinel2/stac.py b/src/stactools/sentinel2/stac.py index 0d94262..5028127 100644 --- a/src/stactools/sentinel2/stac.py +++ b/src/stactools/sentinel2/stac.py @@ -11,6 +11,7 @@ import antimeridian import pystac +from pystac.extensions.classification import Classification, ClassificationExtension from pystac.extensions.eo import Band, EOExtension from pystac.extensions.grid import GridExtension from pystac.extensions.projection import ProjectionExtension @@ -465,12 +466,26 @@ def set_asset_properties(_asset: pystac.Asset, _band_gsd: Optional[int] = None): asset_id = mk_asset_id(maybe_res, "scl") set_asset_properties(asset, maybe_res) - RasterExtension.ext(asset).bands = [ - RasterBand.create( - nodata=0, - spatial_resolution=resolution, - data_type=DataType.UINT8, - ) + band = RasterBand.create( + nodata=0, + spatial_resolution=resolution, + data_type=DataType.UINT8, + ) + RasterExtension.ext(asset).bands = [band] + + ClassificationExtension.ext(band).classes = [ + Classification.create(0, "no_data"), + Classification.create(1, "saturated_or_defective"), + Classification.create(2, "dark_area_pixels"), + Classification.create(3, "cloud_shadows"), + Classification.create(4, "vegetation"), + Classification.create(5, "not_vegetated"), + Classification.create(6, "water"), + Classification.create(7, "unclassified"), + Classification.create(8, "cloud_medium_probability"), + Classification.create(9, "cloud_high_probability"), + Classification.create(10, "thin_cirrus"), + Classification.create(11, "snow"), ] elif CLD_PATTERN.search(asset_href):