Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
huard committed Sep 28, 2023
2 parents ee7a339 + dba86a5 commit 6d32e14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
STACpopulator.egg-info/
.vscode/
.venv/
jupyter/
jupyter/
.idea
.vscode
22 changes: 15 additions & 7 deletions STACpopulator/extensions/cmip6.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
"""CMIP6 extension based on https://stac-extensions.github.io/cmip6/v1.0.0/schema.json"""

from typing import Generic, TypeVar, Dict, Any, cast
import json
from typing import Generic, TypeVar, Union, cast

import pystac
from pystac.extensions.base import ExtensionManagementMixin, PropertiesExtension
from pystac.extensions.hooks import ExtensionHooks

from datetime import datetime
from datetime import date, datetime
from typing import Any, Dict, List, Literal
import pyessv
from pydantic import (AnyHttpUrl, BaseModel, Field, FieldValidationInfo, field_validator, model_serializer,
FieldSerializationInfo)
from pydantic import (
AnyHttpUrl,
FieldValidationInfo,
field_validator,
model_serializer,
)
from pydantic.networks import Url


from STACpopulator.stac_utils import ItemProperties
Expand Down Expand Up @@ -57,8 +63,8 @@ class Properties(ItemProperties, validate_assignment=True):
source: str
source_id: SourceID
source_type: List[SourceType]
sub_experiment: str | Literal["none"]
sub_experiment_id: SubExperimentID | Literal["none"]
sub_experiment: Union[str, Literal["none"]]
sub_experiment_id: Union[SubExperimentID, Literal["none"]]
table_id: TableID
variable_id: str
variant_label: str
Expand All @@ -73,6 +79,7 @@ class Properties(ItemProperties, validate_assignment=True):
grid: str
mip_era: str


@field_validator("initialization_index", "physics_index", "realization_index", "forcing_index", mode="before")
@classmethod
def first_item(cls, v: list, info: FieldValidationInfo):
Expand All @@ -94,7 +101,6 @@ def validate_version(cls, v: str, info: FieldValidationInfo):
return v



class CMIP6Extension(Generic[T], ExtensionManagementMixin[pystac.Item], PropertiesExtension):
"""An abstract class that can be used to extend the properties of a
:class:`~pystac.Item` with properties from the :stac-ext:`CMIP6 Extension <cmip6>`.
Expand Down Expand Up @@ -143,6 +149,7 @@ def ext(cls, obj: T, add_if_missing: bool = False):
else:
raise pystac.ExtensionTypeError(cls._ext_error_message(obj))


class ItemCMIP6Extension(CMIP6Extension[pystac.Item]):
"""A concrete implementation of :class:`DatacubeExtension` on an
:class:`~pystac.Item` that extends the properties of the Item to include properties
Expand All @@ -168,4 +175,5 @@ class CMIP6ExtensionHooks(ExtensionHooks):
prev_extension_ids = {"cmip6"}
stac_object_types = {pystac.STACObjectType.ITEM}


CMIP6_EXTENSION_HOOKS: ExtensionHooks = CMIP6ExtensionHooks()

0 comments on commit 6d32e14

Please sign in to comment.