1
1
from dataclasses import dataclass
2
2
from typing import Any , Generic , Literal , TypeVar , cast
3
3
4
- import pystac
4
+ from pystac import Asset , Catalog , Collection , Item , STACError
5
5
from pystac .extensions .classification import ClassificationExtension
6
6
from pystac .extensions .datacube import DatacubeExtension
7
7
from pystac .extensions .eo import EOExtension
18
18
from pystac .extensions .storage import StorageExtension
19
19
from pystac .extensions .table import TableExtension
20
20
from pystac .extensions .timestamps import TimestampsExtension
21
- from pystac .extensions .version import VersionExtension
21
+ from pystac .extensions .version import BaseVersionExtension , VersionExtension
22
22
from pystac .extensions .view import ViewExtension
23
23
from pystac .extensions .xarray_assets import XarrayAssetsExtension
24
24
25
- T = TypeVar ("T" , pystac . Asset , AssetDefinition )
25
+ T = TypeVar ("T" , Asset , AssetDefinition )
26
26
27
27
EXTENSION_NAMES = Literal [
28
28
"classification" ,
@@ -80,8 +80,8 @@ def _get_class_by_name(name: str) -> Any:
80
80
81
81
82
82
@dataclass
83
- class CollectionExt :
84
- stac_object : pystac . Collection
83
+ class CatalogExt :
84
+ stac_object : Catalog
85
85
86
86
def has (self , name : EXTENSION_NAMES ) -> bool :
87
87
return cast (bool , _get_class_by_name (name ).has_extension (self .stac_object ))
@@ -93,33 +93,38 @@ def remove(self, name: EXTENSION_NAMES) -> None:
93
93
_get_class_by_name (name ).remove_from (self .stac_object )
94
94
95
95
@property
96
- def cube (self ) -> DatacubeExtension [pystac .Collection ]:
96
+ def version (self ) -> VersionExtension [Catalog ]:
97
+ return VersionExtension .ext (self .stac_object )
98
+
99
+
100
+ @dataclass
101
+ class CollectionExt (CatalogExt ):
102
+ stac_object : Collection
103
+
104
+ @property
105
+ def cube (self ) -> DatacubeExtension [Collection ]:
97
106
return DatacubeExtension .ext (self .stac_object )
98
107
99
108
@property
100
109
def item_assets (self ) -> dict [str , AssetDefinition ]:
101
110
return ItemAssetsExtension .ext (self .stac_object ).item_assets
102
111
103
112
@property
104
- def sci (self ) -> ScientificExtension [pystac . Collection ]:
113
+ def sci (self ) -> ScientificExtension [Collection ]:
105
114
return ScientificExtension .ext (self .stac_object )
106
115
107
116
@property
108
- def table (self ) -> TableExtension [pystac . Collection ]:
117
+ def table (self ) -> TableExtension [Collection ]:
109
118
return TableExtension .ext (self .stac_object )
110
119
111
120
@property
112
- def version (self ) -> VersionExtension [pystac .Collection ]:
113
- return VersionExtension .ext (self .stac_object )
114
-
115
- @property
116
- def xarray (self ) -> XarrayAssetsExtension [pystac .Collection ]:
121
+ def xarray (self ) -> XarrayAssetsExtension [Collection ]:
117
122
return XarrayAssetsExtension .ext (self .stac_object )
118
123
119
124
120
125
@dataclass
121
126
class ItemExt :
122
- stac_object : pystac . Item
127
+ stac_object : Item
123
128
124
129
def has (self , name : EXTENSION_NAMES ) -> bool :
125
130
return cast (bool , _get_class_by_name (name ).has_extension (self .stac_object ))
@@ -131,15 +136,15 @@ def remove(self, name: EXTENSION_NAMES) -> None:
131
136
_get_class_by_name (name ).remove_from (self .stac_object )
132
137
133
138
@property
134
- def classification (self ) -> ClassificationExtension [pystac . Item ]:
139
+ def classification (self ) -> ClassificationExtension [Item ]:
135
140
return ClassificationExtension .ext (self .stac_object )
136
141
137
142
@property
138
- def cube (self ) -> DatacubeExtension [pystac . Item ]:
143
+ def cube (self ) -> DatacubeExtension [Item ]:
139
144
return DatacubeExtension .ext (self .stac_object )
140
145
141
146
@property
142
- def eo (self ) -> EOExtension [pystac . Item ]:
147
+ def eo (self ) -> EOExtension [Item ]:
143
148
return EOExtension .ext (self .stac_object )
144
149
145
150
@property
@@ -151,43 +156,43 @@ def mgrs(self) -> MgrsExtension:
151
156
return MgrsExtension .ext (self .stac_object )
152
157
153
158
@property
154
- def pc (self ) -> PointcloudExtension [pystac . Item ]:
159
+ def pc (self ) -> PointcloudExtension [Item ]:
155
160
return PointcloudExtension .ext (self .stac_object )
156
161
157
162
@property
158
- def proj (self ) -> ProjectionExtension [pystac . Item ]:
163
+ def proj (self ) -> ProjectionExtension [Item ]:
159
164
return ProjectionExtension .ext (self .stac_object )
160
165
161
166
@property
162
- def sar (self ) -> SarExtension [pystac . Item ]:
167
+ def sar (self ) -> SarExtension [Item ]:
163
168
return SarExtension .ext (self .stac_object )
164
169
165
170
@property
166
- def sat (self ) -> SatExtension [pystac . Item ]:
171
+ def sat (self ) -> SatExtension [Item ]:
167
172
return SatExtension .ext (self .stac_object )
168
173
169
174
@property
170
- def storage (self ) -> StorageExtension [pystac . Item ]:
175
+ def storage (self ) -> StorageExtension [Item ]:
171
176
return StorageExtension .ext (self .stac_object )
172
177
173
178
@property
174
- def table (self ) -> TableExtension [pystac . Item ]:
179
+ def table (self ) -> TableExtension [Item ]:
175
180
return TableExtension .ext (self .stac_object )
176
181
177
182
@property
178
- def timestamps (self ) -> TimestampsExtension [pystac . Item ]:
183
+ def timestamps (self ) -> TimestampsExtension [Item ]:
179
184
return TimestampsExtension .ext (self .stac_object )
180
185
181
186
@property
182
- def version (self ) -> VersionExtension [pystac . Item ]:
187
+ def version (self ) -> VersionExtension [Item ]:
183
188
return VersionExtension .ext (self .stac_object )
184
189
185
190
@property
186
- def view (self ) -> ViewExtension [pystac . Item ]:
191
+ def view (self ) -> ViewExtension [Item ]:
187
192
return ViewExtension .ext (self .stac_object )
188
193
189
194
@property
190
- def xarray (self ) -> XarrayAssetsExtension [pystac . Item ]:
195
+ def xarray (self ) -> XarrayAssetsExtension [Item ]:
191
196
return XarrayAssetsExtension .ext (self .stac_object )
192
197
193
198
@@ -196,7 +201,7 @@ class _AssetExt(Generic[T]):
196
201
197
202
def has (self , name : EXTENSION_NAMES ) -> bool :
198
203
if self .stac_object .owner is None :
199
- raise pystac . STACError (
204
+ raise STACError (
200
205
f"Attempted to add extension='{ name } ' for an Asset with no owner. "
201
206
"Use Asset.set_owner and then try to add the extension again."
202
207
)
@@ -207,7 +212,7 @@ def has(self, name: EXTENSION_NAMES) -> bool:
207
212
208
213
def add (self , name : EXTENSION_NAMES ) -> None :
209
214
if self .stac_object .owner is None :
210
- raise pystac . STACError (
215
+ raise STACError (
211
216
f"Attempted to add extension='{ name } ' for an Asset with no owner. "
212
217
"Use Asset.set_owner and then try to add the extension again."
213
218
)
@@ -216,7 +221,7 @@ def add(self, name: EXTENSION_NAMES) -> None:
216
221
217
222
def remove (self , name : EXTENSION_NAMES ) -> None :
218
223
if self .stac_object .owner is None :
219
- raise pystac . STACError (
224
+ raise STACError (
220
225
f"Attempted to remove extension='{ name } ' for an Asset with no owner. "
221
226
"Use Asset.set_owner and then try to remove the extension again."
222
227
)
@@ -263,25 +268,29 @@ def storage(self) -> StorageExtension[T]:
263
268
def table (self ) -> TableExtension [T ]:
264
269
return TableExtension .ext (self .stac_object )
265
270
271
+ @property
272
+ def version (self ) -> BaseVersionExtension [T ]:
273
+ return BaseVersionExtension .ext (self .stac_object )
274
+
266
275
@property
267
276
def view (self ) -> ViewExtension [T ]:
268
277
return ViewExtension .ext (self .stac_object )
269
278
270
279
271
280
@dataclass
272
- class AssetExt (_AssetExt [pystac . Asset ]):
273
- stac_object : pystac . Asset
281
+ class AssetExt (_AssetExt [Asset ]):
282
+ stac_object : Asset
274
283
275
284
@property
276
285
def file (self ) -> FileExtension :
277
286
return FileExtension .ext (self .stac_object )
278
287
279
288
@property
280
- def timestamps (self ) -> TimestampsExtension [pystac . Asset ]:
289
+ def timestamps (self ) -> TimestampsExtension [Asset ]:
281
290
return TimestampsExtension .ext (self .stac_object )
282
291
283
292
@property
284
- def xarray (self ) -> XarrayAssetsExtension [pystac . Asset ]:
293
+ def xarray (self ) -> XarrayAssetsExtension [Asset ]:
285
294
return XarrayAssetsExtension .ext (self .stac_object )
286
295
287
296
0 commit comments