Skip to content

Commit a625106

Browse files
committed
Update docs
1 parent 41557be commit a625106

File tree

6 files changed

+93
-10
lines changed

6 files changed

+93
-10
lines changed

docs/api/item_assets.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pystac.item_assets
2+
==================
3+
4+
.. automodule:: pystac.item_assets
5+
:members:
6+
:undoc-members:
7+
:noindex:

docs/api/pystac.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pystac
1515
Summaries
1616
Item
1717
Asset
18+
ItemAssetDefinition
1819
CommonMetadata
1920
ItemCollection
2021
Link
@@ -116,6 +117,14 @@ Asset
116117
:members:
117118
:undoc-members:
118119

120+
ItemAssetDefinition
121+
-------------------
122+
123+
.. autoclass:: pystac.ItemAssetDefinition
124+
:members:
125+
:undoc-members:
126+
127+
119128
CommonMetadata
120129
--------------
121130

pystac/collection.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,41 @@ def get_item(self, id: str, recursive: bool = False) -> Item | None:
735735

736736
@property
737737
def item_assets(self) -> dict[str, ItemAssetDefinition] | None:
738+
"""Accessor for `item_assets
739+
<https://github.com/radiantearth/stac-spec/blob/v1.1.0/collection-spec/collection-spec.md#item_assets>`__
740+
on this collection.
741+
742+
Example::
743+
744+
.. code-block:: python
745+
746+
>>> print(collection.item_assets)
747+
{'thumbnail': <pystac.item_assets.ItemAssetDefinition at 0x72aea0420750>,
748+
'metadata': <pystac.item_assets.ItemAssetDefinition at 0x72aea017dc90>,
749+
'B5': <pystac.item_assets.ItemAssetDefinition at 0x72aea017efd0>,
750+
'B6': <pystac.item_assets.ItemAssetDefinition at 0x72aea016d5d0>,
751+
'B7': <pystac.item_assets.ItemAssetDefinition at 0x72aea016e050>,
752+
'B8': <pystac.item_assets.ItemAssetDefinition at 0x72aea016da90>}
753+
>>> collection.item_assets["thumbnail"].title
754+
'Thumbnail'
755+
756+
Set attributes on :class:`~pystac.ItemAssetDefinition` objects
757+
758+
.. code-block:: python
759+
760+
>>> collection.item_assets["thumbnail"].title = "New Title"
761+
762+
Add to the ``item_assets`` dict:
763+
764+
.. code-block:: python
765+
766+
>>> collection.item_assets["B4"] = {
767+
'type': 'image/tiff; application=geotiff; profile=cloud-optimized',
768+
'eo:bands': [{'name': 'B4', 'common_name': 'red'}]
769+
}
770+
>>> collection.item_assets["B4"].owner == collection
771+
True
772+
"""
738773
if self._item_assets is None and "item_assets" in self.extra_fields:
739774
self._item_assets = _ItemAssets(self)
740775
return self._item_assets

pystac/extensions/item_assets.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,21 @@ def __init__(cls, *args: Any, **kwargs: Any) -> None:
2828

2929

3030
class ItemAssetsExtension(ExtensionManagementMixin[pystac.Collection]):
31+
"""
32+
DEPRECATED
33+
34+
.. deprecated:: 1.12.0
35+
Use :attr:`~pystac.Collection.item_assets` instead.
36+
"""
37+
3138
name: Literal["item_assets"] = "item_assets"
3239
collection: pystac.Collection
3340

3441
def __init__(self, collection: pystac.Collection) -> None:
3542
warnings.warn(
3643
(
3744
"The ``item_assets`` extension is deprecated. "
38-
"``item_assets`` are now top-level collection properties."
45+
"``item_assets`` is now a top-level property of ``Collection``."
3946
),
4047
DeprecatedWarning,
4148
)

pystac/item_assets.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
"""Implements the ``Item Asset Definition <item-assets>``."""
1+
"""
2+
Implements the `Item Asset Definition Object
3+
<https://github.com/radiantearth/stac-spec/blob/v1.1.0/collection-spec/collection-spec.md#item-asset-definition-object>`__
4+
for use as values in the :attr:`~pystac.Collection.item_assets` dict.
5+
"""
26

37
from __future__ import annotations
48

@@ -18,10 +22,9 @@
1822

1923

2024
class ItemAssetDefinition:
21-
"""Object that contains details about the datafiles that will be included in member
22-
Items for this Collection.
23-
24-
See the `Item Asset Definition Object <item-assets#asset-object>` for details.
25+
"""Implementation of the `Item Asset Definition Object
26+
<https://github.com/radiantearth/stac-spec/blob/v1.1.0/collection-spec/collection-spec.md#item-asset-definition-object>`__
27+
for use as values in the :attr:`~pystac.Collection.item_assets` dict.
2528
"""
2629

2730
properties: dict[str, Any]
@@ -58,10 +61,10 @@ def create(
5861
`CommonMark 0.29 <http://commonmark.org/>`__ syntax MAY be used
5962
for rich text representation.
6063
media_type : `media type\
61-
<https://github.com/radiantearth/stac-spec/tree/v1.0.0/catalog-spec/catalog-spec.md#media-types>`__
64+
<https://github.com/radiantearth/stac-spec/tree/v1.1.0/catalog-spec/catalog-spec.md#media-types>`__
6265
of the asset.
6366
roles : `semantic roles
64-
<https://github.com/radiantearth/stac-spec/tree/v1.0.0/item-spec/item-spec.md#asset-role-types>`__
67+
<https://github.com/radiantearth/stac-spec/tree/v1.1.0/item-spec/item-spec.md#asset-role-types>`__
6568
of the asset, similar to the use of rel in links.
6669
extra_fields : Additional fields on the asset definition, e.g. from
6770
extensions.

tests/test_item_assets.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ def test_example(self) -> None:
4545
),
4646
)
4747

48+
def test_set_using_dict(self) -> None:
49+
collection = self.collection.clone()
50+
51+
assert collection.item_assets
52+
self.assertEqual(len(collection.item_assets), 13)
53+
54+
collection.item_assets["Bx"] = {
55+
"type": "image/tiff; application=geotiff",
56+
"eo:bands": [
57+
{
58+
"name": "B1",
59+
"common_name": "coastal",
60+
"center_wavelength": 0.44,
61+
"full_width_half_max": 0.02,
62+
}
63+
],
64+
"title": "Coastal Band (B1)",
65+
"description": "Coastal Band Top Of the Atmosphere",
66+
} # type:ignore
67+
68+
self.assertEqual(collection.item_assets["B1"], collection.item_assets["Bx"])
69+
4870

4971
class TestAssetDefinition(unittest.TestCase):
5072
def setUp(self) -> None:
@@ -130,14 +152,14 @@ def test_item_assets_extension_is_deprecated() -> None:
130152

131153
assert ItemAssetsExtension.get_schema_uri() not in collection.stac_extensions
132154

133-
with pytest.warns(DeprecatedWarning, match="top-level collection properties"):
155+
with pytest.warns(DeprecatedWarning, match="top-level property of"):
134156
item_asset = ItemAssetsExtension.ext(
135157
collection, add_if_missing=True
136158
).item_assets["cloud-mask-raster"]
137159

138160
assert item_asset.ext.has("eo")
139161

140-
with pytest.warns(DeprecatedWarning, match="top-level collection properties"):
162+
with pytest.warns(DeprecatedWarning, match="top-level property of"):
141163
assert collection.ext.item_assets["cloud-mask-raster"].ext.has("eo")
142164

143165
assert ItemAssetsExtension.get_schema_uri() in collection.stac_extensions

0 commit comments

Comments
 (0)