Skip to content

Commit d78d122

Browse files
author
Jon Duckworth
authored
Merge pull request #510 from duckontheweb/change/properties-to-extra-fields
`properties` -> `extra_fields` for Asset and Link
2 parents 27d6132 + 4b4bc51 commit d78d122

22 files changed

+142
-121
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
### Changed
1818

19+
- Renamed `Asset.properties` -> `Asset.extra_fields` and `Link.properties` ->
20+
`Link.extra_fields` for consistency with other STAC objects
21+
([#510](https://github.com/stac-utils/pystac/pull/510))
22+
1923
### Fixed
2024

2125
- Bug in `pystac.serialization.identify_stac_object_type` where invalid objects with

pystac/asset.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from copy import copy
22
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Union
33

4-
import pystac
54
from pystac.utils import is_absolute_href, make_absolute_href
65

76
if TYPE_CHECKING:
@@ -24,47 +23,56 @@ class Asset:
2423
are preferred. See :class:`~pystac.MediaType` for common media types.
2524
roles : Optional, Semantic roles (i.e. thumbnail, overview,
2625
data, metadata) of the asset.
27-
properties : Optional, additional properties for this asset. This is used
26+
extra_fields : Optional, additional fields for this asset. This is used
2827
by extensions as a way to serialize and deserialize properties on asset
2928
object JSON.
30-
31-
Attributes:
32-
href : Link to the asset object. Relative and absolute links are both
33-
allowed.
34-
title : Optional displayed title for clients and users.
35-
description : A description of the Asset providing additional details,
36-
such as how it was processed or created. CommonMark 0.29 syntax MAY be
37-
used for rich text representation.
38-
media_type : Optional description of the media type. Registered Media Types
39-
are preferred. See :class:`~pystac.MediaType` for common media types.
40-
properties : Optional, additional properties for this asset. This is used
41-
by extensions as a way to serialize and deserialize properties on asset
42-
object JSON.
43-
owner: The Item or Collection this asset belongs to, or None if it has no owner.
4429
"""
4530

31+
href: str
32+
"""Link to the asset object. Relative and absolute links are both allowed."""
33+
34+
title: Optional[str]
35+
"""Optional displayed title for clients and users."""
36+
37+
description: Optional[str]
38+
"""A description of the Asset providing additional details, such as how it was
39+
processed or created. CommonMark 0.29 syntax MAY be used for rich text
40+
representation."""
41+
42+
media_type: Optional[str]
43+
"""Optional description of the media type. Registered Media Types are preferred.
44+
See :class:`~pystac.MediaType` for common media types."""
45+
46+
roles: Optional[List[str]]
47+
"""Optional, Semantic roles (i.e. thumbnail, overview, data, metadata) of the
48+
asset."""
49+
50+
owner: Optional[Union["Item_Type", "Collection_Type"]]
51+
"""The :class:`~pystac.Item` or :class:`~pystac.Collection` that this asset belongs
52+
to, or ``None`` if it has no owner."""
53+
54+
extra_fields: Dict[str, Any]
55+
"""Optional, additional fields for this asset. This is used by extensions as a
56+
way to serialize and deserialize properties on asset object JSON."""
57+
4658
def __init__(
4759
self,
4860
href: str,
4961
title: Optional[str] = None,
5062
description: Optional[str] = None,
5163
media_type: Optional[str] = None,
5264
roles: Optional[List[str]] = None,
53-
properties: Optional[Dict[str, Any]] = None,
65+
extra_fields: Optional[Dict[str, Any]] = None,
5466
) -> None:
5567
self.href = href
5668
self.title = title
5769
self.description = description
5870
self.media_type = media_type
5971
self.roles = roles
60-
61-
if properties is not None:
62-
self.properties = properties
63-
else:
64-
self.properties = {}
72+
self.extra_fields = extra_fields or {}
6573

6674
# The Item which owns this Asset.
67-
self.owner: Optional[Union[pystac.Item, pystac.Collection]] = None
75+
self.owner = None
6876

6977
def set_owner(self, obj: Union["Collection_Type", "Item_Type"]) -> None:
7078
"""Sets the owning item of this Asset.
@@ -112,8 +120,8 @@ def to_dict(self) -> Dict[str, Any]:
112120
if self.description is not None:
113121
d["description"] = self.description
114122

115-
if self.properties is not None and len(self.properties) > 0:
116-
for k, v in self.properties.items():
123+
if self.extra_fields is not None and len(self.extra_fields) > 0:
124+
for k, v in self.extra_fields.items():
117125
d[k] = v
118126

119127
if self.roles is not None:
@@ -134,7 +142,7 @@ def clone(self) -> "Asset":
134142
description=self.description,
135143
media_type=self.media_type,
136144
roles=self.roles,
137-
properties=self.properties,
145+
extra_fields=self.extra_fields,
138146
)
139147

140148
def __repr__(self) -> str:
@@ -163,5 +171,5 @@ def from_dict(cls, d: Dict[str, Any]) -> "Asset":
163171
title=title,
164172
description=description,
165173
roles=roles,
166-
properties=properties,
174+
extra_fields=properties,
167175
)

pystac/extensions/datacube.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ class AssetDatacubeExtension(DatacubeExtension[pystac.Asset]):
391391

392392
def __init__(self, asset: pystac.Asset):
393393
self.asset_href = asset.href
394-
self.properties = asset.properties
394+
self.properties = asset.extra_fields
395395
if asset.owner and isinstance(asset.owner, pystac.Item):
396396
self.additional_read_properties = [asset.owner.properties]
397397
else:

pystac/extensions/eo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ def _get_bands(self) -> Optional[List[Band]]:
409409
if bands is None:
410410
asset_bands: List[Dict[str, Any]] = []
411411
for _, value in self.item.get_assets().items():
412-
if BANDS_PROP in value.properties:
412+
if BANDS_PROP in value.extra_fields:
413413
asset_bands.extend(
414-
cast(List[Dict[str, Any]], value.properties.get(BANDS_PROP))
414+
cast(List[Dict[str, Any]], value.extra_fields.get(BANDS_PROP))
415415
)
416416
if any(asset_bands):
417417
bands = asset_bands
@@ -455,7 +455,7 @@ def _get_bands(self) -> Optional[List[Band]]:
455455

456456
def __init__(self, asset: pystac.Asset):
457457
self.asset_href = asset.href
458-
self.properties = asset.properties
458+
self.properties = asset.extra_fields
459459
if asset.owner and isinstance(asset.owner, pystac.Item):
460460
self.additional_read_properties = [asset.owner.properties]
461461

pystac/extensions/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class FileExtension(PropertiesExtension, ExtensionManagementMixin[pystac.Item]):
103103

104104
def __init__(self, asset: pystac.Asset):
105105
self.asset_href = asset.href
106-
self.properties = asset.properties
106+
self.properties = asset.extra_fields
107107
if asset.owner and isinstance(asset.owner, pystac.Item):
108108
self.additional_read_properties = [asset.owner.properties]
109109

pystac/extensions/item_assets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def create_asset(self, href: str) -> pystac.Asset:
7676
description=self.description,
7777
media_type=self.media_type,
7878
roles=self.roles,
79-
properties={
79+
extra_fields={
8080
k: v
8181
for k, v in self.properties.items()
8282
if k

pystac/extensions/label.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,15 +619,15 @@ def add_source(
619619
assets : Optional list of assets that determine what
620620
assets in the source item this label item data applies to.
621621
"""
622-
properties = None
622+
extra_fields = None
623623
if assets is not None:
624-
properties = {"label:assets": assets}
624+
extra_fields = {"label:assets": assets}
625625
link = pystac.Link(
626626
"source",
627627
source_item,
628628
title=title,
629629
media_type=pystac.MediaType.JSON,
630-
properties=properties,
630+
extra_fields=extra_fields,
631631
)
632632
self.obj.add_link(link)
633633

@@ -665,7 +665,7 @@ def add_labels(
665665
self.obj.add_asset(
666666
"labels",
667667
pystac.Asset(
668-
href=href, title=title, media_type=media_type, properties=properties
668+
href=href, title=title, media_type=media_type, extra_fields=properties
669669
),
670670
)
671671

pystac/extensions/pointcloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def __repr__(self) -> str:
552552
class AssetPointcloudExtension(PointcloudExtension[pystac.Asset]):
553553
def __init__(self, asset: pystac.Asset):
554554
self.asset_href = asset.href
555-
self.properties = asset.properties
555+
self.properties = asset.extra_fields
556556
if asset.owner and isinstance(asset.owner, pystac.Item):
557557
self.additional_read_properties = [asset.owner.properties]
558558
self.repr_id = f"href={asset.href} item.id={asset.owner.id}"

pystac/extensions/projection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class AssetProjectionExtension(ProjectionExtension[pystac.Asset]):
314314

315315
def __init__(self, asset: pystac.Asset):
316316
self.asset_href = asset.href
317-
self.properties = asset.properties
317+
self.properties = asset.extra_fields
318318
if asset.owner and isinstance(asset.owner, pystac.Item):
319319
self.additional_read_properties = [asset.owner.properties]
320320

pystac/extensions/raster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ class RasterExtension(PropertiesExtension, ExtensionManagementMixin[pystac.Item]
647647

648648
def __init__(self, asset: pystac.Asset):
649649
self.asset_href = asset.href
650-
self.properties = asset.properties
650+
self.properties = asset.extra_fields
651651
if asset.owner and isinstance(asset.owner, pystac.Item):
652652
self.additional_read_properties = [asset.owner.properties]
653653

0 commit comments

Comments
 (0)