Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

### Changed

- Renamed `Asset.properties` -> `Asset.extra_fields` and `Link.properties` ->
`Link.extra_fields` for consistency with other STAC objects
([#510](https://github.com/stac-utils/pystac/pull/510))

### Fixed

- Bug in `pystac.serialization.identify_stac_object_type` where invalid objects with
Expand Down
62 changes: 35 additions & 27 deletions pystac/asset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from copy import copy
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Union

import pystac
from pystac.utils import is_absolute_href, make_absolute_href

if TYPE_CHECKING:
Expand All @@ -24,47 +23,56 @@ class Asset:
are preferred. See :class:`~pystac.MediaType` for common media types.
roles : Optional, Semantic roles (i.e. thumbnail, overview,
data, metadata) of the asset.
properties : Optional, additional properties for this asset. This is used
extra_fields : Optional, additional fields for this asset. This is used
by extensions as a way to serialize and deserialize properties on asset
object JSON.

Attributes:
href : Link to the asset object. Relative and absolute links are both
allowed.
title : Optional displayed title for clients and users.
description : A description of the Asset providing additional details,
such as how it was processed or created. CommonMark 0.29 syntax MAY be
used for rich text representation.
media_type : Optional description of the media type. Registered Media Types
are preferred. See :class:`~pystac.MediaType` for common media types.
properties : Optional, additional properties for this asset. This is used
by extensions as a way to serialize and deserialize properties on asset
object JSON.
owner: The Item or Collection this asset belongs to, or None if it has no owner.
"""

href: str
"""Link to the asset object. Relative and absolute links are both allowed."""

title: Optional[str]
"""Optional displayed title for clients and users."""

description: Optional[str]
"""A description of the Asset providing additional details, such as how it was
processed or created. CommonMark 0.29 syntax MAY be used for rich text
representation."""

media_type: Optional[str]
"""Optional description of the media type. Registered Media Types are preferred.
See :class:`~pystac.MediaType` for common media types."""

roles: Optional[List[str]]
"""Optional, Semantic roles (i.e. thumbnail, overview, data, metadata) of the
asset."""

owner: Optional[Union["Item_Type", "Collection_Type"]]
"""The :class:`~pystac.Item` or :class:`~pystac.Collection` that this asset belongs
to, or ``None`` if it has no owner."""

extra_fields: Dict[str, Any]
"""Optional, additional fields for this asset. This is used by extensions as a
way to serialize and deserialize properties on asset object JSON."""

def __init__(
self,
href: str,
title: Optional[str] = None,
description: Optional[str] = None,
media_type: Optional[str] = None,
roles: Optional[List[str]] = None,
properties: Optional[Dict[str, Any]] = None,
extra_fields: Optional[Dict[str, Any]] = None,
) -> None:
self.href = href
self.title = title
self.description = description
self.media_type = media_type
self.roles = roles

if properties is not None:
self.properties = properties
else:
self.properties = {}
self.extra_fields = extra_fields or {}

# The Item which owns this Asset.
self.owner: Optional[Union[pystac.Item, pystac.Collection]] = None
self.owner = None

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

if self.properties is not None and len(self.properties) > 0:
for k, v in self.properties.items():
if self.extra_fields is not None and len(self.extra_fields) > 0:
for k, v in self.extra_fields.items():
d[k] = v

if self.roles is not None:
Expand All @@ -133,7 +141,7 @@ def clone(self) -> "Asset":
description=self.description,
media_type=self.media_type,
roles=self.roles,
properties=self.properties,
extra_fields=self.extra_fields,
)

def __repr__(self) -> str:
Expand Down Expand Up @@ -162,5 +170,5 @@ def from_dict(d: Dict[str, Any]) -> "Asset":
title=title,
description=description,
roles=roles,
properties=properties,
extra_fields=properties,
)
2 changes: 1 addition & 1 deletion pystac/extensions/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class AssetDatacubeExtension(DatacubeExtension[pystac.Asset]):

def __init__(self, asset: pystac.Asset):
self.asset_href = asset.href
self.properties = asset.properties
self.properties = asset.extra_fields
if asset.owner and isinstance(asset.owner, pystac.Item):
self.additional_read_properties = [asset.owner.properties]
else:
Expand Down
6 changes: 3 additions & 3 deletions pystac/extensions/eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ def _get_bands(self) -> Optional[List[Band]]:
if bands is None:
asset_bands: List[Dict[str, Any]] = []
for _, value in self.item.get_assets().items():
if BANDS_PROP in value.properties:
if BANDS_PROP in value.extra_fields:
asset_bands.extend(
cast(List[Dict[str, Any]], value.properties.get(BANDS_PROP))
cast(List[Dict[str, Any]], value.extra_fields.get(BANDS_PROP))
)
if any(asset_bands):
bands = asset_bands
Expand Down Expand Up @@ -454,7 +454,7 @@ def _get_bands(self) -> Optional[List[Band]]:

def __init__(self, asset: pystac.Asset):
self.asset_href = asset.href
self.properties = asset.properties
self.properties = asset.extra_fields
if asset.owner and isinstance(asset.owner, pystac.Item):
self.additional_read_properties = [asset.owner.properties]

Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class FileExtension(PropertiesExtension, ExtensionManagementMixin[pystac.Item]):

def __init__(self, asset: pystac.Asset):
self.asset_href = asset.href
self.properties = asset.properties
self.properties = asset.extra_fields
if asset.owner and isinstance(asset.owner, pystac.Item):
self.additional_read_properties = [asset.owner.properties]

Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/item_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def create_asset(self, href: str) -> pystac.Asset:
description=self.description,
media_type=self.media_type,
roles=self.roles,
properties={
extra_fields={
k: v
for k, v in self.properties.items()
if k
Expand Down
8 changes: 4 additions & 4 deletions pystac/extensions/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,15 +619,15 @@ def add_source(
assets : Optional list of assets that determine what
assets in the source item this label item data applies to.
"""
properties = None
extra_fields = None
if assets is not None:
properties = {"label:assets": assets}
extra_fields = {"label:assets": assets}
link = pystac.Link(
"source",
source_item,
title=title,
media_type=pystac.MediaType.JSON,
properties=properties,
extra_fields=extra_fields,
)
self.obj.add_link(link)

Expand Down Expand Up @@ -665,7 +665,7 @@ def add_labels(
self.obj.add_asset(
"labels",
pystac.Asset(
href=href, title=title, media_type=media_type, properties=properties
href=href, title=title, media_type=media_type, extra_fields=properties
),
)

Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def __repr__(self) -> str:
class AssetPointcloudExtension(PointcloudExtension[pystac.Asset]):
def __init__(self, asset: pystac.Asset):
self.asset_href = asset.href
self.properties = asset.properties
self.properties = asset.extra_fields
if asset.owner and isinstance(asset.owner, pystac.Item):
self.additional_read_properties = [asset.owner.properties]
self.repr_id = f"href={asset.href} item.id={asset.owner.id}"
Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class AssetProjectionExtension(ProjectionExtension[pystac.Asset]):

def __init__(self, asset: pystac.Asset):
self.asset_href = asset.href
self.properties = asset.properties
self.properties = asset.extra_fields
if asset.owner and isinstance(asset.owner, pystac.Item):
self.additional_read_properties = [asset.owner.properties]

Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ class RasterExtension(PropertiesExtension, ExtensionManagementMixin[pystac.Item]

def __init__(self, asset: pystac.Asset):
self.asset_href = asset.href
self.properties = asset.properties
self.properties = asset.extra_fields
if asset.owner and isinstance(asset.owner, pystac.Item):
self.additional_read_properties = [asset.owner.properties]

Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/sar.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def __repr__(self) -> str:
class AssetSarExtension(SarExtension[pystac.Asset]):
def __init__(self, asset: pystac.Asset):
self.asset_href = asset.href
self.properties = asset.properties
self.properties = asset.extra_fields
if asset.owner and isinstance(asset.owner, pystac.Item):
self.additional_read_properties = [asset.owner.properties]

Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/sat.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __repr__(self) -> str:
class AssetSatExtension(SatExtension[pystac.Asset]):
def __init__(self, asset: pystac.Asset):
self.asset_href = asset.href
self.properties = asset.properties
self.properties = asset.extra_fields
if asset.owner and isinstance(asset.owner, pystac.Item):
self.additional_read_properties = [asset.owner.properties]

Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/timestamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def __repr__(self) -> str:
class AssetTimestampsExtension(TimestampsExtension[pystac.Asset]):
def __init__(self, asset: pystac.Asset):
self.asset_href = asset.href
self.properties = asset.properties
self.properties = asset.extra_fields
if asset.owner and isinstance(asset.owner, pystac.Item):
self.additional_read_properties = [asset.owner.properties]

Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class AssetViewExtension(ViewExtension[pystac.Asset]):

def __init__(self, asset: pystac.Asset):
self.asset_href = asset.href
self.properties = asset.properties
self.properties = asset.extra_fields
if asset.owner and isinstance(asset.owner, pystac.Item):
self.additional_read_properties = [asset.owner.properties]

Expand Down
Loading