Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ transfer_functions \ io \ zonge \ metadata \ ch.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-10 00:11 -0800

1# ===================================================== 

2# Imports 

3# ===================================================== 

4from typing import Annotated 

5 

6from pydantic import Field, field_validator 

7 

8from mt_metadata.base import MetadataBase 

9 

10 

11# ===================================================== 

12class CH(MetadataBase): 

13 a_d_card_s_n: Annotated[ 

14 str | list[str] | None, 

15 Field( 

16 default=None, 

17 description="serial number of ad card for local and remote stations", 

18 alias=None, 

19 json_schema_extra={ 

20 "units": None, 

21 "required": False, 

22 "examples": ["6545BAC6,BE380864"], 

23 }, 

24 ), 

25 ] 

26 

27 gdp_box: Annotated[ 

28 str | list[str] | None, 

29 Field( 

30 default=None, 

31 description="Box number for local and remote stations", 

32 alias=None, 

33 json_schema_extra={ 

34 "units": None, 

35 "required": False, 

36 "examples": ["18,15"], 

37 }, 

38 ), 

39 ] 

40 

41 stn: Annotated[ 

42 str | list[str] | None, 

43 Field( 

44 default=None, 

45 description="station number of local and remote", 

46 alias=None, 

47 json_schema_extra={ 

48 "units": None, 

49 "required": False, 

50 "examples": ["1,2"], 

51 }, 

52 ), 

53 ] 

54 

55 number: Annotated[ 

56 str | list[str] | None, 

57 Field( 

58 default=None, 

59 description="channel number for local and coil number of remote", 

60 alias=None, 

61 json_schema_extra={ 

62 "units": None, 

63 "required": False, 

64 "examples": ["1, 2284"], 

65 }, 

66 ), 

67 ] 

68 

69 cmp: Annotated[ 

70 str | list[str] | None, 

71 Field( 

72 default=None, 

73 description="component of local and remote stations", 

74 alias=None, 

75 json_schema_extra={ 

76 "units": None, 

77 "required": False, 

78 "examples": ["ex,hy"], 

79 }, 

80 ), 

81 ] 

82 

83 c_res: Annotated[ 

84 str | list[str] | None, 

85 Field( 

86 default=None, 

87 description="contact resistance for local and remote sensors", 

88 alias=None, 

89 json_schema_extra={ 

90 "units": None, 

91 "required": False, 

92 "examples": ["0,0"], 

93 }, 

94 ), 

95 ] 

96 

97 azimuth: Annotated[ 

98 str | list[str] | None, 

99 Field( 

100 default=None, 

101 description="azimuth for local and remote sensors", 

102 alias=None, 

103 json_schema_extra={ 

104 "units": None, 

105 "required": False, 

106 "examples": ["12.1,12.1"], 

107 }, 

108 ), 

109 ] 

110 

111 incl: Annotated[ 

112 str | list[str] | None, 

113 Field( 

114 default=None, 

115 description="Inclination ", 

116 alias=None, 

117 json_schema_extra={ 

118 "units": None, 

119 "required": False, 

120 "examples": ["335754.685:4263553.435:1650.2"], 

121 }, 

122 ), 

123 ] 

124 

125 @field_validator( 

126 "a_d_card_s_n", 

127 "gdp_box", 

128 "stn", 

129 "number", 

130 "cmp", 

131 "c_res", 

132 "azimuth", 

133 "incl", 

134 mode="before", 

135 ) 

136 @classmethod 

137 def validate_comma_separated_fields(cls, v): 

138 """ 

139 Validate fields that may contain comma-separated values. 

140 Returns a list when commas are found, otherwise returns the string as-is. 

141 """ 

142 if v is None: 

143 return None 

144 if isinstance(v, list): 

145 return v 

146 if isinstance(v, str): 

147 # If the value contains a comma, split into a list 

148 if "," in v: 

149 parts = [part.strip() for part in v.split(",") if part.strip()] 

150 # Return list if we have multiple parts, otherwise return single string 

151 return parts if len(parts) > 1 else (parts[0] if parts else None) 

152 return v 

153 return str(v)