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
2 changes: 1 addition & 1 deletion stac_pydantic/api/extensions/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ class SortExtension(BaseModel):
https://github.com/radiantearth/stac-api-spec/tree/master/extensions/sort#sort-api-extension
"""

field: str
field: const(min_length=1)
moradology marked this conversation as resolved.
Show resolved Hide resolved
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
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: 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
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
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
6 changes: 3 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
8 changes: 4 additions & 4 deletions stac_pydantic/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum, auto
from typing import List, Optional, Tuple, Union

from pydantic import BaseModel, Extra, Field
from pydantic import constr, confloat, BaseModel, Extra, Field

from stac_pydantic.extensions.eo import BandObject
from stac_pydantic.utils import AutoValueEnum
Expand Down Expand Up @@ -89,7 +89,7 @@ class Provider(BaseModel):
https://github.com/radiantearth/stac-spec/blob/v1.0.0-beta.1/collection-spec/collection-spec.md#provider-object
"""

name: str
name: constr(min_length=1)
description: Optional[str]
roles: Optional[List[str]]
url: Optional[str]
Expand All @@ -111,7 +111,7 @@ class StacCommonMetadata(BaseModel):
constellation: Optional[str] = Field(None, alias="constellation")
mission: Optional[str] = Field(None, alias="mission")
providers: Optional[List[Provider]] = Field(None, alias="providers")
gsd: Optional[NumType] = Field(None, alias="gsd")
gsd: Optional[confloat(gt=0)] = Field(None, alias="gsd")

class Config:
json_encoders = {datetime: lambda v: v.strftime(DATETIME_RFC339)}
Expand All @@ -122,7 +122,7 @@ class Asset(StacCommonMetadata):
https://github.com/radiantearth/stac-spec/blob/v1.0.0-beta.1/item-spec/item-spec.md#asset-object
"""

href: str
href: constr(min_length=1)
type: Optional[str]
title: Optional[str]
description: Optional[str]
Expand Down
2 changes: 1 addition & 1 deletion stac_pydantic/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
STAC_VERSION = "1.0.0-beta.2"
STAC_VERSION = "1.0.0"
Copy link
Collaborator Author

@moradology moradology Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change, if omitted, allows tests to complete successfully as the prior files all appear to be 1.0.0 compliant

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm rolling some example files that simply extend the previously working versions to use some 1.0.0 features. More canonical examples can be swapped in later if that's desirable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone ahead and folded the testing files within this repository