|
21 | 21 | from pystac.extensions.base import ( |
22 | 22 | ExtensionManagementMixin, |
23 | 23 | PropertiesExtension, |
| 24 | + SummariesExtension, |
24 | 25 | ) |
25 | 26 | from pystac.extensions.hooks import ExtensionHooks |
| 27 | +from pystac.summaries import RangeSummary |
26 | 28 | from pystac.utils import StringEnum, datetime_to_str, map_opt, str_to_datetime |
27 | 29 |
|
28 | 30 | T = TypeVar("T", pystac.Item, pystac.Asset, item_assets.AssetDefinition) |
@@ -211,7 +213,6 @@ def expression(self: Self) -> dict[str, str | Any] | None: |
211 | 213 | the relation type processing-expression. |
212 | 214 | .. code-block:: python |
213 | 215 | >>> proc_ext.expression = "(b4-b1)/(b4+b1)" |
214 | | - >>> proc_ext.expression = "(b4-b1)/(b4+b1)" |
215 | 216 | """ |
216 | 217 | return self._get_property(EXPRESSION_PROP, dict[str, str | Any]) |
217 | 218 |
|
@@ -334,25 +335,116 @@ class AssetProcessingExtension(ProcessingExtension[pystac.Asset]): |
334 | 335 | """If present, this will be a list containing 1 dictionary representing the |
335 | 336 | properties of the owning :class:`~pystac.Item`.""" |
336 | 337 |
|
337 | | - def __init__(self, asset: pystac.Asset): |
| 338 | + def __init__(self: Self, asset: pystac.Asset): |
338 | 339 | self.asset_href = asset.href |
339 | 340 | self.properties = asset.extra_fields |
340 | 341 | if asset.owner and isinstance(asset.owner, pystac.Item): |
341 | 342 | self.additional_read_properties = [asset.owner.properties] |
342 | 343 |
|
343 | | - def __repr__(self) -> str: |
| 344 | + def __repr__(self: Self) -> str: |
344 | 345 | return f"<AssetProcessingExtension Asset href={self.asset_href}>" |
345 | 346 |
|
346 | 347 |
|
347 | 348 | class ItemAssetsProcessingExtension(ProcessingExtension[pystac.ItemAssetDefinition]): |
348 | 349 | properties: dict[str, Any] |
349 | 350 | asset_defn: pystac.ItemAssetDefinition |
350 | 351 |
|
351 | | - def __init__(self, item_asset: pystac.ItemAssetDefinition): |
| 352 | + def __init__(self: Self, item_asset: pystac.ItemAssetDefinition): |
352 | 353 | self.asset_defn = item_asset |
353 | 354 | self.properties = item_asset.properties |
354 | 355 |
|
355 | 356 |
|
| 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 | + |
356 | 448 | class ProcessingExtensionHooks(ExtensionHooks): |
357 | 449 | schema_uri: str = SCHEMA_URI |
358 | 450 | prev_extension_ids = {"processing"} |
|
0 commit comments