Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ transfer_functions \ io \ zonge \ metadata \ survey.py: 100%
25 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:11 -0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:11 -0800
1# =====================================================
2# Imports
3# =====================================================
4from enum import Enum
5from typing import Annotated
7from pydantic import Field, field_validator
8from pyproj import CRS
10from mt_metadata.base import MetadataBase
11from mt_metadata.common.enumerations import DataTypeEnum
14# =====================================================
17class ArrayEnum(str, Enum):
18 tensor = "tensor"
21class ProjEnum(str, Enum):
22 UTM = "UTM"
23 other = "other"
26class Survey(MetadataBase):
27 type: Annotated[
28 DataTypeEnum,
29 Field(
30 default=DataTypeEnum.NSAMT,
31 description="Type of EM survey",
32 alias=None,
33 json_schema_extra={
34 "units": None,
35 "required": True,
36 "examples": ["nsamt"],
37 },
38 ),
39 ]
41 array: Annotated[
42 ArrayEnum,
43 Field(
44 default=ArrayEnum.tensor,
45 description="Type of array",
46 alias=None,
47 json_schema_extra={
48 "units": None,
49 "required": True,
50 "examples": ["tensor"],
51 },
52 ),
53 ]
55 datum: Annotated[
56 str,
57 Field(
58 default="WGS84",
59 description="Datum of the location",
60 alias=None,
61 json_schema_extra={
62 "units": None,
63 "required": True,
64 "examples": ["WGS84"],
65 },
66 ),
67 ]
69 u_t_m_zone: Annotated[
70 int,
71 Field(
72 default=0,
73 description="UTM zone of location",
74 alias=None,
75 json_schema_extra={
76 "units": None,
77 "required": True,
78 "examples": ["12"],
79 },
80 ),
81 ]
83 proj: Annotated[
84 ProjEnum,
85 Field(
86 default=ProjEnum.UTM,
87 description="Projection of the location coordinates",
88 alias=None,
89 json_schema_extra={
90 "units": None,
91 "required": True,
92 "examples": ["UTM"],
93 },
94 ),
95 ]
97 @field_validator("datum", mode="before")
98 @classmethod
99 def validate_datum(cls, value: str | int) -> str:
100 """
101 Validate the datum value and convert it to the appropriate enum type.
102 """
103 try:
104 datum_crs = CRS.from_user_input(value)
105 return datum_crs.name
106 except Exception:
107 raise ValueError(
108 f"Invalid datum value: {value}. Must be a valid CRS string or identifier."
109 )