4
4
"""
5
5
6
6
import enum
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 (
18
18
19
19
SCHEMA_URI = "https://stac-extensions.github.io/sat/v1.0.0/schema.json"
20
20
21
- ORBIT_STATE : str = "sat:orbit_state"
22
- RELATIVE_ORBIT : str = "sat:relative_orbit"
21
+ PREFIX : str = "sat:"
22
+ ORBIT_STATE : str = PREFIX + "orbit_state"
23
+ RELATIVE_ORBIT : str = PREFIX + "relative_orbit"
23
24
24
25
25
- class OrbitState (enum .Enum ):
26
+ class OrbitState (str , enum .Enum ):
26
27
ASCENDING = "ascending"
27
28
DESCENDING = "descending"
28
29
GEOSTATIONARY = "geostationary"
@@ -31,25 +32,28 @@ class OrbitState(enum.Enum):
31
32
class SatExtension (
32
33
Generic [T ], PropertiesExtension , ExtensionManagementMixin [pystac .Item ]
33
34
):
34
- """SatItemExt extends Item to add sat properties to a STAC Item.
35
+ """An abstract class that can be used to extend the properties of an
36
+ :class:`~pystac.Item` or :class:`~pystac.Asset` with properties from the
37
+ :stac-ext:`Satellite Extension <sat>`. This class is generic over the type of
38
+ STAC Object to be extended (e.g. :class:`~pystac.Item`,
39
+ :class:`~pystac.Collection`).
35
40
36
- Args:
37
- item : The item to be extended.
41
+ To create a concrete instance of :class:`SatExtension`, use the
42
+ :meth:`SatExtension.ext` method. For example:
38
43
39
- Attributes:
40
- item : The item that is being extended.
44
+ .. code-block:: python
41
45
42
- Note:
43
- Using SatItemExt to directly wrap an item will add the 'sat'
44
- extension ID to the item's stac_extensions.
46
+ >>> item: pystac.Item = ...
47
+ >>> sat_ext = SatExtension.ext(item)
45
48
"""
46
49
47
50
def apply (
48
51
self ,
49
52
orbit_state : Optional [OrbitState ] = None ,
50
53
relative_orbit : Optional [int ] = None ,
51
54
) -> None :
52
- """Applies ext extension properties to the extended Item.
55
+ """Applies ext extension properties to the extended :class:`~pystac.Item` or
56
+ class:`~pystac.Asset`.
53
57
54
58
Must specify at least one of orbit_state or relative_orbit in order
55
59
for the sat extension to properties to be valid.
@@ -67,11 +71,7 @@ def apply(
67
71
68
72
@property
69
73
def orbit_state (self ) -> Optional [OrbitState ]:
70
- """Get or sets an orbit state of the item.
71
-
72
- Returns:
73
- OrbitState or None
74
- """
74
+ """Get or sets an orbit state of the object."""
75
75
return map_opt (lambda x : OrbitState (x ), self ._get_property (ORBIT_STATE , str ))
76
76
77
77
@orbit_state .setter
@@ -80,11 +80,7 @@ def orbit_state(self, v: Optional[OrbitState]) -> None:
80
80
81
81
@property
82
82
def relative_orbit (self ) -> Optional [int ]:
83
- """Get or sets a relative orbit number of the item.
84
-
85
- Returns:
86
- int or None
87
- """
83
+ """Get or sets a relative orbit number of the item."""
88
84
return self ._get_property (RELATIVE_ORBIT , int )
89
85
90
86
@relative_orbit .setter
@@ -97,6 +93,16 @@ def get_schema_uri(cls) -> str:
97
93
98
94
@classmethod
99
95
def ext (cls , obj : T , add_if_missing : bool = False ) -> "SatExtension[T]" :
96
+ """Extends the given STAC Object with properties from the :stac-ext:`Satellite
97
+ Extension <sat>`.
98
+
99
+ This extension can be applied to instances of :class:`~pystac.Item` or
100
+ :class:`~pystac.Asset`.
101
+
102
+ Raises:
103
+
104
+ pystac.ExtensionTypeError : If an invalid object type is passed.
105
+ """
100
106
if isinstance (obj , pystac .Item ):
101
107
if add_if_missing :
102
108
cls .add_to (obj )
@@ -114,6 +120,21 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "SatExtension[T]":
114
120
115
121
116
122
class ItemSatExtension (SatExtension [pystac .Item ]):
123
+ """A concrete implementation of :class:`SatExtension` on an :class:`~pystac.Item`
124
+ that extends the properties of the Item to include properties defined in the
125
+ :stac-ext:`Satellite Extension <sat>`.
126
+
127
+ This class should generally not be instantiated directly. Instead, call
128
+ :meth:`SatExtension.ext` on an :class:`~pystac.Item` to
129
+ extend it.
130
+ """
131
+
132
+ item : pystac .Item
133
+ """The :class:`~pystac.Item` being extended."""
134
+
135
+ properties : Dict [str , Any ]
136
+ """The :class:`~pystac.Item` properties, including extension properties."""
137
+
117
138
def __init__ (self , item : pystac .Item ):
118
139
self .item = item
119
140
self .properties = item .properties
@@ -123,6 +144,25 @@ def __repr__(self) -> str:
123
144
124
145
125
146
class AssetSatExtension (SatExtension [pystac .Asset ]):
147
+ """A concrete implementation of :class:`SatExtension` on an :class:`~pystac.Asset`
148
+ that extends the properties of the Asset to include properties defined in the
149
+ :stac-ext:`Satellite Extension <sat>`.
150
+
151
+ This class should generally not be instantiated directly. Instead, call
152
+ :meth:`SatExtension.ext` on an :class:`~pystac.Asset` to
153
+ extend it.
154
+ """
155
+
156
+ asset_href : str
157
+ """The ``href`` value of the :class:`~pystac.Asset` being extended."""
158
+
159
+ properties : Dict [str , Any ]
160
+ """The :class:`~pystac.Asset` fields, including extension properties."""
161
+
162
+ additional_read_properties : Optional [Iterable [Dict [str , Any ]]] = None
163
+ """If present, this will be a list containing 1 dictionary representing the
164
+ properties of the owning :class:`~pystac.Item`."""
165
+
126
166
def __init__ (self , asset : pystac .Asset ):
127
167
self .asset_href = asset .href
128
168
self .properties = asset .properties
0 commit comments