Skip to content

Commit

Permalink
Add eo:snow_cover #164
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed May 28, 2024
1 parent 1177bb2 commit 08a2715
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"msi"
],
"eo:cloud_cover": 51.580326,
"eo:snow_cover": 0.0,
"sat:orbit_state": "descending",
"sat:relative_orbit": 13,
"proj:epsg": 32707,
Expand Down
7 changes: 7 additions & 0 deletions src/stactools/sentinel2/granule_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def cloudiness_percentage(self) -> float | None:
self._image_content_node.find_text("CLOUDY_PIXEL_PERCENTAGE"),
)

@property
def snow_ice_percentage(self) -> float | None:
return map_opt(
float,
self._image_content_node.find_text("SNOW_ICE_PERCENTAGE"),
)

@property
def mean_solar_zenith(self) -> float | None:
return map_opt(
Expand Down
4 changes: 4 additions & 0 deletions src/stactools/sentinel2/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
class Metadata:
scene_id: str
cloudiness_percentage: Optional[float]
snow_ice_percentage: Optional[float]
extra_assets: dict[str, pystac.Asset]
geometry: dict[str, Any]
datetime: datetime
Expand Down Expand Up @@ -170,6 +171,7 @@ def create_item(
# Electro-Optical Extension
eo = EOExtension.ext(item, add_if_missing=True)
eo.cloud_cover = metadata.cloudiness_percentage
eo.snow_cover = metadata.snow_ice_percentage
RasterExtension.add_to(item)

# Satellite Extension
Expand Down Expand Up @@ -588,6 +590,7 @@ def metadata_from_safe_manifest(
image_media_type=product_metadata.image_media_type,
image_paths=product_metadata.image_paths,
cloudiness_percentage=granule_metadata.cloudiness_percentage,
snow_ice_percentage=granule_metadata.cloudiness_percentage,
epsg=granule_metadata.epsg,
proj_bbox=[round(v, COORD_ROUNDING) for v in granule_metadata.proj_bbox],
resolution_to_shape=granule_metadata.resolution_to_shape,
Expand Down Expand Up @@ -669,6 +672,7 @@ def metadata_from_granule_metadata(
extra_assets=extra_assets,
metadata_dict=metadata_dict,
cloudiness_percentage=granule_metadata.cloudiness_percentage,
snow_ice_percentage=granule_metadata.snow_ice_percentage,
epsg=granule_metadata.epsg,
proj_bbox=granule_metadata.proj_bbox,
resolution_to_shape=granule_metadata.resolution_to_shape,
Expand Down
1 change: 1 addition & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_parses_product_metadata_properties(self):
self.assertEqual(s2_props[k], v)

self.assertEqual(granule_metadata.cloudiness_percentage, 51.580326)
self.assertEqual(granule_metadata.snow_ice_percentage, 0.0)
self.assertEqual(
granule_metadata.processing_baseline,
s2_props[f"{s2_prefix}:processing_baseline"],
Expand Down

0 comments on commit 08a2715

Please sign in to comment.