Skip to content

Commit

Permalink
Add classification:classes to SCL asset stactools-packages#165
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed May 28, 2024
1 parent 1177bb2 commit 3b2b63d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,57 @@
{
"nodata": 0,
"data_type": "uint8",
"spatial_resolution": 20
"spatial_resolution": 20,
"classification:classes": [
{
"value": 0,
"description": "no_data"
},
{
"value": 1,
"description": "saturated_or_defective"
},
{
"value": 2,
"description": "dark_area_pixels"
},
{
"value": 3,
"description": "cloud_shadows"
},
{
"value": 4,
"description": "vegetation"
},
{
"value": 5,
"description": "not_vegetated"
},
{
"value": 6,
"description": "water"
},
{
"value": 7,
"description": "unclassified"
},
{
"value": 8,
"description": "cloud_medium_probability"
},
{
"value": 9,
"description": "cloud_high_probability"
},
{
"value": 10,
"description": "thin_cirrus"
},
{
"value": 11,
"description": "snow"
}
]
}
],
"roles": [
Expand Down Expand Up @@ -1733,7 +1783,8 @@
"https://stac-extensions.github.io/mgrs/v1.0.0/schema.json",
"https://stac-extensions.github.io/grid/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json",
"https://stac-extensions.github.io/classification/v1.1.0/schema.json"
],
"collection": "sentinel2-l2a-example"
}
27 changes: 21 additions & 6 deletions src/stactools/sentinel2/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 3b2b63d

Please sign in to comment.