From 925e24701fdd922c9ac4f381339f1caf85927c4f Mon Sep 17 00:00:00 2001 From: Deepak Chandan Date: Wed, 21 Feb 2024 16:51:43 -0500 Subject: [PATCH 1/3] updating cmip6 schema URI --- STACpopulator/extensions/cmip6.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/STACpopulator/extensions/cmip6.py b/STACpopulator/extensions/cmip6.py index 1957571..296a020 100644 --- a/STACpopulator/extensions/cmip6.py +++ b/STACpopulator/extensions/cmip6.py @@ -36,7 +36,7 @@ # FIXME: below reference (used as ID in the schema itself) should be updated once the extension is officially released # SCHEMA_URI: str = "https://stac-extensions.github.io/cmip6/v1.0.0/schema.json" # below is the temporary resolvable URI -SCHEMA_URI: str = "https://raw.githubusercontent.com/TomAugspurger/cmip6/main/json-schema/schema.json" +SCHEMA_URI: str = "https://raw.githubusercontent.com/dchandan/stac-extension-cmip6/main/json-schema/schema.json" PREFIX = f"{get_args(SchemaName)[0]}:" # CMIP6 controlled vocabulary (CV) From 3119a646c0fe206080b23024ee8949b8a38b8936 Mon Sep 17 00:00:00 2001 From: Deepak Chandan Date: Wed, 21 Feb 2024 16:51:51 -0500 Subject: [PATCH 2/3] black --- STACpopulator/extensions/cmip6.py | 43 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/STACpopulator/extensions/cmip6.py b/STACpopulator/extensions/cmip6.py index 296a020..46f4edb 100644 --- a/STACpopulator/extensions/cmip6.py +++ b/STACpopulator/extensions/cmip6.py @@ -7,28 +7,40 @@ List, Literal, MutableMapping, + Optional, Type, TypeVar, Union, - Optional, cast, - get_args + get_args, ) -import pystac import pyessv -from pydantic import AnyHttpUrl, BaseModel, ConfigDict, Field, FieldValidationInfo, field_validator +import pystac +from pydantic import ( + AnyHttpUrl, + BaseModel, + ConfigDict, + Field, + FieldValidationInfo, + field_validator, +) from pydantic.fields import FieldInfo from pystac.extensions import item_assets +from pystac.extensions.base import S # generic pystac.STACObject from pystac.extensions.base import ( ExtensionManagementMixin, PropertiesExtension, SummariesExtension, - S, # generic pystac.STACObject ) from STACpopulator.models import AnyGeometry -from STACpopulator.stac_utils import ServiceType, collection2literal, ncattrs_to_bbox, ncattrs_to_geometry +from STACpopulator.stac_utils import ( + ServiceType, + collection2literal, + ncattrs_to_bbox, + ncattrs_to_geometry, +) T = TypeVar("T", pystac.Collection, pystac.Item, pystac.Asset, item_assets.AssetDefinition) @@ -240,9 +252,7 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "CMIP6Extension[T]": raise pystac.ExtensionTypeError(cls._ext_error_message(obj)) @classmethod - def summaries( - cls, obj: pystac.Collection, add_if_missing: bool = False - ) -> "SummariesCMIP6Extension": + def summaries(cls, obj: pystac.Collection, add_if_missing: bool = False) -> "SummariesCMIP6Extension": """Returns the extended summaries object for the given collection.""" cls.ensure_has_extension(obj, add_if_missing) return SummariesCMIP6Extension(obj) @@ -278,19 +288,14 @@ def get_assets( return { key: asset for key, asset in self.item.get_assets().items() - if ( - service_type is ServiceType and service_type.value in asset.extra_fields - ) - or any( - ServiceType.from_value(field, default=None) is ServiceType - for field in asset.extra_fields - ) + if (service_type is ServiceType and service_type.value in asset.extra_fields) + or any(ServiceType.from_value(field, default=None) is ServiceType for field in asset.extra_fields) } def __repr__(self) -> str: return f"" - - + + class ItemAssetsCMIP6Extension(CMIP6Extension[item_assets.AssetDefinition]): properties: dict[str, Any] asset_defn: item_assets.AssetDefinition @@ -334,6 +339,7 @@ class SummariesCMIP6Extension(SummariesExtension): the ``summaries`` field of a :class:`~pystac.Collection` to include properties defined in the :stac-ext:`CMIP6 `. """ + def _check_cmip6_property(self, prop: str) -> FieldInfo: try: return CMIP6Properties.model_fields[prop] @@ -363,6 +369,5 @@ def __setattr__(self, prop, value): class CollectionCMIP6Extension(CMIP6Extension[pystac.Collection]): - def __init__(self, collection: pystac.Collection): self.collection = collection From 56c8bc4500191fa853e0ba2cecdcf7224fdb5c6e Mon Sep 17 00:00:00 2001 From: Deepak Chandan Date: Wed, 21 Feb 2024 16:56:07 -0500 Subject: [PATCH 3/3] update schema in test file --- tests/data/stac_item_testdata_xclim_cmip6_ncml.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/stac_item_testdata_xclim_cmip6_ncml.json b/tests/data/stac_item_testdata_xclim_cmip6_ncml.json index 2ff83d1..d253774 100644 --- a/tests/data/stac_item_testdata_xclim_cmip6_ncml.json +++ b/tests/data/stac_item_testdata_xclim_cmip6_ncml.json @@ -121,6 +121,6 @@ 89.74176788330078 ], "stac_extensions": [ - "https://raw.githubusercontent.com/TomAugspurger/cmip6/main/json-schema/schema.json" + "https://raw.githubusercontent.com/dchandan/stac-extension-cmip6/main/json-schema/schema.json" ] }