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 eo:snow_cover #164 #177

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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

- Add `eo:snow_cover` for L2A

## [0.6.4] - 2024-04-04

### Added
Expand Down
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
Loading