Skip to content

Commit

Permalink
Merge pull request #131 from stactools-packages/issue/130-id
Browse files Browse the repository at this point in the history
Update STAC Item ID
  • Loading branch information
matthewhanson authored Nov 13, 2023
2 parents 274b339 + 6e6e48e commit a1744b1
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 43 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Populate `created` property with a valid RFC 3339 datetime ([#125](https://github.com/stactools-packages/sentinel2/pull/125))
- stactools required version should be >=0.5.2 instead of >= 0.4.8 ([#125](https://github.com/stactools-packages/sentinel2/pull/125))

### Changed

- The convention for naming the STAC Items has changed. ([#131](https://github.com/stactools-packages/sentinel2/pull/131)). A full explanation given in [Issue #130](https://github.com/stactools-packages/sentinel2/issues/130)

## [0.4.2] - 2023-07-03

## Fixed
Expand Down
15 changes: 9 additions & 6 deletions src/stactools/sentinel2/product_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,18 @@ def scene_id(self) -> str:
"naming convention, including "
"ending in .SAFE"
)
# product_id: S2A_MSIL2A_20230419T153551_N0509_R111_T19TDJ_20230419T220859.SAFE
id_parts = self.product_id.split("_")
sensor_id = id_parts[0]
tile_id = id_parts[5].lstrip("T")

# Remove .SAFE
id_parts[-1] = id_parts[-1].replace(".SAFE", "")
# get datastrip sensing time to use as datetime
# datastrip_id: S2A_OPER_MSI_L2A_DS_2APS_20230419T220859_S20230419T153818_N05.09
datastrip_id = self.metadata_dict["s2:datastrip_id"].split("_")
dt = datastrip_id[-2].lstrip("S")
processing_level = datastrip_id[3]

# Remove PDGS Processing Baseline number
id_parts = [part for part in id_parts if not part.startswith("N")]

return "_".join(id_parts)
return f"{sensor_id}_T{tile_id}_{dt}_{processing_level}"

@property
def product_id(self) -> str:
Expand Down
4 changes: 3 additions & 1 deletion src/stactools/sentinel2/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ def metadata_from_granule_metadata(
metadata_dict.update(**product_metadata.metadata_dict)

return Metadata(
scene_id=granule_metadata.scene_id,
scene_id=granule_metadata.scene_id
if product_metadata is None
else product_metadata.scene_id,
extra_assets=extra_assets,
metadata_dict=metadata_dict,
cloudiness_percentage=granule_metadata.cloudiness_percentage,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2A_MSIL1C_20200717T221941_R029_T01LAC_20200717T234135",
"id": "S2A_T01LAC_20200717T221944_L1C",
"properties": {
"created": "2023-11-10T20:34:27.299954Z",
"created": "2023-11-11T00:05:39.027393Z",
"providers": [
{
"name": "ESA",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2A_MSIL1C_20210908T042701_R133_T46RER_20210908T070248",
"id": "S2A_T46RER_20210908T043714_L1C",
"properties": {
"created": "2023-11-10T20:34:27.102000Z",
"created": "2023-11-11T00:05:38.825484Z",
"providers": [
{
"name": "ESA",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2A_MSIL2A_20190212T192651_R013_T07HFE_20201007T160857",
"id": "S2A_T07HFE_20190212T192646_L2A",
"properties": {
"created": "2023-11-10T20:34:27.036383Z",
"created": "2023-11-11T00:05:38.760027Z",
"providers": [
{
"name": "ESA",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2A_MSIL2A_20230625T234621_R073_T01WCP_20230626T022157",
"id": "S2A_T01WCP_20230625T234624_L2A",
"properties": {
"created": "2023-11-10T20:34:26.868142Z",
"created": "2023-11-11T00:05:38.603440Z",
"providers": [
{
"name": "ESA",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2A_MSIL2A_20230625T234621_R073_T01WCP_20230626T022158",
"id": "S2A_T01WCP_20230625T234624_L2A",
"properties": {
"created": "2023-11-10T20:34:27.125956Z",
"created": "2023-11-11T00:05:38.849063Z",
"providers": [
{
"name": "ESA",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2A_MSIL2A_20230625T234621_R073_T01WCS_20230626T022157",
"id": "S2A_T01WCS_20230625T234624_L2A",
"properties": {
"created": "2023-11-10T20:34:27.199678Z",
"created": "2023-11-11T00:05:38.924283Z",
"providers": [
{
"name": "ESA",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2A_MSIL2A_20230821T221941_R029_T01KAB_20230822T021825",
"id": "S2A_T01KAB_20230821T221944_L2A",
"properties": {
"created": "2023-11-10T20:34:26.967480Z",
"created": "2023-11-11T00:05:38.690250Z",
"providers": [
{
"name": "ESA",
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_OPER_MSI_L1C_TL_SGS__20181231T203637_A018414_T10SDG",
"properties": {
"created": "2023-11-10T20:34:27.334360Z",
"created": "2023-11-11T00:05:39.060976Z",
"providers": [
{
"name": "ESA",
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_OPER_MSI_L2A_TL_SGS__20181231T210250_A018414_T10SDG",
"properties": {
"created": "2023-11-10T20:34:27.168377Z",
"created": "2023-11-11T00:05:38.892827Z",
"providers": [
{
"name": "ESA",
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_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBP",
"properties": {
"created": "2023-11-10T20:34:26.297068Z",
"created": "2023-11-11T00:05:38.178793Z",
"providers": [
{
"name": "ESA",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBQ",
"id": "S2A_T34LBQ_20220401T090142_L2A",
"properties": {
"created": "2023-11-10T20:34:27.005228Z",
"created": "2023-11-11T00:05:38.728486Z",
"providers": [
{
"name": "ESA",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2B_MSIL2A_20191228T210519_R071_T01CCV_20201003T104658",
"id": "S2B_T01CCV_20191228T210521_L2A",
"properties": {
"created": "2023-11-10T20:34:27.068980Z",
"created": "2023-11-11T00:05:38.792523Z",
"providers": [
{
"name": "ESA",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2B_MSIL2A_20220413T150759_R025_T33XWJ_20220414T082126",
"id": "S2B_T33XWJ_20220413T150756_L2A",
"properties": {
"created": "2023-11-10T20:34:27.233166Z",
"created": "2023-11-11T00:05:38.958753Z",
"providers": [
{
"name": "ESA",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "S2B_MSIL2A_20210122T133229_R081_T22HBD_20210122T155500",
"id": "S2B_T22HBD_20210122T133224_L2A",
"properties": {
"created": "2023-11-10T20:34:27.266721Z",
"created": "2023-11-11T00:05:38.992841Z",
"providers": [
{
"name": "ESA",
Expand Down
22 changes: 11 additions & 11 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@
"swir22": [20, 60],
}
ID_TO_FILE_NAME = {
"S2A_MSIL1C_20210908T042701_R133_T46RER_20210908T070248": "S2A_MSIL1C_20210908T042701_N0301_R133_T46RER_20210908T070248.SAFE",
"S2A_MSIL2A_20190212T192651_R013_T07HFE_20201007T160857": "S2A_MSIL2A_20190212T192651_N0212_R013_T07HFE_20201007T160857.SAFE",
"S2B_MSIL2A_20191228T210519_R071_T01CCV_20201003T104658": "S2B_MSIL2A_20191228T210519_N0212_R071_T01CCV_20201003T104658.SAFE",
"S2B_MSIL2A_20210122T133229_R081_T22HBD_20210122T155500": "esa_S2B_MSIL2A_20210122T133229_N0214_R081_T22HBD_20210122T155500.SAFE",
"S2B_MSIL2A_20220413T150759_R025_T33XWJ_20220414T082126": "S2B_MSIL2A_20220413T150759_N0400_R025_T33XWJ_20220414T082126.SAFE",
"S2A_T46RER_20210908T043714_L1C": "S2A_MSIL1C_20210908T042701_N0301_R133_T46RER_20210908T070248.SAFE",
"S2A_T07HFE_20190212T192646_L2A": "S2A_MSIL2A_20190212T192651_N0212_R013_T07HFE_20201007T160857.SAFE",
"S2B_T01CCV_20191228T210521_L2A": "S2B_MSIL2A_20191228T210519_N0212_R071_T01CCV_20201003T104658.SAFE",
"S2B_T22HBD_20210122T133224_L2A": "esa_S2B_MSIL2A_20210122T133229_N0214_R081_T22HBD_20210122T155500.SAFE",
"S2B_T33XWJ_20220413T150756_L2A": "S2B_MSIL2A_20220413T150759_N0400_R025_T33XWJ_20220414T082126.SAFE",
"S2A_OPER_MSI_L2A_TL_SGS__20181231T210250_A018414_T10SDG": "S2A_OPER_MSI_L2A_TL_SGS__20181231T210250_A018414_T10SDG",
"S2A_OPER_MSI_L1C_TL_SGS__20181231T203637_A018414_T10SDG": "S2A_OPER_MSI_L1C_TL_SGS__20181231T203637_A018414_T10SDG",
"S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBP": "S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBP",
"S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBQ": "S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBQ",
"S2A_T34LBQ_20220401T090142_L2A": "S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBQ",
# antimeridian-crossing scene
"S2A_MSIL1C_20200717T221941_R029_T01LAC_20200717T234135": "S2A_MSIL1C_20200717T221941_R029_T01LAC_20200717T234135.SAFE",
"S2A_T01LAC_20200717T221944_L1C": "S2A_MSIL1C_20200717T221941_R029_T01LAC_20200717T234135.SAFE",
# antimeridian-crossing scene with positive lon centroid
"S2A_MSIL2A_20230625T234621_R073_T01WCP_20230626T022157": "S2A_MSIL2A_20230625T234621_N0509_R073_T01WCP_20230626T022157.SAFE",
"S2A_T01WCP_20230625T234624_L2A": "S2A_MSIL2A_20230625T234621_N0509_R073_T01WCP_20230626T022157.SAFE",
# antimeridian-crossing scene with negative lon centroid
"S2A_MSIL2A_20230625T234621_R073_T01WCS_20230626T022157": "S2A_MSIL2A_20230625T234621_N0509_R073_T01WCS_20230626T022157.SAFE",
"S2A_T01WCS_20230625T234624_L2A": "S2A_MSIL2A_20230625T234621_N0509_R073_T01WCS_20230626T022157.SAFE",
# both sun_azimuth and sun_zenith can be NaN, so don't set
"S2A_MSIL2A_20230625T234621_R073_T01WCP_20230626T022158": "S2A_MSIL2A_20230625T234621_N0509_R073_T01WCP_20230626T022158.SAFE",
# "S2A_T01WCP_20230625T234624_L2A": "S2A_MSIL2A_20230625T234621_N0509_R073_T01WCP_20230626T022158.SAFE",
}


Expand Down Expand Up @@ -234,7 +234,7 @@ def mk_comparable(i: pystac.Item) -> Dict[str, Any]:
except pystac.errors.ExtensionNotImplemented as e:
# this item is the example that doesn't have the View Extension
# applied because the values are NaN
if item_id != "S2A_MSIL2A_20230625T234621_R073_T01WCP_20230626T022158":
if item_id != "S2A_T01WCP_20230625T234624_L2A":
raise e

proj = ProjectionExtension.ext(item)
Expand Down

0 comments on commit a1744b1

Please sign in to comment.