Skip to content

Commit

Permalink
Merge branch 'main' into feature/classification-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski authored May 25, 2023
2 parents 4eb17e4 + e196e50 commit 5b2216d
Show file tree
Hide file tree
Showing 43 changed files with 208 additions and 67 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- Make `Link.to_dict()` only contain strings ([#1114](https://github.com/stac-utils/pystac/pull/1114))
- Updated raster extension to work with the item_assets extension's AssetDefinition objects ([#1110](https://github.com/stac-utils/pystac/pull/1110))
- Return all validation errors from validation methods of `JsonSchemaSTACValidator` ([#1120](https://github.com/stac-utils/pystac/pull/1120))
- EO extension updated to v1.1.0 ([#1131](https://github.com/stac-utils/pystac/pull/1131))

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion docs/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ extended.
# Add the Electro-Optical extension
EOExtension.add_to(item)
print(item.stac_extensions)
# ['https://stac-extensions.github.io/eo/v1.0.0/schema.json']
# ['https://stac-extensions.github.io/eo/v1.1.0/schema.json']
Extended Summaries
------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "LC80150322018141LGN00",
"stac_version" : "1.0.0",
"stac_extensions" : [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "LC80140332018166LGN00",
"stac_version" : "1.0.0",
"stac_extensions" : [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "Feature",
"stac_version" : "1.0.0",
"stac_extensions" : [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "LC80150332018189LGN00",
"stac_version" : "1.0.0",
"stac_extensions" : [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
],
Expand Down
8 changes: 3 additions & 5 deletions docs/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
" </summary>\n",
" <table style=\"width: 100%; text-align: left;\">\n",
" \n",
" <tr><td style=\"text-align: left;\"><a href=\"https://stac-extensions.github.io/eo/v1.0.0/schema.json\">https://stac-extensions.github.io/eo/v1.0.0/schema.json</a></td></tr>\n",
" <tr><td style=\"text-align: left;\"><a href=\"https://stac-extensions.github.io/eo/v1.1.0/schema.json\">https://stac-extensions.github.io/eo/v1.1.0/schema.json</a></td></tr>\n",
" \n",
" <tr><td style=\"text-align: left;\"><a href=\"https://stac-extensions.github.io/view/v1.0.0/schema.json\">https://stac-extensions.github.io/view/v1.0.0/schema.json</a></td></tr>\n",
" \n",
Expand Down Expand Up @@ -1524,7 +1524,7 @@
{
"data": {
"text/plain": [
"['https://stac-extensions.github.io/eo/v1.0.0/schema.json',\n",
"['https://stac-extensions.github.io/eo/v1.1.0/schema.json',\n",
" 'https://stac-extensions.github.io/view/v1.0.0/schema.json',\n",
" 'https://stac-extensions.github.io/projection/v1.1.0/schema.json']"
]
Expand Down Expand Up @@ -1796,9 +1796,7 @@
"metadata": {},
"outputs": [],
"source": [
"item_to_update = next(\n",
" root_catalog.get_items(\"LC80140332018166LGN00\", recursive=True)\n",
")\n",
"item_to_update = next(root_catalog.get_items(\"LC80140332018166LGN00\", recursive=True))\n",
"item_to_update_eo_ext = EOExtension.ext(item_to_update)\n",
"\n",
"# Update the cloud cover\n",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test = [
"pytest-mock~=3.10",
"pytest-vcr~=1.0",
"pytest~=7.3",
"ruff==0.0.269",
"ruff==0.0.270",
"types-html5lib~=1.1",
"types-orjson~=3.6",
"types-python-dateutil~=2.8",
Expand Down
62 changes: 57 additions & 5 deletions pystac/extensions/eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,25 @@

T = TypeVar("T", pystac.Item, pystac.Asset)

SCHEMA_URI: str = "https://stac-extensions.github.io/eo/v1.0.0/schema.json"
SCHEMA_URI: str = "https://stac-extensions.github.io/eo/v1.1.0/schema.json"
SCHEMA_URIS: List[str] = [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
SCHEMA_URI,
]
PREFIX: str = "eo:"

# Field names
BANDS_PROP: str = PREFIX + "bands"
CLOUD_COVER_PROP: str = PREFIX + "cloud_cover"
SNOW_COVER_PROP: str = PREFIX + "snow_cover"


def validated_percentage(v: Optional[float]) -> Optional[float]:
if v is not None and not isinstance(v, (float, int)) or isinstance(v, bool):
raise ValueError(f"Invalid percentage: {v} must be number")
if v is not None and not 0 <= v <= 100:
raise ValueError(f"Invalid percentage: {v} must be between 0 and 100")
return v


class Band:
Expand Down Expand Up @@ -296,7 +309,10 @@ class EOExtension(
"""

def apply(
self, bands: Optional[List[Band]] = None, cloud_cover: Optional[float] = None
self,
bands: Optional[List[Band]] = None,
cloud_cover: Optional[float] = None,
snow_cover: Optional[float] = None,
) -> None:
"""Applies Electro-Optical Extension properties to the extended
:class:`~pystac.Item` or :class:`~pystac.Asset`.
Expand All @@ -307,9 +323,13 @@ def apply(
cloud_cover : The estimate of cloud cover as a percentage
(0-100) of the entire scene. If not available the field should not
be provided.
snow_cover : The estimate of snow cover as a percentage
(0-100) of the entire scene. If not available the field should not
be provided.
"""
self.bands = bands
self.cloud_cover = cloud_cover
self.cloud_cover = validated_percentage(cloud_cover)
self.snow_cover = validated_percentage(snow_cover)

@property
def bands(self) -> Optional[List[Band]]:
Expand Down Expand Up @@ -343,12 +363,30 @@ def cloud_cover(self) -> Optional[float]:

@cloud_cover.setter
def cloud_cover(self, v: Optional[float]) -> None:
self._set_property(CLOUD_COVER_PROP, v)
self._set_property(CLOUD_COVER_PROP, validated_percentage(v), pop_if_none=True)

@property
def snow_cover(self) -> Optional[float]:
"""Get or sets the estimate of snow cover as a percentage
(0-100) of the entire scene. If not available the field should not be provided.
Returns:
float or None
"""
return self._get_property(SNOW_COVER_PROP, float)

@snow_cover.setter
def snow_cover(self, v: Optional[float]) -> None:
self._set_property(SNOW_COVER_PROP, validated_percentage(v), pop_if_none=True)

@classmethod
def get_schema_uri(cls) -> str:
return SCHEMA_URI

@classmethod
def get_schema_uris(cls) -> List[str]:
return SCHEMA_URIS

@classmethod
def ext(cls, obj: T, add_if_missing: bool = False) -> EOExtension[T]:
"""Extends the given STAC Object with properties from the
Expand Down Expand Up @@ -496,10 +534,24 @@ def cloud_cover(self) -> Optional[RangeSummary[float]]:
def cloud_cover(self, v: Optional[RangeSummary[float]]) -> None:
self._set_summary(CLOUD_COVER_PROP, v)

@property
def snow_cover(self) -> Optional[RangeSummary[float]]:
"""Get or sets the summary of :attr:`EOExtension.snow_cover` values
for this Collection.
"""
return self.summaries.get_range(SNOW_COVER_PROP)

@snow_cover.setter
def snow_cover(self, v: Optional[RangeSummary[float]]) -> None:
self._set_summary(SNOW_COVER_PROP, v)


class EOExtensionHooks(ExtensionHooks):
schema_uri: str = SCHEMA_URI
prev_extension_ids = {"eo"}
prev_extension_ids = {
"eo",
*[uri for uri in SCHEMA_URIS if uri != SCHEMA_URI],
}
stac_object_types = {pystac.STACObjectType.ITEM}

def migrate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://schemas.stacspec.org/v1.0.0-beta.2/extensions/item-assets/json-schema/schema.json"
],
"providers": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"
],
"providers": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"
],
"providers": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"
],
"providers": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "planet-disaster-data",
"stac_version": "1.0.0-beta.2",
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
"description": "[Planet Disaster Data](https://www.planet.com/disasterdata/) makes imagery available directly to the public, volunteers, humanitarian organizations, and other coordinating bodies in support of the International Charter for Space and Major Disasters. Data is released for individual disaster events, providing a 30 day window pre- and post-disaster. Imagery is provided under Creative Commons licenses, free of charge, with either CC-BY-SA or CC-BY-NC.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
29.064872627755797
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
"collection": "planet-disaster-data"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
29.62330817060518
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
30.052156732418428
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
"collection": "planet-disaster-data"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
29.834836581964858
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
"collection": "planet-disaster-data"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
30.157560439570304
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
28.3637
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json"
"https://stac-extensions.github.io/eo/v1.1.0/schema.json"
],
"providers": [
{
Expand Down
6 changes: 5 additions & 1 deletion tests/data-files/eo/eo-collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json"
"https://stac-extensions.github.io/eo/v1.1.0/schema.json"
],
"title": "Landsat 8 L1",
"keywords": [
Expand Down Expand Up @@ -128,6 +128,10 @@
"eo:cloud_cover": {
"minimum": 0.0,
"maximum": 80.0
},
"eo:snow_cover": {
"minimum": 0.0,
"maximum": 80.0
}
},
"extent": {
Expand Down
5 changes: 3 additions & 2 deletions tests/data-files/eo/eo-landsat-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"view:off_nadir": 0,
"landsat:path": 107,
"landsat:row": 18,
"eo:cloud_cover": 78
"eo:cloud_cover": 78,
"eo:snow_cover": 44.5
},
"geometry": {
"type": "Polygon",
Expand Down Expand Up @@ -229,7 +230,7 @@
60.63437
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
"collection": "landsat-8-l1"
Expand Down
2 changes: 1 addition & 1 deletion tests/data-files/eo/eo-sentinel2-item.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"stac_version": "1.0.0",
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/processing/v1.0.0/schema.json",
"https://stac-extensions.github.io/raster/v1.0.0/schema.json",
"https://stac-extensions.github.io/sat/v1.0.0/schema.json",
Expand Down
2 changes: 1 addition & 1 deletion tests/data-files/eo/sample-bands-in-item-properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
37.613537207
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
"collection": "CS3"
Expand Down
3 changes: 1 addition & 2 deletions tests/data-files/examples/1.0.0-RC2/extended-item.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"stac_version": "1.0.0-rc.2",
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
Expand Down Expand Up @@ -189,4 +189,3 @@
}
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"stac_version": "1.0.0",
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/sat/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
],
Expand Down
Loading

0 comments on commit 5b2216d

Please sign in to comment.