4
4
"""
5
5
6
6
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
8
8
9
9
import pystac
10
10
from pystac .extensions .base import (
26
26
class TimestampsExtension (
27
27
Generic [T ], PropertiesExtension , ExtensionManagementMixin [pystac .Item ]
28
28
):
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)
31
41
"""
32
42
33
43
def apply (
@@ -52,18 +62,13 @@ def apply(
52
62
53
63
@property
54
64
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.
67
72
"""
68
73
return map_opt (str_to_datetime , self ._get_property (PUBLISHED_PROP , str ))
69
74
@@ -73,18 +78,13 @@ def published(self, v: Optional[Datetime]) -> None:
73
78
74
79
@property
75
80
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.
88
88
"""
89
89
return map_opt (str_to_datetime , self ._get_property (EXPIRES_PROP , str ))
90
90
@@ -94,17 +94,13 @@ def expires(self, v: Optional[Datetime]) -> None:
94
94
95
95
@property
96
96
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.
105
99
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.
108
104
"""
109
105
return map_opt (str_to_datetime , self ._get_property (UNPUBLISHED_PROP , str ))
110
106
@@ -118,6 +114,16 @@ def get_schema_uri(cls) -> str:
118
114
119
115
@classmethod
120
116
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
+ """
121
127
if isinstance (obj , pystac .Item ):
122
128
if add_if_missing :
123
129
cls .add_to (obj )
@@ -135,23 +141,55 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "TimestampsExtension[T]":
135
141
136
142
137
143
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
+
138
158
def __init__ (self , item : pystac .Item ):
139
159
self .item = item
140
160
self .properties = item .properties
141
161
142
162
def __repr__ (self ) -> str :
143
- return "<ItemtimestampsExtension Item id={}>" .format (self .item .id )
163
+ return "<ItemTimestampsExtension Item id={}>" .format (self .item .id )
144
164
145
165
146
166
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
+
147
185
def __init__ (self , asset : pystac .Asset ):
148
186
self .asset_href = asset .href
149
187
self .properties = asset .properties
150
188
if asset .owner and isinstance (asset .owner , pystac .Item ):
151
189
self .additional_read_properties = [asset .owner .properties ]
152
190
153
191
def __repr__ (self ) -> str :
154
- return "<AssettimestampsExtension Asset href={}>" .format (self .asset_href )
192
+ return "<AssetTimestampsExtension Asset href={}>" .format (self .asset_href )
155
193
156
194
157
195
class TimestampsExtensionHooks (ExtensionHooks ):
0 commit comments