Skip to content
Draft
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
10 changes: 6 additions & 4 deletions src/pystac/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from typing_extensions import deprecated

from .common import T_DataValue, T_Instrument
from .media_type import MediaType
from .utils import is_absolute_href, make_absolute_href, make_relative_href
from .writer import Writer
Expand All @@ -26,7 +27,7 @@ def __init__(
self.description: str | None = description
self.type: str | None = type
self.roles: list[str] | None = roles
self.extra_fields: dict[str, Any] = kwargs
self.extra_fields: dict[str, Any] | T_DataValue | T_Instrument = kwargs

@classmethod
def try_from[T: ItemAsset](cls: type[T], data: T | dict[str, Any]) -> T:
Expand All @@ -45,7 +46,9 @@ def clone[T: ItemAsset](self: T) -> T:
return self.from_dict(self.to_dict())

def to_dict(self) -> dict[str, Any]:
data = copy.deepcopy(self.extra_fields)
data: dict[str, Any] = {
k: v for k, v in copy.deepcopy(self.extra_fields).items()
}
if self.title is not None:
data["title"] = self.title
if self.description is not None:
Expand Down Expand Up @@ -103,8 +106,7 @@ def get_absolute_href(self) -> str | None:
@override
def to_dict(self) -> dict[str, Any]:
data = super().to_dict()
data["href"] = self.href
return data
return {"href": self.href, **data}


class Assets(Protocol):
Expand Down
62 changes: 62 additions & 0 deletions src/pystac/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from __future__ import annotations

from typing import Literal, TypedDict


class T_Basics(TypedDict, total=False):
title: str
description: str
keywords: list[str]
roles: list[str]


class T_DateTime(TypedDict, total=False):
datetime: str
created: str
updated: str
start_datetime: str
end_datetime: str


class T_Instrument(TypedDict, total=False):
platform: str
instruments: list[str]
constellation: str
mission: str
gsd: int


class T_Statistics(TypedDict, total=False):
minimum: float
maximum: float
mean: float
stddev: float
count: int
valid_percent: float


class T_DataValue(TypedDict, total=False):
nodata: float | str
unit: str
data_type: DataType
statistics: T_Statistics


type DataType = Literal[
"int8",
"int16",
"int32",
"int64",
"uint8",
"uint16",
"uint32",
"uint64",
"float16",
"float32",
"float64",
"cint16",
"cint32",
"cfloat32",
"cfloat64",
"other",
]
Loading