Skip to content

Commit 5b2216d

Browse files
authored
Merge branch 'main' into feature/classification-extension
2 parents 4eb17e4 + e196e50 commit 5b2216d

File tree

43 files changed

+208
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+208
-67
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- Make `Link.to_dict()` only contain strings ([#1114](https://github.com/stac-utils/pystac/pull/1114))
2727
- Updated raster extension to work with the item_assets extension's AssetDefinition objects ([#1110](https://github.com/stac-utils/pystac/pull/1110))
2828
- Return all validation errors from validation methods of `JsonSchemaSTACValidator` ([#1120](https://github.com/stac-utils/pystac/pull/1120))
29+
- EO extension updated to v1.1.0 ([#1131](https://github.com/stac-utils/pystac/pull/1131))
2930

3031
### Deprecated
3132

docs/concepts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ extended.
570570
# Add the Electro-Optical extension
571571
EOExtension.add_to(item)
572572
print(item.stac_extensions)
573-
# ['https://stac-extensions.github.io/eo/v1.0.0/schema.json']
573+
# ['https://stac-extensions.github.io/eo/v1.1.0/schema.json']
574574
575575
Extended Summaries
576576
------------------

docs/example-catalog/landsat-8-l1/2018-05/LC80150322018141LGN00.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"id": "LC80150322018141LGN00",
44
"stac_version" : "1.0.0",
55
"stac_extensions" : [
6-
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
6+
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
77
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
88
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
99
],

docs/example-catalog/landsat-8-l1/2018-06/LC80140332018166LGN00.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"id": "LC80140332018166LGN00",
44
"stac_version" : "1.0.0",
55
"stac_extensions" : [
6-
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
6+
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
77
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
88
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
99
],

docs/example-catalog/landsat-8-l1/2018-06/LC80300332018166LGN00.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"type": "Feature",
33
"stac_version" : "1.0.0",
44
"stac_extensions" : [
5-
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
5+
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
66
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
77
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
88
],

docs/example-catalog/landsat-8-l1/2018-07/LC80150332018189LGN00.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"id": "LC80150332018189LGN00",
44
"stac_version" : "1.0.0",
55
"stac_extensions" : [
6-
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
6+
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
77
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
88
"https://stac-extensions.github.io/projection/v1.1.0/schema.json"
99
],

docs/quickstart.ipynb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@
470470
" </summary>\n",
471471
" <table style=\"width: 100%; text-align: left;\">\n",
472472
" \n",
473-
" <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",
473+
" <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",
474474
" \n",
475475
" <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",
476476
" \n",
@@ -1524,7 +1524,7 @@
15241524
{
15251525
"data": {
15261526
"text/plain": [
1527-
"['https://stac-extensions.github.io/eo/v1.0.0/schema.json',\n",
1527+
"['https://stac-extensions.github.io/eo/v1.1.0/schema.json',\n",
15281528
" 'https://stac-extensions.github.io/view/v1.0.0/schema.json',\n",
15291529
" 'https://stac-extensions.github.io/projection/v1.1.0/schema.json']"
15301530
]
@@ -1796,9 +1796,7 @@
17961796
"metadata": {},
17971797
"outputs": [],
17981798
"source": [
1799-
"item_to_update = next(\n",
1800-
" root_catalog.get_items(\"LC80140332018166LGN00\", recursive=True)\n",
1801-
")\n",
1799+
"item_to_update = next(root_catalog.get_items(\"LC80140332018166LGN00\", recursive=True))\n",
18021800
"item_to_update_eo_ext = EOExtension.ext(item_to_update)\n",
18031801
"\n",
18041802
"# Update the cloud cover\n",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ test = [
6161
"pytest-mock~=3.10",
6262
"pytest-vcr~=1.0",
6363
"pytest~=7.3",
64-
"ruff==0.0.269",
64+
"ruff==0.0.270",
6565
"types-html5lib~=1.1",
6666
"types-orjson~=3.6",
6767
"types-python-dateutil~=2.8",

pystac/extensions/eo.py

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,25 @@
2929

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

32-
SCHEMA_URI: str = "https://stac-extensions.github.io/eo/v1.0.0/schema.json"
32+
SCHEMA_URI: str = "https://stac-extensions.github.io/eo/v1.1.0/schema.json"
33+
SCHEMA_URIS: List[str] = [
34+
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
35+
SCHEMA_URI,
36+
]
3337
PREFIX: str = "eo:"
3438

3539
# Field names
3640
BANDS_PROP: str = PREFIX + "bands"
3741
CLOUD_COVER_PROP: str = PREFIX + "cloud_cover"
42+
SNOW_COVER_PROP: str = PREFIX + "snow_cover"
43+
44+
45+
def validated_percentage(v: Optional[float]) -> Optional[float]:
46+
if v is not None and not isinstance(v, (float, int)) or isinstance(v, bool):
47+
raise ValueError(f"Invalid percentage: {v} must be number")
48+
if v is not None and not 0 <= v <= 100:
49+
raise ValueError(f"Invalid percentage: {v} must be between 0 and 100")
50+
return v
3851

3952

4053
class Band:
@@ -296,7 +309,10 @@ class EOExtension(
296309
"""
297310

298311
def apply(
299-
self, bands: Optional[List[Band]] = None, cloud_cover: Optional[float] = None
312+
self,
313+
bands: Optional[List[Band]] = None,
314+
cloud_cover: Optional[float] = None,
315+
snow_cover: Optional[float] = None,
300316
) -> None:
301317
"""Applies Electro-Optical Extension properties to the extended
302318
:class:`~pystac.Item` or :class:`~pystac.Asset`.
@@ -307,9 +323,13 @@ def apply(
307323
cloud_cover : The estimate of cloud cover as a percentage
308324
(0-100) of the entire scene. If not available the field should not
309325
be provided.
326+
snow_cover : The estimate of snow cover as a percentage
327+
(0-100) of the entire scene. If not available the field should not
328+
be provided.
310329
"""
311330
self.bands = bands
312-
self.cloud_cover = cloud_cover
331+
self.cloud_cover = validated_percentage(cloud_cover)
332+
self.snow_cover = validated_percentage(snow_cover)
313333

314334
@property
315335
def bands(self) -> Optional[List[Band]]:
@@ -343,12 +363,30 @@ def cloud_cover(self) -> Optional[float]:
343363

344364
@cloud_cover.setter
345365
def cloud_cover(self, v: Optional[float]) -> None:
346-
self._set_property(CLOUD_COVER_PROP, v)
366+
self._set_property(CLOUD_COVER_PROP, validated_percentage(v), pop_if_none=True)
367+
368+
@property
369+
def snow_cover(self) -> Optional[float]:
370+
"""Get or sets the estimate of snow cover as a percentage
371+
(0-100) of the entire scene. If not available the field should not be provided.
372+
373+
Returns:
374+
float or None
375+
"""
376+
return self._get_property(SNOW_COVER_PROP, float)
377+
378+
@snow_cover.setter
379+
def snow_cover(self, v: Optional[float]) -> None:
380+
self._set_property(SNOW_COVER_PROP, validated_percentage(v), pop_if_none=True)
347381

348382
@classmethod
349383
def get_schema_uri(cls) -> str:
350384
return SCHEMA_URI
351385

386+
@classmethod
387+
def get_schema_uris(cls) -> List[str]:
388+
return SCHEMA_URIS
389+
352390
@classmethod
353391
def ext(cls, obj: T, add_if_missing: bool = False) -> EOExtension[T]:
354392
"""Extends the given STAC Object with properties from the
@@ -496,10 +534,24 @@ def cloud_cover(self) -> Optional[RangeSummary[float]]:
496534
def cloud_cover(self, v: Optional[RangeSummary[float]]) -> None:
497535
self._set_summary(CLOUD_COVER_PROP, v)
498536

537+
@property
538+
def snow_cover(self) -> Optional[RangeSummary[float]]:
539+
"""Get or sets the summary of :attr:`EOExtension.snow_cover` values
540+
for this Collection.
541+
"""
542+
return self.summaries.get_range(SNOW_COVER_PROP)
543+
544+
@snow_cover.setter
545+
def snow_cover(self, v: Optional[RangeSummary[float]]) -> None:
546+
self._set_summary(SNOW_COVER_PROP, v)
547+
499548

500549
class EOExtensionHooks(ExtensionHooks):
501550
schema_uri: str = SCHEMA_URI
502-
prev_extension_ids = {"eo"}
551+
prev_extension_ids = {
552+
"eo",
553+
*[uri for uri in SCHEMA_URIS if uri != SCHEMA_URI],
554+
}
503555
stac_object_types = {pystac.STACObjectType.ITEM}
504556

505557
def migrate(

tests/data-files/catalogs/cbers-partial/CBERS4AWFI/collection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"stac_extensions": [
19-
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
19+
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
2020
"https://schemas.stacspec.org/v1.0.0-beta.2/extensions/item-assets/json-schema/schema.json"
2121
],
2222
"providers": [

0 commit comments

Comments
 (0)