24
24
25
25
SCHEMA_URI = "https://stac-extensions.github.io/file/v1.0.0/schema.json"
26
26
27
- DATA_TYPE_PROP = "file:data_type"
28
- SIZE_PROP = "file:size"
29
- NODATA_PROP = "file:nodata"
30
- CHECKSUM_PROP = "file:checksum"
27
+ PREFIX = "file:"
28
+ DATA_TYPE_PROP = PREFIX + "data_type"
29
+ SIZE_PROP = PREFIX + "size"
30
+ NODATA_PROP = PREFIX + "nodata"
31
+ CHECKSUM_PROP = PREFIX + "checksum"
31
32
32
33
33
34
class FileDataType (str , enum .Enum ):
@@ -55,18 +56,19 @@ def __str__(self) -> str:
55
56
class FileExtension (
56
57
Generic [T ], PropertiesExtension , ExtensionManagementMixin [pystac .Item ]
57
58
):
58
- """FileItemExt is the extension of the Item in the file extension which
59
- adds file related details such as checksum, data type and size for assets.
59
+ """An abstract class that can be used to extend the properties of an
60
+ :class:`~pystac.Item` or :class:`~pystac.Asset` with properties from the
61
+ :stac-ext:`File Info Extension <file>`. This class is generic over the type of
62
+ STAC Object to be extended (e.g. :class:`~pystac.Item`,
63
+ :class:`~pystac.Asset`).
60
64
61
- Args:
62
- item : The item to be extended.
65
+ To create a concrete instance of :class:`FileExtension`, use the
66
+ :meth:`FileExtension.ext` method. For example:
63
67
64
- Attributes:
65
- item : The Item that is being extended.
68
+ .. code-block:: python
66
69
67
- Note:
68
- Using FileItemExt to directly wrap an item will add the 'file' extension ID to
69
- the item's stac_extensions.
70
+ >>> item: pystac.Item = ...
71
+ >>> file_ext = FileExtension.ext(item)
70
72
"""
71
73
72
74
def apply (
@@ -92,11 +94,7 @@ def apply(
92
94
93
95
@property
94
96
def data_type (self ) -> Optional [FileDataType ]:
95
- """Get or sets the data_type of the file.
96
-
97
- Returns:
98
- FileDataType
99
- """
97
+ """Get or sets the data_type of the file."""
100
98
return map_opt (
101
99
lambda s : FileDataType (s ), self ._get_property (DATA_TYPE_PROP , str )
102
100
)
@@ -107,11 +105,7 @@ def data_type(self, v: Optional[FileDataType]) -> None:
107
105
108
106
@property
109
107
def size (self ) -> Optional [int ]:
110
- """Get or sets the size in bytes of the file
111
-
112
- Returns:
113
- int or None
114
- """
108
+ """Get or sets the size in bytes of the file."""
115
109
return self ._get_property (SIZE_PROP , int )
116
110
117
111
@size .setter
@@ -120,7 +114,7 @@ def size(self, v: Optional[int]) -> None:
120
114
121
115
@property
122
116
def nodata (self ) -> Optional [List [Any ]]:
123
- """Get or sets the no data values"""
117
+ """Get or sets the no data values. """
124
118
return self ._get_property (NODATA_PROP , List [Any ])
125
119
126
120
@nodata .setter
@@ -129,11 +123,7 @@ def nodata(self, v: Optional[List[Any]]) -> None:
129
123
130
124
@property
131
125
def checksum (self ) -> Optional [str ]:
132
- """Get or sets the checksum
133
-
134
- Returns:
135
- str or None
136
- """
126
+ """Get or sets the checksum"""
137
127
return self ._get_property (CHECKSUM_PROP , str )
138
128
139
129
@checksum .setter
@@ -146,6 +136,16 @@ def get_schema_uri(cls) -> str:
146
136
147
137
@staticmethod
148
138
def ext (obj : T ) -> "FileExtension[T]" :
139
+ """Extends the given STAC Object with properties from the :stac-ext:`File Info
140
+ Extension <file>`.
141
+
142
+ This extension can be applied to instances of :class:`~pystac.Item` or
143
+ :class:`~pystac.Asset`.
144
+
145
+ Raises:
146
+
147
+ pystac.ExtensionTypeError : If an invalid object type is passed.
148
+ """
149
149
if isinstance (obj , pystac .Item ):
150
150
return cast (FileExtension [T ], ItemFileExtension (obj ))
151
151
elif isinstance (obj , pystac .Asset ):
@@ -161,6 +161,14 @@ def summaries(obj: pystac.Collection) -> "SummariesFileExtension":
161
161
162
162
163
163
class ItemFileExtension (FileExtension [pystac .Item ]):
164
+ """A concrete implementation of :class:`FileExtension` on an :class:`~pystac.Item`
165
+ that extends the properties of the Item to include properties defined in the
166
+ :stac-ext:`File Info Extension <file>`.
167
+
168
+ This class should generally not be instantiated directly. Instead, call
169
+ :meth:`FileExtension.ext` on an :class:`~pystac.Item` to extend it.
170
+ """
171
+
164
172
def __init__ (self , item : pystac .Item ):
165
173
self .item = item
166
174
self .properties = item .properties
@@ -170,6 +178,14 @@ def __repr__(self) -> str:
170
178
171
179
172
180
class AssetFileExtension (FileExtension [pystac .Asset ]):
181
+ """A concrete implementation of :class:`FileExtension` on an :class:`~pystac.Asset`
182
+ that extends the Asset fields to include properties defined in the
183
+ :stac-ext:`File Info Extension <info>`.
184
+
185
+ This class should generally not be instantiated directly. Instead, call
186
+ :meth:`FileExtension.ext` on an :class:`~pystac.Asset` to extend it.
187
+ """
188
+
173
189
def __init__ (self , asset : pystac .Asset ):
174
190
self .asset_href = asset .href
175
191
self .properties = asset .properties
@@ -183,11 +199,7 @@ def __repr__(self) -> str:
183
199
class SummariesFileExtension (SummariesExtension ):
184
200
@property
185
201
def data_type (self ) -> Optional [List [FileDataType ]]:
186
- """Get or sets the data_type of the file.
187
-
188
- Returns:
189
- FileDataType
190
- """
202
+ """Get or sets the summary of data_type values for this Collection."""
191
203
192
204
return map_opt (
193
205
lambda x : [FileDataType (t ) for t in x ],
@@ -200,11 +212,7 @@ def data_type(self, v: Optional[List[FileDataType]]) -> None:
200
212
201
213
@property
202
214
def size (self ) -> Optional [pystac .RangeSummary [int ]]:
203
- """Get or sets the size in bytes of the file
204
-
205
- Returns:
206
- int or None
207
- """
215
+ """Get or sets the summary of size values for this Collection."""
208
216
return self .summaries .get_range (SIZE_PROP )
209
217
210
218
@size .setter
@@ -213,7 +221,7 @@ def size(self, v: Optional[pystac.RangeSummary[int]]) -> None:
213
221
214
222
@property
215
223
def nodata (self ) -> Optional [List [Any ]]:
216
- """Get or sets the list of no data values"""
224
+ """Get or sets the summary of nodata values for this Collection. """
217
225
return self .summaries .get_list (NODATA_PROP )
218
226
219
227
@nodata .setter
0 commit comments