Skip to content

Commit 3fead31

Browse files
committed
Update Sat Extension docstrings
1 parent 27d6132 commit 3fead31

File tree

1 file changed

+63
-23
lines changed

1 file changed

+63
-23
lines changed

pystac/extensions/sat.py

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

66
import enum
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 (
@@ -18,11 +18,12 @@
1818

1919
SCHEMA_URI = "https://stac-extensions.github.io/sat/v1.0.0/schema.json"
2020

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"
2324

2425

25-
class OrbitState(enum.Enum):
26+
class OrbitState(str, enum.Enum):
2627
ASCENDING = "ascending"
2728
DESCENDING = "descending"
2829
GEOSTATIONARY = "geostationary"
@@ -31,25 +32,28 @@ class OrbitState(enum.Enum):
3132
class SatExtension(
3233
Generic[T], PropertiesExtension, ExtensionManagementMixin[pystac.Item]
3334
):
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`).
3540
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:
3843
39-
Attributes:
40-
item : The item that is being extended.
44+
.. code-block:: python
4145
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)
4548
"""
4649

4750
def apply(
4851
self,
4952
orbit_state: Optional[OrbitState] = None,
5053
relative_orbit: Optional[int] = None,
5154
) -> 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`.
5357
5458
Must specify at least one of orbit_state or relative_orbit in order
5559
for the sat extension to properties to be valid.
@@ -67,11 +71,7 @@ def apply(
6771

6872
@property
6973
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."""
7575
return map_opt(lambda x: OrbitState(x), self._get_property(ORBIT_STATE, str))
7676

7777
@orbit_state.setter
@@ -80,11 +80,7 @@ def orbit_state(self, v: Optional[OrbitState]) -> None:
8080

8181
@property
8282
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."""
8884
return self._get_property(RELATIVE_ORBIT, int)
8985

9086
@relative_orbit.setter
@@ -97,6 +93,16 @@ def get_schema_uri(cls) -> str:
9793

9894
@classmethod
9995
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+
"""
100106
if isinstance(obj, pystac.Item):
101107
if add_if_missing:
102108
cls.add_to(obj)
@@ -114,6 +120,21 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "SatExtension[T]":
114120

115121

116122
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+
117138
def __init__(self, item: pystac.Item):
118139
self.item = item
119140
self.properties = item.properties
@@ -123,6 +144,25 @@ def __repr__(self) -> str:
123144

124145

125146
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+
126166
def __init__(self, asset: pystac.Asset):
127167
self.asset_href = asset.href
128168
self.properties = asset.properties

0 commit comments

Comments
 (0)