Skip to content

Commit 4416a09

Browse files
committed
feat: SummariesProcessingExtension
1 parent 6ee5987 commit 4416a09

File tree

1 file changed

+96
-4
lines changed

1 file changed

+96
-4
lines changed

pystac/extensions/processing.py

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
from pystac.extensions.base import (
2222
ExtensionManagementMixin,
2323
PropertiesExtension,
24+
SummariesExtension,
2425
)
2526
from pystac.extensions.hooks import ExtensionHooks
27+
from pystac.summaries import RangeSummary
2628
from pystac.utils import StringEnum, datetime_to_str, map_opt, str_to_datetime
2729

2830
T = TypeVar("T", pystac.Item, pystac.Asset, item_assets.AssetDefinition)
@@ -211,7 +213,6 @@ def expression(self: Self) -> dict[str, str | Any] | None:
211213
the relation type processing-expression.
212214
.. code-block:: python
213215
>>> proc_ext.expression = "(b4-b1)/(b4+b1)"
214-
>>> proc_ext.expression = "(b4-b1)/(b4+b1)"
215216
"""
216217
return self._get_property(EXPRESSION_PROP, dict[str, str | Any])
217218

@@ -334,25 +335,116 @@ class AssetProcessingExtension(ProcessingExtension[pystac.Asset]):
334335
"""If present, this will be a list containing 1 dictionary representing the
335336
properties of the owning :class:`~pystac.Item`."""
336337

337-
def __init__(self, asset: pystac.Asset):
338+
def __init__(self: Self, asset: pystac.Asset):
338339
self.asset_href = asset.href
339340
self.properties = asset.extra_fields
340341
if asset.owner and isinstance(asset.owner, pystac.Item):
341342
self.additional_read_properties = [asset.owner.properties]
342343

343-
def __repr__(self) -> str:
344+
def __repr__(self: Self) -> str:
344345
return f"<AssetProcessingExtension Asset href={self.asset_href}>"
345346

346347

347348
class ItemAssetsProcessingExtension(ProcessingExtension[pystac.ItemAssetDefinition]):
348349
properties: dict[str, Any]
349350
asset_defn: pystac.ItemAssetDefinition
350351

351-
def __init__(self, item_asset: pystac.ItemAssetDefinition):
352+
def __init__(self: Self, item_asset: pystac.ItemAssetDefinition):
352353
self.asset_defn = item_asset
353354
self.properties = item_asset.properties
354355

355356

357+
class SummariesProcessingExtension(SummariesExtension):
358+
"""A concrete implementation of :class:`~pystac.extensions.base.SummariesExtension`
359+
that extends the ``summaries`` field of a :class:`~pystac.Collection` to include
360+
properties defined in the :stac-ext:`Processing Extension <processing>`.
361+
"""
362+
363+
@property
364+
def level(self: Self) -> list[ProcessingLevel] | None:
365+
"""Get or sets the summary of :attr:`ProcessingExtension.level` values
366+
for this Collection.
367+
"""
368+
369+
return self.summaries.get_list(LEVEL_PROP)
370+
371+
@level.setter
372+
def level(self: Self, v: list[ProcessingLevel] | None) -> None:
373+
self._set_summary(LEVEL_PROP, v)
374+
375+
@property
376+
def datetime(self: Self) -> RangeSummary[datetime] | None:
377+
"""Get or sets the summary of :attr:`ProcessingExtension.datetime` values
378+
for this Collection.
379+
"""
380+
381+
return self.summaries.get_range(DATETIME_PROP)
382+
383+
@datetime.setter
384+
def datetime(self: Self, v: RangeSummary[datetime] | None) -> None:
385+
self._set_summary(DATETIME_PROP, v)
386+
387+
@property
388+
def expression(self: Self) -> list[dict[str, str | Any]] | None:
389+
"""Get or sets the summary of :attr:`ProcessingExtension.expression` values
390+
for this Collection.
391+
"""
392+
393+
return self.summaries.get_list(EXPRESSION_PROP)
394+
395+
@expression.setter
396+
def expression(self: Self, v: list[dict[str, str | Any]] | None) -> None:
397+
self._set_summary(EXPRESSION_PROP, v)
398+
399+
@property
400+
def lineage(self: Self) -> RangeSummary[str] | None:
401+
"""Get or sets the summary of :attr:`ProcessingExtension.lineage` values
402+
for this Collection.
403+
"""
404+
405+
return self.summaries.get_range(LINEAGE_PROP)
406+
407+
@lineage.setter
408+
def lineage(self: Self, v: RangeSummary[str] | None) -> None:
409+
self._set_summary(LINEAGE_PROP, v)
410+
411+
@property
412+
def facility(self: Self) -> RangeSummary[str] | None:
413+
"""Get or sets the summary of :attr:`ProcessingExtension.facility` values
414+
for this Collection.
415+
"""
416+
417+
return self.summaries.get_range(FACILITY_PROP)
418+
419+
@facility.setter
420+
def facility(self: Self, v: RangeSummary[str] | None) -> None:
421+
self._set_summary(FACILITY_PROP, v)
422+
423+
@property
424+
def version(self: Self) -> RangeSummary[str] | None:
425+
"""Get or sets the summary of :attr:`ProcessingExtension.version` values
426+
for this Collection.
427+
"""
428+
429+
return self.summaries.get_range(VERSION_PROP)
430+
431+
@version.setter
432+
def version(self: Self, v: RangeSummary[str] | None) -> None:
433+
self._set_summary(VERSION_PROP, v)
434+
435+
@property
436+
def software(self: Self) -> RangeSummary[dict[str, str]] | None:
437+
"""Get or sets the summary of :attr:`ProcessingExtension.software` values
438+
for this Collection.
439+
"""
440+
441+
return self.summaries.get_range(SOFTWARE_PROP)
442+
443+
@software.setter
444+
def software(self: Self, v: RangeSummary[dict[str, str]] | None) -> None:
445+
self._set_summary(SOFTWARE_PROP, v)
446+
447+
356448
class ProcessingExtensionHooks(ExtensionHooks):
357449
schema_uri: str = SCHEMA_URI
358450
prev_extension_ids = {"processing"}

0 commit comments

Comments
 (0)