Skip to content

Commit

Permalink
update to support sentinel-2 extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Varner committed Nov 13, 2023
1 parent a9c8894 commit e45c0fc
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2A_20200717T221941_026481_N02.09",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2A_OPER_MSI_L1C_DS_SGS__20200717T234135_S20200717T221944_N02.09",
"s2:granule_id": "S2A_OPER_MSI_L1C_TL_SGS__20200717T234135_A026481_T01LAC_N02.09",
"s2:mgrs_tile": "01LAC",
"s2:tile_id": "S2A_OPER_MSI_L1C_TL_SGS__20200717T234135_A026481_T01LAC_N02.09",
"s2:reflectance_conversion_factor": 0.967801407960869,
"s2:degraded_msi_data_percentage": 0.0,
"datetime": "2020-07-17T22:19:41.024000Z"
Expand Down Expand Up @@ -872,7 +871,8 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
],
"collection": "sentinel2-l1c-example"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2A_20190212T192651_019029_N02.12",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2A_OPER_MSI_L2A_DS_ESRI_20201007T160858_S20190212T192646_N02.12",
"s2:granule_id": "S2A_OPER_MSI_L2A_TL_ESRI_20201007T160858_A019029_T07HFE_N02.12",
"s2:mgrs_tile": "07HFE",
"s2:tile_id": "S2A_OPER_MSI_L2A_TL_ESRI_20201007T160858_A019029_T07HFE_N02.12",
"s2:reflectance_conversion_factor": 1.02763689829235,
"s2:degraded_msi_data_percentage": 0.0,
"s2:nodata_pixel_percentage": 96.769553,
Expand Down Expand Up @@ -1788,7 +1787,8 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
],
"collection": "sentinel2-l2a-example"
}
2 changes: 1 addition & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
docs/*.rst docs/**/*.rst \
docs/*.ipynb docs/**/*.ipynb

pytest --cov=stactools tests/
pytest --cov=stactools -vvv tests/
coverage xml
fi
fi
1 change: 1 addition & 0 deletions src/stactools/sentinel2/granule_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def mean_solar_azimuth(self) -> Optional[float]:
@property
def metadata_dict(self):
properties: Dict[str, Optional[float]] = {
f"{s2_prefix}:tile_id": self.tile_id,
f"{s2_prefix}:product_type": map_opt(
float, self._image_content_node.find_text("PRODUCT_TYPE")
),
Expand Down
2 changes: 1 addition & 1 deletion src/stactools/sentinel2/mgrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def ext(cls, obj: pystac.Item, add_if_missing: bool = False) -> "MgrsExtension":
pystac.ExtensionTypeError : If an invalid object type is passed.
"""
if isinstance(obj, pystac.Item):
cls.validate_has_extension(obj, add_if_missing)
cls.ensure_has_extension(obj, add_if_missing)
return cast(MgrsExtension, MgrsExtension(obj))
else:
raise pystac.ExtensionTypeError(
Expand Down
9 changes: 1 addition & 8 deletions src/stactools/sentinel2/product_metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import re
from datetime import datetime
from typing import Any, Dict, List, Optional

Expand Down Expand Up @@ -180,11 +179,6 @@ def orbit_state(self) -> Optional[str]:
def platform(self) -> Optional[str]:
return self.datatake_node.find_text("SPACECRAFT_NAME")

@property
def mgrs_tile(self) -> Optional[str]:
m = re.search(r"_T(\d{2}[a-zA-Z]{3})_", self.href)
return None if m is None else m.group(1)

@property
def metadata_dict(self) -> Dict[str, Any]:
result = {
Expand All @@ -205,8 +199,7 @@ def metadata_dict(self) -> Dict[str, Any]:
f"{s2_prefix}:datastrip_id": self.granule_node.get_attr(
"datastripIdentifier"
),
f"{s2_prefix}:granule_id": self.granule_node.get_attr("granuleIdentifier"),
f"{s2_prefix}:mgrs_tile": self.mgrs_tile,
f"{s2_prefix}:tile_id": self.granule_node.get_attr("granuleIdentifier"),
f"{s2_prefix}:reflectance_conversion_factor": map_opt(
float, self.reflectance_conversion_node.find_text("U")
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2A_20200717T221941_026481_N02.09",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2A_OPER_MSI_L1C_DS_SGS__20200717T234135_S20200717T221944_N02.09",
"s2:granule_id": "S2A_OPER_MSI_L1C_TL_SGS__20200717T234135_A026481_T01LAC_N02.09",
"s2:mgrs_tile": "01LAC",
"s2:tile_id": "S2A_OPER_MSI_L1C_TL_SGS__20200717T234135_A026481_T01LAC_N02.09",
"s2:reflectance_conversion_factor": 0.967801407960869,
"s2:degraded_msi_data_percentage": 0.0,
"datetime": "2020-07-17T22:19:41.024000Z"
Expand Down Expand Up @@ -857,6 +856,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2A_20210908T042701_032448_N03.01",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2A_OPER_MSI_L1C_DS_VGS4_20210908T070248_S20210908T043714_N03.01",
"s2:granule_id": "S2A_OPER_MSI_L1C_TL_VGS4_20210908T070248_A032448_T46RER_N03.01",
"s2:mgrs_tile": "46RER",
"s2:tile_id": "S2A_OPER_MSI_L1C_TL_VGS4_20210908T070248_A032448_T46RER_N03.01",
"s2:reflectance_conversion_factor": 0.983841990384341,
"s2:degraded_msi_data_percentage": 0.0,
"datetime": "2021-09-08T04:27:01.024000Z"
Expand Down Expand Up @@ -847,6 +846,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2A_20190212T192651_019029_N02.12",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2A_OPER_MSI_L2A_DS_ESRI_20201007T160858_S20190212T192646_N02.12",
"s2:granule_id": "S2A_OPER_MSI_L2A_TL_ESRI_20201007T160858_A019029_T07HFE_N02.12",
"s2:mgrs_tile": "07HFE",
"s2:tile_id": "S2A_OPER_MSI_L2A_TL_ESRI_20201007T160858_A019029_T07HFE_N02.12",
"s2:reflectance_conversion_factor": 1.02763689829235,
"s2:degraded_msi_data_percentage": 0.0,
"s2:nodata_pixel_percentage": 96.769553,
Expand Down Expand Up @@ -1773,6 +1772,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2A_20230625T234621_041826_N05.09",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2A_OPER_MSI_L2A_DS_2APS_20230626T022157_S20230625T234624_N05.09",
"s2:granule_id": "S2A_OPER_MSI_L2A_TL_2APS_20230626T022157_A041826_T01WCP_N05.09",
"s2:mgrs_tile": "01WCP",
"s2:tile_id": "S2A_OPER_MSI_L2A_TL_2APS_20230626T022157_A041826_T01WCP_N05.09",
"s2:reflectance_conversion_factor": 0.96817485048713,
"s2:degraded_msi_data_percentage": 0.0001,
"s2:nodata_pixel_percentage": 7e-06,
Expand Down Expand Up @@ -1835,6 +1834,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
"s2:datatake_id": "GS2A_20230625T234621_041826_N05.09",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2A_OPER_MSI_L2A_DS_2APS_20230626T022158_S20230625T234624_N05.09",
"s2:granule_id": "S2A_OPER_MSI_L2A_TL_2APS_20230626T022158_A041826_T01WCP_N05.09",
"s2:mgrs_tile": "01WCP",
"s2:tile_id": "S2A_OPER_MSI_L2A_TL_2APS_20230626T022158_A041826_T01WCP_N05.09",
"s2:reflectance_conversion_factor": 0.96817485048713,
"s2:degraded_msi_data_percentage": 0.0001,
"s2:nodata_pixel_percentage": 7e-06,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2A_20230625T234621_041826_N05.09",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2A_OPER_MSI_L2A_DS_2APS_20230626T022157_S20230625T234624_N05.09",
"s2:granule_id": "S2A_OPER_MSI_L2A_TL_2APS_20230626T022157_A041826_T01WCS_N05.09",
"s2:mgrs_tile": "01WCS",
"s2:tile_id": "S2A_OPER_MSI_L2A_TL_2APS_20230626T022157_A041826_T01WCS_N05.09",
"s2:reflectance_conversion_factor": 0.96817485048713,
"s2:degraded_msi_data_percentage": 0.0275,
"s2:nodata_pixel_percentage": 56.275433,
Expand Down Expand Up @@ -1863,6 +1862,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2A_20230821T221941_042640_N05.09",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2A_OPER_MSI_L2A_DS_2APS_20230822T021825_S20230821T221944_N05.09",
"s2:granule_id": "S2A_OPER_MSI_L2A_TL_2APS_20230822T021825_A042640_T01KAB_N05.09",
"s2:mgrs_tile": "01KAB",
"s2:tile_id": "S2A_OPER_MSI_L2A_TL_2APS_20230822T021825_A042640_T01KAB_N05.09",
"s2:reflectance_conversion_factor": 0.976023471600241,
"s2:degraded_msi_data_percentage": 0.0012,
"s2:nodata_pixel_percentage": 0.0,
Expand Down Expand Up @@ -1835,6 +1834,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"mgrs:latitude_band": "S",
"mgrs:grid_square": "DG",
"grid:code": "MGRS-10SDG",
"s2:tile_id": "S2A_OPER_MSI_L1C_TL_SGS__20181231T203637_A018414_T10SDG_N02.07",
"view:sun_azimuth": 161.105709274255,
"view:sun_elevation": 27.099070943431997,
"s2:degraded_msi_data_percentage": 0.0,
Expand Down Expand Up @@ -792,6 +793,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"mgrs:latitude_band": "S",
"mgrs:grid_square": "DG",
"grid:code": "MGRS-10SDG",
"s2:tile_id": "S2A_OPER_MSI_L2A_TL_SGS__20181231T210250_A018414_T10SDG_N02.11",
"view:sun_azimuth": 161.105709274255,
"view:sun_elevation": 27.099070943431997,
"s2:degraded_msi_data_percentage": 0.0,
Expand Down Expand Up @@ -1884,6 +1885,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"s2:vegetation_percentage": 0.094889,
"s2:not_vegetated_percentage": 0.001937,
"s2:water_percentage": 0.0,
"s2:tile_id": "S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBP_N04.00",
"s2:unclassified_percentage": 0.093294,
"s2:medium_proba_clouds_percentage": 16.551426,
"s2:high_proba_clouds_percentage": 76.137125,
Expand Down Expand Up @@ -1884,6 +1885,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"s2:datatake_id": "GS2A_20220401T083601_035382_N04.00",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2A_OPER_MSI_L2A_DS_VGS1_20220401T110010_S20220401T090142_N04.00",
"s2:granule_id": "S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBQ_N04.00",
"s2:tile_id": "S2A_OPER_MSI_L2A_TL_VGS1_20220401T110010_A035382_T34LBQ_N04.00",
"s2:reflectance_conversion_factor": 1.00413041106276,
"datetime": "2022-04-01T09:03:19.283000Z"
},
Expand Down Expand Up @@ -1898,6 +1898,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2B_20191228T210519_014683_N02.12",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2B_OPER_MSI_L2A_DS_ESRI_20201003T104659_S20191228T210521_N02.12",
"s2:granule_id": "S2B_OPER_MSI_L2A_TL_ESRI_20201003T104659_A014683_T01CCV_N02.12",
"s2:mgrs_tile": "01CCV",
"s2:tile_id": "S2B_OPER_MSI_L2A_TL_ESRI_20201003T104659_A014683_T01CCV_N02.12",
"s2:reflectance_conversion_factor": 1.03382780603275,
"s2:degraded_msi_data_percentage": 0.0,
"s2:nodata_pixel_percentage": 79.061437,
Expand Down Expand Up @@ -1789,6 +1788,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2B_20220413T150759_026649_N04.00",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2B_OPER_MSI_L2A_DS_ESRI_20220414T082127_S20220413T150756_N04.00",
"s2:granule_id": "S2B_OPER_MSI_L2A_TL_ESRI_20220414T082127_A026649_T33XWJ_N04.00",
"s2:mgrs_tile": "33XWJ",
"s2:tile_id": "S2B_OPER_MSI_L2A_TL_ESRI_20220414T082127_A026649_T33XWJ_N04.00",
"s2:reflectance_conversion_factor": 0.99707551771009,
"s2:degraded_msi_data_percentage": 0.0,
"s2:nodata_pixel_percentage": 98.441625,
Expand Down Expand Up @@ -1809,6 +1808,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"s2:datatake_id": "GS2B_20210122T133229_020270_N02.14",
"s2:datatake_type": "INS-NOBS",
"s2:datastrip_id": "S2B_OPER_MSI_L2A_DS_VGS2_20210122T155500_S20210122T133224_N02.14",
"s2:granule_id": "S2B_OPER_MSI_L2A_TL_VGS2_20210122T155500_A020270_T22HBD_N02.14",
"s2:mgrs_tile": "22HBD",
"s2:tile_id": "S2B_OPER_MSI_L2A_TL_VGS2_20210122T155500_A020270_T22HBD_N02.14",
"s2:reflectance_conversion_factor": 1.03305092950356,
"s2:degraded_msi_data_percentage": 0.0,
"s2:nodata_pixel_percentage": 0.913129,
Expand Down Expand Up @@ -1793,6 +1792,7 @@
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"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/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/sentinel-2/v1.0.0/schema.json"
]
}
3 changes: 1 addition & 2 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ def test_parses_product_metadata_properties(self):
f"{s2_prefix}:datatake_type": "INS-NOBS",
f"{s2_prefix}:datastrip_id":
"S2A_OPER_MSI_L2A_DS_ESRI_20201007T160858_S20190212T192646_N02.12",
f"{s2_prefix}:granule_id":
f"{s2_prefix}:tile_id":
"S2A_OPER_MSI_L2A_TL_ESRI_20201007T160858_A019029_T07HFE_N02.12",
f"{s2_prefix}:mgrs_tile": "07HFE",
f"{s2_prefix}:reflectance_conversion_factor": 1.02763689829235,
# From granule metadata
f"{s2_prefix}:degraded_msi_data_percentage": 0.0,
Expand Down

0 comments on commit e45c0fc

Please sign in to comment.