pystac-ext-xarray-assets 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
File without changes
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Implements the :stac-ext:`Xarray Assets Extension <xarray>`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
from typing import Any, Generic, Literal, TypeVar
|
|
7
|
+
|
|
8
|
+
import pystac
|
|
9
|
+
from pystac.extensions.base import ExtensionManagementMixin, PropertiesExtension
|
|
10
|
+
from pystac.extensions.hooks import ExtensionHooks
|
|
11
|
+
|
|
12
|
+
#: Generalized version of :class:`~pystac.Collection`,
|
|
13
|
+
#: :class:`~pystac.Item`, or :class:`~pystac.Asset`
|
|
14
|
+
T = TypeVar("T", pystac.Collection, pystac.Item, pystac.Asset)
|
|
15
|
+
|
|
16
|
+
SCHEMA_URI = "https://stac-extensions.github.io/xarray-assets/v1.0.0/schema.json"
|
|
17
|
+
|
|
18
|
+
PREFIX: str = "xarray:"
|
|
19
|
+
OPEN_KWARGS_PROP = PREFIX + "open_kwargs"
|
|
20
|
+
STORAGE_OPTIONS_PROP = PREFIX + "storage_options"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class XarrayAssetsExtension(
|
|
24
|
+
Generic[T],
|
|
25
|
+
PropertiesExtension,
|
|
26
|
+
ExtensionManagementMixin[pystac.Item | pystac.Collection],
|
|
27
|
+
):
|
|
28
|
+
"""An abstract class that can be used to extend the properties of a
|
|
29
|
+
:class:`~pystac.Collection`, :class:`~pystac.Item`, or :class:`~pystac.Asset` with
|
|
30
|
+
properties from the :stac-ext:`Xarray Assets Extension <xarray>`. This class is
|
|
31
|
+
generic over the type of STAC Object to be extended (e.g. :class:`~pystac.Item`,
|
|
32
|
+
:class:`~pystac.Asset`).
|
|
33
|
+
|
|
34
|
+
To create a concrete instance of :class:`XarrayAssetsExtension`, use the
|
|
35
|
+
:meth:`XarrayAssetsExtension.ext` method. For example:
|
|
36
|
+
|
|
37
|
+
.. code-block:: python
|
|
38
|
+
|
|
39
|
+
>>> item: pystac.Item = ...
|
|
40
|
+
>>> xr_ext = XarrayAssetsExtension.ext(item)
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
name: Literal["xarray"] = "xarray"
|
|
45
|
+
|
|
46
|
+
@classmethod
|
|
47
|
+
def get_schema_uri(cls) -> str:
|
|
48
|
+
return SCHEMA_URI
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def ext(cls, obj: T, add_if_missing: bool = False) -> XarrayAssetsExtension[T]:
|
|
52
|
+
"""Extend the given STAC Object with properties from the
|
|
53
|
+
:stac-ext:`XarrayAssets Extension <xarray>`.
|
|
54
|
+
|
|
55
|
+
This extension can be applied to instances of :class:`~pystac.Collection`,
|
|
56
|
+
:class:`~pystac.Item` or :class:`~pystac.Asset`.
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
pystac.ExtensionTypeError : If an invalid object type is passed.
|
|
60
|
+
"""
|
|
61
|
+
if isinstance(obj, pystac.Collection):
|
|
62
|
+
cls.ensure_has_extension(obj, add_if_missing)
|
|
63
|
+
return CollectionXarrayAssetsExtension(obj)
|
|
64
|
+
if isinstance(obj, pystac.Item):
|
|
65
|
+
cls.ensure_has_extension(obj, add_if_missing)
|
|
66
|
+
return ItemXarrayAssetsExtension(obj)
|
|
67
|
+
if isinstance(obj, pystac.Asset):
|
|
68
|
+
cls.ensure_owner_has_extension(obj, add_if_missing)
|
|
69
|
+
return AssetXarrayAssetsExtension(obj)
|
|
70
|
+
else:
|
|
71
|
+
raise pystac.ExtensionTypeError(cls._ext_error_message(obj))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class CollectionXarrayAssetsExtension(XarrayAssetsExtension[pystac.Collection]):
|
|
75
|
+
"""A concrete implementation of :class:`XarrayAssetsExtension` on a
|
|
76
|
+
:class:`~pystac.Collection` that extends the properties of the Item to include
|
|
77
|
+
properties defined in the :stac-ext:`XarrayAssets Extension <xarray>`.
|
|
78
|
+
|
|
79
|
+
This class should generally not be instantiated directly. Instead, call
|
|
80
|
+
:meth:`XarrayAssetsExtension.ext` on an :class:`~pystac.Collection` to extend it.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
collection: pystac.Collection
|
|
84
|
+
properties: dict[str, Any]
|
|
85
|
+
|
|
86
|
+
def __init__(self, collection: pystac.Collection):
|
|
87
|
+
self.collection = collection
|
|
88
|
+
self.properties = collection.extra_fields
|
|
89
|
+
|
|
90
|
+
def __repr__(self) -> str:
|
|
91
|
+
return f"<CollectionXarrayAssetsExtension Item id={self.collection.id}>"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class ItemXarrayAssetsExtension(XarrayAssetsExtension[pystac.Item]):
|
|
95
|
+
"""A concrete implementation of :class:`XarrayAssetsExtension` on an
|
|
96
|
+
:class:`~pystac.Item` that extends the properties of the Item to include properties
|
|
97
|
+
defined in the :stac-ext:`XarrayAssets Extension <xarray>`.
|
|
98
|
+
|
|
99
|
+
This class should generally not be instantiated directly. Instead, call
|
|
100
|
+
:meth:`XarrayAssetsExtension.ext` on an :class:`~pystac.Item` to extend it.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
item: pystac.Item
|
|
104
|
+
properties: dict[str, Any]
|
|
105
|
+
|
|
106
|
+
def __init__(self, item: pystac.Item):
|
|
107
|
+
self.item = item
|
|
108
|
+
self.properties = item.properties
|
|
109
|
+
|
|
110
|
+
def __repr__(self) -> str:
|
|
111
|
+
return f"<ItemXarrayAssetsExtension Item id={self.item.id}>"
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class AssetXarrayAssetsExtension(XarrayAssetsExtension[pystac.Asset]):
|
|
115
|
+
"""A concrete implementation of :class:`XarrayAssetsExtension` on an
|
|
116
|
+
:class:`~pystac.Asset` that extends the Asset fields to include properties defined
|
|
117
|
+
in the :stac-ext:`XarrayAssets Extension <xarray>`.
|
|
118
|
+
|
|
119
|
+
This class should generally not be instantiated directly. Instead, call
|
|
120
|
+
:meth:`XarrayAssetsExtension.ext` on an :class:`~pystac.Asset` to extend it.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
asset: pystac.Asset
|
|
124
|
+
properties: dict[str, Any]
|
|
125
|
+
additional_read_properties: Iterable[dict[str, Any]] | None = None
|
|
126
|
+
|
|
127
|
+
def __init__(self, asset: pystac.Asset):
|
|
128
|
+
self.asset = asset
|
|
129
|
+
self.properties = asset.extra_fields
|
|
130
|
+
if asset.owner and isinstance(asset.owner, pystac.Item):
|
|
131
|
+
self.additional_read_properties = [asset.owner.properties]
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def storage_options(self) -> dict[str, Any] | None:
|
|
135
|
+
"""Additional keywords for accessing the dataset from remote storage"""
|
|
136
|
+
return self.properties.get(STORAGE_OPTIONS_PROP)
|
|
137
|
+
|
|
138
|
+
@storage_options.setter
|
|
139
|
+
def storage_options(self, v: dict[str, Any] | None) -> Any:
|
|
140
|
+
if v is None:
|
|
141
|
+
self.properties.pop(STORAGE_OPTIONS_PROP, None)
|
|
142
|
+
else:
|
|
143
|
+
self.properties[STORAGE_OPTIONS_PROP] = v
|
|
144
|
+
|
|
145
|
+
@property
|
|
146
|
+
def open_kwargs(self) -> dict[str, Any] | None:
|
|
147
|
+
"""Additional keywords for opening the dataset"""
|
|
148
|
+
return self.properties.get(OPEN_KWARGS_PROP)
|
|
149
|
+
|
|
150
|
+
@open_kwargs.setter
|
|
151
|
+
def open_kwargs(self, v: dict[str, Any] | None) -> Any:
|
|
152
|
+
if v is None:
|
|
153
|
+
self.properties.pop(OPEN_KWARGS_PROP, None)
|
|
154
|
+
else:
|
|
155
|
+
self.properties[OPEN_KWARGS_PROP] = v
|
|
156
|
+
|
|
157
|
+
def __repr__(self) -> str:
|
|
158
|
+
return f"<AssetXarrayAssetsExtension Asset href={self.asset.href}>"
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
class XarrayAssetsExtensionHooks(ExtensionHooks):
|
|
162
|
+
schema_uri: str = SCHEMA_URI
|
|
163
|
+
prev_extension_ids = {"xarray"}
|
|
164
|
+
stac_object_types = {pystac.STACObjectType.COLLECTION, pystac.STACObjectType.ITEM}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
XARRAY_ASSETS_EXTENSION_HOOKS: ExtensionHooks = XarrayAssetsExtensionHooks()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pystac-ext-xarray-assets
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Xarray Assets extension for PySTAC
|
|
5
|
+
Project-URL: Documentation, https://pystac.readthedocs.io
|
|
6
|
+
Project-URL: Repository, https://github.com/stac-utils/pystac
|
|
7
|
+
Project-URL: Issues, https://github.com/stac-utils/pystac/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/stac-utils/pystac/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Discussions, https://github.com/radiantearth/stac-spec/discussions/categories/stac-software
|
|
10
|
+
License: Apache-2.0
|
|
11
|
+
Keywords: STAC,catalog,imagery,pystac,raster,xarray-assets
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Natural Language :: English
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: pystac-core
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# pystac-ext-xarray-assets
|
|
26
|
+
|
|
27
|
+
[PySTAC](https://pypi.org/project/pystac/) extension package for the [Xarray Assets Extension](https://github.com/stac-extensions/xarray-assets).
|
|
28
|
+
This extension provides fields for describing how assets can be opened with [xarray](https://xarray.dev/), including storage options, open parameters, and engine configuration.
|
|
29
|
+
|
|
30
|
+
## Supported versions
|
|
31
|
+
|
|
32
|
+
- [v1.0.0](https://stac-extensions.github.io/xarray-assets/v1.0.0/schema.json)
|
|
33
|
+
|
|
34
|
+
## Versioning
|
|
35
|
+
|
|
36
|
+
This package's version corresponds to the version of the extension specification it targets.
|
|
37
|
+
When we release updates to the package code without changing the target extension version, we use [post releases](https://packaging.python.org/en/latest/discussions/versioning/#post-releases), e.g. `1.0.0.post1`.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
pystac/extensions/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
pystac/extensions/xarray_assets.py,sha256=o48JFoYvUdmtLIyoGXqvl83QYJaNEwM6KlWFuCUZPP0,6229
|
|
3
|
+
pystac_ext_xarray_assets-1.0.0.dist-info/METADATA,sha256=4MF8wlq_dtz202sr_QCyUXD30iyzMTzayiA1DS7KMok,1888
|
|
4
|
+
pystac_ext_xarray_assets-1.0.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
5
|
+
pystac_ext_xarray_assets-1.0.0.dist-info/RECORD,,
|