Skip to content

Commit 0130128

Browse files
committed
Update Timestamps Extension docs
1 parent a4fe4cd commit 0130128

File tree

3 files changed

+100
-49
lines changed

3 files changed

+100
-49
lines changed

docs/api.rst

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,17 +536,29 @@ ItemScientificExtension
536536
Timestamps Extension
537537
--------------------
538538

539-
Implements the :stac-ext:`Timestamps Extension <timestamps>`.
539+
These classes are representations of the :stac-ext:`Timestamps Extension Spec
540+
<timestamps>`.
540541

541-
TimestampsItemExt
542-
~~~~~~~~~~~~~~~~~
542+
TimestampsExtension
543+
~~~~~~~~~~~~~~~~~~~
543544

544-
**TEMPORARILY REMOVED**
545+
.. autoclass:: pystac.extensions.timestamps.TimestampsExtension
546+
:members:
547+
:show-inheritance:
545548

546-
.. .. autoclass:: pystac.extensions.timestamps.TimestampsItemExt
547-
.. :members:
548-
.. :undoc-members:
549-
.. :show-inheritance:
549+
ItemTimestampsExtension
550+
~~~~~~~~~~~~~~~~~~~~~~~
551+
552+
.. autoclass:: pystac.extensions.timestamps.ItemTimestampsExtension
553+
:members:
554+
:show-inheritance:
555+
556+
AssetTimestampsExtension
557+
~~~~~~~~~~~~~~~~~~~~~~~~
558+
559+
.. autoclass:: pystac.extensions.timestamps.AssetTimestampsExtension
560+
:members:
561+
:show-inheritance:
550562

551563
SAR Extension
552564
-------------

pystac/extensions/eo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,11 @@ class EOExtension(
278278
Generic[T], PropertiesExtension, ExtensionManagementMixin[pystac.Item]
279279
):
280280
"""An abstract class that can be used to extend the properties of an
281-
:class:`~pystac.Item` or :class:`~pystac.Collection` with properties from the
281+
:class:`~pystac.Item` or :class:`~pystac.Asset` with properties from the
282282
:stac-ext:`Electro-Optical Extension <eo>`. This class is generic over the type of
283283
STAC Object to be extended (e.g. :class:`~pystac.Item`,
284-
:class:`~pystac.Collection`).
284+
:class:`~pystac.
285+
Asset`).
285286
286287
To create a concrete instance of :class:`EOExtension`, use the
287288
:meth:`EOExtension.ext` method. For example:

pystac/extensions/timestamps.py

Lines changed: 77 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
from datetime import datetime as Datetime
7-
from typing import Generic, Optional, Set, TypeVar, cast
7+
from typing import Dict, Any, Generic, Iterable, Optional, Set, TypeVar, cast
88

99
import pystac
1010
from pystac.extensions.base import (
@@ -26,8 +26,18 @@
2626
class TimestampsExtension(
2727
Generic[T], PropertiesExtension, ExtensionManagementMixin[pystac.Item]
2828
):
29-
"""TimestampsItemExt is the extension of an Item in that
30-
allows to specify additional timestamps for assets and metadata.
29+
"""An abstract class that can be used to extend the properties of an
30+
:class:`~pystac.Item` or :class:`~pystac.Asset` with properties from the
31+
:stac-ext:`Timestamps Extension <timestamps>`. This class is generic over the type
32+
of STAC Object to be extended (e.g. :class:`~pystac.Item`, :class:`~pystac.Asset`).
33+
34+
To create a concrete instance of :class:`TimestampsExtension`, use the
35+
:meth:`TimestampsExtension.ext` method. For example:
36+
37+
.. code-block:: python
38+
39+
>>> item: pystac.Item = ...
40+
>>> ts_ext = TimestampsExtension.ext(item)
3141
"""
3242

3343
def apply(
@@ -52,18 +62,13 @@ def apply(
5262

5363
@property
5464
def published(self) -> Optional[Datetime]:
55-
"""Get or sets a datetime objects that represent
56-
the date and time that the corresponding data
57-
was published the first time.
58-
59-
'Published'
60-
has a different meaning depending on where it is used. If available in
61-
the asset properties, it refers to the timestamps valid for the actual data
62-
linked to the Asset Object. If it comes from the Item properties, it's
63-
referencing to the timestamp valid for the metadata.
64-
65-
Returns:
66-
datetime
65+
"""Gets or sets a datetime object that represents the date and time that the
66+
corresponding data was published the first time.
67+
68+
'Published' has a different meaning depending on where it is used. If available
69+
in the asset properties, it refers to the timestamps valid for the actual data
70+
linked to the Asset Object. If it comes from the Item properties, it refers to
71+
timestamp valid for the metadata.
6772
"""
6873
return map_opt(str_to_datetime, self._get_property(PUBLISHED_PROP, str))
6974

@@ -73,18 +78,13 @@ def published(self, v: Optional[Datetime]) -> None:
7378

7479
@property
7580
def expires(self) -> Optional[Datetime]:
76-
"""Get or sets a datetime objects that represent
77-
the date and time the corresponding data
78-
expires (is not valid any longer).
79-
80-
'Unpublished'
81-
has a different meaning depending on where it is used. If available in
82-
the asset properties, it refers to the timestamps valid for the actual data
83-
linked to the Asset Object. If it comes from the Item properties, it's
84-
referencing to the timestamp valid for the metadata.
85-
86-
Returns:
87-
datetime
81+
"""Gets or sets a datetime object that represents the date and time the
82+
corresponding data expires (is not valid any longer).
83+
84+
'Unpublished' has a different meaning depending on where it is used. If
85+
available in the asset properties, it refers to the timestamps valid for the
86+
actual data linked to the Asset Object. If it comes from the Item properties,
87+
it refers to to the timestamp valid for the metadata.
8888
"""
8989
return map_opt(str_to_datetime, self._get_property(EXPIRES_PROP, str))
9090

@@ -94,17 +94,13 @@ def expires(self, v: Optional[Datetime]) -> None:
9494

9595
@property
9696
def unpublished(self) -> Optional[Datetime]:
97-
"""Get or sets a datetime objects that represent
98-
the Date and time the corresponding data was unpublished.
99-
100-
'Unpublished'
101-
has a different meaning depending on where it is used. If available in
102-
the asset properties, it refers to the timestamps valid for the actual data
103-
linked to the Asset Object. If it comes from the Item properties, it's
104-
referencing to the timestamp valid for the metadata.
97+
"""Gets or sets a datetime object that represents the date and time the
98+
corresponding data was unpublished.
10599
106-
Returns:
107-
datetime
100+
'Unpublished' has a different meaning depending on where it is used. If
101+
available in the asset properties, it refers to the timestamps valid for the
102+
actual data linked to the Asset Object. If it comes from the Item properties,
103+
it's referencing to the timestamp valid for the metadata.
108104
"""
109105
return map_opt(str_to_datetime, self._get_property(UNPUBLISHED_PROP, str))
110106

@@ -118,6 +114,16 @@ def get_schema_uri(cls) -> str:
118114

119115
@classmethod
120116
def ext(cls, obj: T, add_if_missing: bool = False) -> "TimestampsExtension[T]":
117+
"""Extends the given STAC Object with properties from the :stac-ext:`Timestamps
118+
Extension <timestamps>`.
119+
120+
This extension can be applied to instances of :class:`~pystac.Item` or
121+
:class:`~pystac.Asset`.
122+
123+
Raises:
124+
125+
pystac.ExtensionTypeError : If an invalid object type is passed.
126+
"""
121127
if isinstance(obj, pystac.Item):
122128
if add_if_missing:
123129
cls.add_to(obj)
@@ -135,23 +141,55 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "TimestampsExtension[T]":
135141

136142

137143
class ItemTimestampsExtension(TimestampsExtension[pystac.Item]):
144+
"""A concrete implementation of :class:`TimestampsExtension` on an
145+
:class:`~pystac.Item` that extends the properties of the Item to include properties
146+
defined in the :stac-ext:`Timestamps Extension <timestamps>`.
147+
148+
This class should generally not be instantiated directly. Instead, call
149+
:meth:`TimestampsExtension.ext` on an :class:`~pystac.Item` to extend it.
150+
"""
151+
152+
item: pystac.Item
153+
"""The :class:`~pystac.Item` being extended."""
154+
155+
properties: Dict[str, Any]
156+
"""The :class:`~pystac.Item` properties, including extension properties."""
157+
138158
def __init__(self, item: pystac.Item):
139159
self.item = item
140160
self.properties = item.properties
141161

142162
def __repr__(self) -> str:
143-
return "<ItemtimestampsExtension Item id={}>".format(self.item.id)
163+
return "<ItemTimestampsExtension Item id={}>".format(self.item.id)
144164

145165

146166
class AssetTimestampsExtension(TimestampsExtension[pystac.Asset]):
167+
"""A concrete implementation of :class:`TimestampsExtension` on an
168+
:class:`~pystac.Asset` that extends the Asset fields to include properties
169+
defined in the :stac-ext:`Timestamps Extension <timestamps>`.
170+
171+
This class should generally not be instantiated directly. Instead, call
172+
:meth:`TimestampsExtension.ext` on an :class:`~pystac.Asset` to extend it.
173+
"""
174+
175+
asset_href: str
176+
"""The ``href`` value of the :class:`~pystac.Asset` being extended."""
177+
178+
properties: Dict[str, Any]
179+
"""The :class:`~pystac.Asset` fields, including extension properties."""
180+
181+
additional_read_properties: Optional[Iterable[Dict[str, Any]]] = None
182+
"""If present, this will be a list containing 1 dictionary representing the
183+
properties of the owning :class:`~pystac.Item`."""
184+
147185
def __init__(self, asset: pystac.Asset):
148186
self.asset_href = asset.href
149187
self.properties = asset.properties
150188
if asset.owner and isinstance(asset.owner, pystac.Item):
151189
self.additional_read_properties = [asset.owner.properties]
152190

153191
def __repr__(self) -> str:
154-
return "<AssettimestampsExtension Asset href={}>".format(self.asset_href)
192+
return "<AssetTimestampsExtension Asset href={}>".format(self.asset_href)
155193

156194

157195
class TimestampsExtensionHooks(ExtensionHooks):

0 commit comments

Comments
 (0)