Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to STAC spec 1.0.0 #86

Merged
merged 14 commits into from
Jun 25, 2021
6 changes: 5 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
1.3.9 (2020-03-02)
Unreleased
------------------
- Update to stac version 1.0.0

1.3.9 (2021-03-02)
------------------
- Add id to landing page, making it a valid catalog (#43, @lossyrob)
- Make `item_assets` (item assets extension) a dictionary of assets (#47, @kylebarron)
Expand Down
4 changes: 2 additions & 2 deletions stac_pydantic/api/extensions/sort.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import auto

from pydantic import BaseModel
from pydantic import constr, BaseModel

from stac_pydantic.utils import AutoValueEnum

Expand All @@ -15,5 +15,5 @@ class SortExtension(BaseModel):
https://github.com/radiantearth/stac-api-spec/tree/master/extensions/sort#sort-api-extension
"""

field: str
field: constr(min_length=1)
direction: SortDirections
6 changes: 3 additions & 3 deletions stac_pydantic/api/landing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Optional, Union

from pydantic import BaseModel, Field
from pydantic import constr, BaseModel, Field

from stac_pydantic.links import Links
from stac_pydantic.shared import ExtensionTypes
Expand All @@ -12,8 +12,8 @@ class LandingPage(BaseModel):
https://github.com/radiantearth/stac-api-spec/blob/master/api-spec.md#ogc-api---features-endpoints
"""

id: str
description: str
id: constr(min_length=1)
description: constr(min_length=1)
title: Optional[str]
stac_version: str = Field(STAC_VERSION, const=True)
stac_extensions: Optional[List[Union[str, ExtensionTypes]]]
Expand Down
2 changes: 1 addition & 1 deletion stac_pydantic/api/utils/link_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BaseLinks:
"""Create inferred links common to collections and items."""

base_url: str
_link_members: ClassVar[Tuple[str]] = ("root")
_link_members: ClassVar[Tuple[str]] = "root"
geospatial-jeff marked this conversation as resolved.
Show resolved Hide resolved

def root(self) -> Link:
"""Return the catalog root."""
Expand Down
9 changes: 5 additions & 4 deletions stac_pydantic/catalog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Optional

from pydantic import BaseModel, Field, root_validator
from pydantic import constr, BaseModel, Field, root_validator

from stac_pydantic.extensions import Extensions
from stac_pydantic.links import Link, Links
Expand All @@ -12,12 +12,13 @@ class Catalog(BaseModel):
https://github.com/radiantearth/stac-spec/blob/v1.0.0-beta.1/catalog-spec/catalog-spec.md
"""

id: str
description: str
stac_version: str = Field(STAC_VERSION, const=True)
id: constr(min_length=1)
description: constr(min_length=1)
stac_version: constr(min_length=1) = Field(STAC_VERSION, const=True)
links: Links
stac_extensions: Optional[List[str]]
title: Optional[str]
type: constr(min_length=1) = "catalog"
geospatial-jeff marked this conversation as resolved.
Show resolved Hide resolved

class Config:
use_enum_values = True
Expand Down
16 changes: 9 additions & 7 deletions stac_pydantic/collection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any, Dict, List, Optional, Union

from pydantic import BaseModel
from pydantic import constr, BaseModel

from stac_pydantic.catalog import Catalog
from stac_pydantic.shared import NumType, Provider
from stac_pydantic.shared import Asset, NumType, Provider


class SpatialExtent(BaseModel):
Expand Down Expand Up @@ -31,23 +31,25 @@ class Extent(BaseModel):
temporal: TimeInterval


class Stats(BaseModel):
class Range(BaseModel):
"""
https://github.com/radiantearth/stac-spec/blob/v1.0.0-beta.1/collection-spec/collection-spec.md#stats-object
"""

min: Union[NumType, str]
max: Union[NumType, str]
minimum: Union[NumType, str]
maximum: Union[NumType, str]


class Collection(Catalog):
"""
https://github.com/radiantearth/stac-spec/blob/v1.0.0-beta.1/collection-spec/collection-spec.md
"""

license: str
assets: Optional[Dict[str, Asset]]
license: constr(min_length=1)
extent: Extent
title: Optional[str]
keywords: Optional[List[str]]
providers: Optional[List[Provider]]
summaries: Optional[Dict[str, Union[Stats, List[Any]]]]
summaries: Optional[Dict[str, Union[Range, List[Any], Dict[str, Any]]]]
type: constr(min_length=1) = "collection"
geospatial-jeff marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 2 additions & 4 deletions stac_pydantic/extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from urllib.parse import urlparse

from .collection_assets import CollectionAssetExtension
from .datacube import DatacubeExtension
from .eo import ElectroOpticalExtension
from .item_assets import ItemAssetExtension
Expand All @@ -9,14 +8,13 @@
from .projection import ProjectionExtension
from .sar import SARExtension
from .sat import SatelliteExtension
from .sci import ScientificExtension
from .sci import ScientificCitationExtension
from .timestamps import TimestampsExtension
from .version import VersionExtension
from .view import ViewExtension


class Extensions:
collection_assets = CollectionAssetExtension
datacube = DatacubeExtension
eo = ElectroOpticalExtension
item_assets = ItemAssetExtension
Expand All @@ -25,7 +23,7 @@ class Extensions:
projection = ProjectionExtension
sar = SARExtension
sat = SatelliteExtension
scientific = ScientificExtension
scientific = ScientificCitationExtension
timestamps = TimestampsExtension
version = VersionExtension
view = ViewExtension
Expand Down
13 changes: 0 additions & 13 deletions stac_pydantic/extensions/collection_assets.py

This file was deleted.

10 changes: 5 additions & 5 deletions stac_pydantic/extensions/datacube.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import auto
from typing import Dict, List, Optional, Tuple, Union

from pydantic import BaseModel, Field
from pydantic import constr, BaseModel, Field

from stac_pydantic.shared import NumType
from stac_pydantic.utils import AutoValueEnum
Expand All @@ -17,7 +17,7 @@ class DimensionObject(BaseModel):
https://github.com/radiantearth/stac-spec/tree/v1.0.0-beta.1/extensions/datacube#additional-dimension-object
"""

type: str
type: constr(min_length=1)
description: Optional[str]
extent: Optional[Tuple[NumType, NumType]]
values: Optional[List[Union[NumType, str]]]
Expand All @@ -32,7 +32,7 @@ class HorizontalSpatialDimension(DimensionObject):
https://github.com/radiantearth/stac-spec/tree/v1.0.0-beta.1/extensions/datacube#horizontal-spatial-dimension-object
"""

type: str = Field("spatial", const=True)
type: constr(min_length=1) = Field("spatial", const=True)
axis: HorizontalAxis
extent: List[NumType]

Expand All @@ -45,15 +45,15 @@ class VerticalSpatialDimension(HorizontalSpatialDimension):
https://github.com/radiantearth/stac-spec/tree/v1.0.0-beta.1/extensions/datacube#vertical-spatial-dimension-object
"""

axis: str = Field("z", const=True)
axis: constr(min_length=1) = Field("z", const=True)


class TemporalDimension(DimensionObject):
"""
https://github.com/radiantearth/stac-spec/tree/v1.0.0-beta.1/extensions/datacube#temporal-dimension-object
"""

type: str = Field("temporal", const=True)
type: constr(min_length=1) = Field("temporal", const=True)
extent: Tuple[NumType, NumType]


Expand Down
4 changes: 2 additions & 2 deletions stac_pydantic/extensions/label.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import auto
from typing import List, Optional, Union

from pydantic import BaseModel, Field
from pydantic import constr, BaseModel, Field

from stac_pydantic.shared import NumType
from stac_pydantic.utils import AutoValueEnum
Expand Down Expand Up @@ -56,7 +56,7 @@ class LabelExtension(BaseModel):

properties: List[Union[str, None]] = Field(..., alias="label:properties")
classes: List[ClassObject] = Field(..., alias="label:classes")
description: str = Field(..., alias="label:description")
description: constr(min_length=1) = Field(..., alias="label:description")
type: LabelTypes = Field(..., alias="label:type")
tasks: Optional[List[str]] = Field(None, alias="label:tasks")
methods: Optional[List[str]] = Field(None, alias="label:methods")
Expand Down
8 changes: 4 additions & 4 deletions stac_pydantic/extensions/pc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import auto
from typing import List, Optional

from pydantic import BaseModel, Field
from pydantic import constr, BaseModel, Field

from stac_pydantic.shared import NumType
from stac_pydantic.utils import AutoValueEnum
Expand All @@ -22,7 +22,7 @@ class SchemaObject(BaseModel):
https://github.com/radiantearth/stac-spec/tree/v1.0.0-beta.1/extensions/pointcloud#schema-object
"""

name: str
name: constr(min_length=1)
size: int
type: ChannelTypes

Expand Down Expand Up @@ -51,8 +51,8 @@ class PointCloudExtension(BaseModel):
"""

count: int = Field(..., alias="pc:count")
type: str = Field(..., alias="pc:type")
encoding: str = Field(..., alias="pc:encoding")
type: constr(min_length=1) = Field(..., alias="pc:type")
encoding: constr(min_length=1) = Field(..., alias="pc:encoding")
schemas: List[SchemaObject] = Field(..., alias="pc:schemas")
density: Optional[int] = Field(None, alias="pc:density")
statistics: Optional[List[StatsObject]] = Field(None, alias="pc:statistics")
Expand Down
4 changes: 2 additions & 2 deletions stac_pydantic/extensions/projection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional, Union

from geojson_pydantic.geometries import Polygon
from geojson_pydantic.geometries import Geometry
from pydantic import BaseModel, Field

from stac_pydantic.shared import BBox, NumType
Expand All @@ -23,7 +23,7 @@ class ProjectionExtension(BaseModel):
epsg: Optional[Union[int]] = Field(..., alias="proj:epsg")
wk2: Optional[Union[str, None]] = Field(None, alias="proj:wk2")
projjson: Optional[Union[Dict[Any, Any], None]] = Field(None, alias="proj:projjson")
geometry: Optional[Polygon] = Field(None, alias="proj:geometry")
geometry: Optional[Geometry] = Field(None, alias="proj:geometry")
bbox: Optional[BBox] = Field(None, alias="proj:bbox")
centroid: Optional[CentroidObject] = Field(None, alias="proj:centroid")
shape: Optional[List[int]] = Field(None, alias="proj:shape")
Expand Down
4 changes: 2 additions & 2 deletions stac_pydantic/extensions/sar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import auto
from typing import List, Optional

from pydantic import BaseModel, Field
from pydantic import constr, BaseModel, Field

from stac_pydantic.shared import NumType
from stac_pydantic.utils import AutoValueEnum
Expand Down Expand Up @@ -50,7 +50,7 @@ class SARExtension(BaseModel):
https://github.com/radiantearth/stac-spec/tree/v1.0.0-beta.1/extensions/sar#sar-extension-specification
"""

instrument_mode: str = Field(..., alias="sar:instrument_mode")
instrument_mode: constr(min_length=1) = Field(..., alias="sar:instrument_mode")
center_frequency: Optional[NumType] = Field(None, alias="sar:center_frequency")
polarizations: Polarizations = Field(..., alias="sar:polarizations")
product_type: str = Field(..., alias="sar:product_type")
Expand Down
2 changes: 1 addition & 1 deletion stac_pydantic/extensions/sci.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PublicationObject(BaseModel):
citation: Optional[str]


class ScientificExtension(PublicationObject):
class ScientificCitationExtension(PublicationObject):
"""
https://github.com/radiantearth/stac-spec/tree/v1.0.0-beta.1/extensions/scientific#item-and-collection-fields
"""
Expand Down
4 changes: 2 additions & 2 deletions stac_pydantic/extensions/version.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Optional

from pydantic import BaseModel
from pydantic import constr, BaseModel


class VersionExtension(BaseModel):
"""
https://github.com/radiantearth/stac-spec/tree/v1.0.0-beta.1/extensions/version#item-properties-and-collection-fields
"""

version: str
version: constr(min_length=1)
deprecated: Optional[bool]
8 changes: 4 additions & 4 deletions stac_pydantic/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict, List, Optional, Tuple, Type, Union

from geojson_pydantic.features import Feature, FeatureCollection
from pydantic import BaseModel, Field, create_model, validator
from pydantic import constr, BaseModel, Field, create_model, validator
from pydantic.datetime_parse import parse_datetime
from pydantic.fields import FieldInfo

Expand Down Expand Up @@ -45,8 +45,8 @@ class Item(Feature):
https://github.com/radiantearth/stac-spec/blob/v1.0.0-beta.1/item-spec/item-spec.md
"""

id: str
stac_version: str = Field(STAC_VERSION, const=True)
id: constr(min_length=1)
stac_version: constr(min_length=1) = Field(STAC_VERSION, const=True)
properties: ItemProperties
assets: Dict[str, Asset]
links: Links
Expand All @@ -66,7 +66,7 @@ class ItemCollection(FeatureCollection):
https://github.com/radiantearth/stac-spec/blob/v1.0.0-beta.1/item-spec/itemcollection-spec.md
"""

stac_version: str = Field(STAC_VERSION, const=True)
stac_version: constr(min_length=1) = Field(STAC_VERSION, const=True)
features: List[Item]
stac_extensions: Optional[List[str]]
links: Links
Expand Down
7 changes: 4 additions & 3 deletions stac_pydantic/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any, Dict, Iterator, List, Optional, Union
from urllib.parse import urljoin

from pydantic import BaseModel, Field
from pydantic import constr, BaseModel, Field

from stac_pydantic.utils import AutoValueEnum

Expand Down Expand Up @@ -30,8 +30,8 @@ class Link(BaseModel):
https://github.com/radiantearth/stac-spec/blob/v1.0.0-beta.1/collection-spec/collection-spec.md#link-object
"""

href: str
rel: str
href: constr(min_length=1)
rel: constr(min_length=1)
type: Optional[str]
title: Optional[str]
# Label extension
Expand Down Expand Up @@ -95,3 +95,4 @@ class Relations(str, AutoValueEnum):
docs = auto()
tiles = auto()
search = auto()
preview = auto()
Loading