Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ transfer_functions \ tf \ statistical_estimate.py: 88%
32 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 typing import Annotated
6from pydantic import Field, field_validator
8from mt_metadata.base import MetadataBase
9from mt_metadata.common.enumerations import ArrayDTypeEnum
10from mt_metadata.common.units import get_unit_object
13# =====================================================
16class StatisticalEstimate(MetadataBase):
17 name: Annotated[
18 str,
19 Field(
20 default="",
21 description="Name of the statistical estimate",
22 alias=None,
23 json_schema_extra={
24 "units": None,
25 "required": True,
26 "examples": ["transfer function"],
27 },
28 ),
29 ]
31 data_type: Annotated[
32 ArrayDTypeEnum,
33 Field(
34 default="complex",
35 description="Type of number contained in the estimate",
36 alias=None,
37 json_schema_extra={
38 "units": None,
39 "required": True,
40 "examples": ["real"],
41 },
42 ),
43 ]
45 description: Annotated[
46 str,
47 Field(
48 default="",
49 description="Description of the statistical estimate",
50 alias=None,
51 json_schema_extra={
52 "units": None,
53 "required": True,
54 "examples": ["this is an estimate"],
55 },
56 ),
57 ]
59 input_channels: Annotated[
60 list[str] | str,
61 Field(
62 default=[],
63 description="List of input channels (sources)",
64 alias=None,
65 json_schema_extra={
66 "units": None,
67 "required": True,
68 "examples": ["hx, hy", ["hx", "hy"]],
69 },
70 ),
71 ]
73 output_channels: Annotated[
74 list[str] | str,
75 Field(
76 default=[],
77 description="List of output channels (response).",
78 alias=None,
79 json_schema_extra={
80 "units": None,
81 "required": True,
82 "examples": ["hx, hy", ["hx", "hy"]],
83 },
84 ),
85 ]
87 units: Annotated[
88 str,
89 Field(
90 default="",
91 description="Units of the estimate.",
92 alias=None,
93 json_schema_extra={
94 "units": None,
95 "required": True,
96 "examples": ["millivolts per kilometer per nanotesla"],
97 },
98 ),
99 ]
101 @field_validator("units", mode="before")
102 @classmethod
103 def validate_units(cls, value: str) -> str:
104 if value in [None, ""]:
105 return ""
106 try:
107 unit_object = get_unit_object(value)
108 return unit_object.name
109 except ValueError as error:
110 raise KeyError(error)
111 except KeyError as error:
112 raise KeyError(error)
114 @field_validator("input_channels", "output_channels", mode="before")
115 @classmethod
116 def validate_channels(cls, value: list[str] | str) -> list[str]:
117 """convert channels to a list of single channels"""
118 if isinstance(value, str):
119 value = [v.strip() for v in value.split(",")]
120 elif not isinstance(value, list):
121 raise TypeError(
122 f"Input channels must be a list of channels, not {type(value)}."
123 )
124 return value