Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add classification:classes to SCL asset #165 #175

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_T07HFE_20190212T192646_L2A",
"properties": {
"created": "2024-04-03T15:21:15.758770Z",
"created": "2024-05-29T10:51:51.944555Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -543,7 +543,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 @@ -1200,7 +1250,57 @@
{
"nodata": 0,
"data_type": "uint8",
"spatial_resolution": 60
"spatial_resolution": 60,
"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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stac_version": "1.0.0",
"id": "S2A_T01WCP_20230625T234624_L2A",
"properties": {
"created": "2024-04-03T15:21:15.594079Z",
"created": "2024-05-29T10:51:51.984651Z",
"providers": [
{
"name": "ESA",
Expand Down Expand Up @@ -1055,7 +1055,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 @@ -1712,7 +1762,57 @@
{
"nodata": 0,
"data_type": "uint8",
"spatial_resolution": 60
"spatial_resolution": 60,
"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
Loading
Loading