Skip to content
Open
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
54 changes: 51 additions & 3 deletions src/eopf_geozarr/data_api/geozarr/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,64 @@
import io
import urllib
import urllib.request
from typing import Annotated, Any, Mapping, TypeVar
from dataclasses import dataclass
from typing import Annotated, Any, Mapping, Self, TypeVar

from cf_xarray.utils import parse_cf_standard_name_table
from pydantic import AfterValidator, BaseModel
from pydantic import AfterValidator, BaseModel, Field, model_validator
from pydantic.experimental.missing_sentinel import MISSING
from typing_extensions import Protocol, runtime_checkable
from typing_extensions import Final, Literal, Protocol, runtime_checkable

from eopf_geozarr.data_api.geozarr.projjson import ProjJSON
from eopf_geozarr.data_api.geozarr.types import ResamplingMethod


@dataclass(frozen=True)
class UNSET_TYPE:
"""
Sentinel value to indicate that a value is not set.
"""

...


UNSET = UNSET_TYPE()

GEO_PROJ_VERSION: Final = "0.1"


class ProjAttrs(BaseModel, extra="allow"):
"""
Zarr attributes for coordinate reference system (CRS) encoding.

Attributes
version: str
The version of the metadata.
code: str | None
Authority:Code identifier.
wkt2 : str | None
WKT2 (ISO 19162) representation of the CRS.
projjson: ProjJson | None
PROJJSON representation of the CRS.
bbox:
"""

version: Literal["0.1"] = "0.1"
code: str | None = Field(pattern="^[A-Z]+:[0-9]+$")
wkt2: str | None = None
projjson: ProjJSON | None
bbox: tuple[float, float, float, float] | UNSET_TYPE = UNSET
transform: tuple[float, float, float, float, float, float] | UNSET_TYPE = UNSET
# TODO: enclosing object must validate these properties against the arrays
spatial_dimensions: tuple[str, str] | UNSET_TYPE = UNSET

@model_validator(mode="after")
def check_one_of(self) -> Self:
if self.code is None and self.wkt2 is None and self.projjson is None:
raise ValueError("One of 'code', 'wkt2', or 'projjson' must be provided.")
return self


class BaseDataArrayAttrs(BaseModel, extra="allow"):
"""
Base attributes for a GeoZarr DataArray.
Expand Down
Loading