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

24 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 

5from xml.etree import cElementTree as et 

6 

7from pydantic import Field, HttpUrl 

8 

9from mt_metadata.base import MetadataBase 

10from mt_metadata.common.enumerations import ArrayDTypeEnum, EstimateIntentionEnum 

11from mt_metadata.transfer_functions.io.emtfxml.metadata import helpers 

12 

13 

14# ===================================================== 

15 

16 

17class Estimate(MetadataBase): 

18 name: Annotated[ 

19 str, 

20 Field( 

21 default="", 

22 description="Name of the statistical estimate", 

23 alias=None, 

24 json_schema_extra={ 

25 "units": None, 

26 "required": True, 

27 "examples": ["var"], 

28 }, 

29 ), 

30 ] 

31 

32 type: Annotated[ 

33 ArrayDTypeEnum, 

34 Field( 

35 default="", 

36 description="Type of number contained in the estimate", 

37 alias=None, 

38 json_schema_extra={ 

39 "units": None, 

40 "required": True, 

41 "examples": ["real"], 

42 }, 

43 ), 

44 ] 

45 

46 description: Annotated[ 

47 str, 

48 Field( 

49 default="", 

50 description="Description of the statistical estimate", 

51 alias=None, 

52 json_schema_extra={ 

53 "units": None, 

54 "required": True, 

55 "examples": ["this is an estimate"], 

56 }, 

57 ), 

58 ] 

59 

60 external_url: Annotated[ 

61 HttpUrl, 

62 Field( 

63 default="", 

64 description="Full path to external link that has additional information", 

65 alias=None, 

66 json_schema_extra={ 

67 "units": None, 

68 "required": True, 

69 "examples": ["http://www.iris.edu/dms/products/emtf/variance.html"], 

70 }, 

71 ), 

72 ] 

73 

74 intention: Annotated[ 

75 EstimateIntentionEnum, 

76 Field( 

77 default="", 

78 description="The intension of the statistical estimate", 

79 alias=None, 

80 json_schema_extra={ 

81 "units": None, 

82 "required": True, 

83 "examples": ["error estimate"], 

84 }, 

85 ), 

86 ] 

87 

88 tag: Annotated[ 

89 str, 

90 Field( 

91 default="", 

92 description="A useful tag for the estimate", 

93 alias=None, 

94 json_schema_extra={ 

95 "units": None, 

96 "required": True, 

97 "examples": ["tipper"], 

98 }, 

99 ), 

100 ] 

101 

102 def read_dict(self, input_dict: dict) -> None: 

103 """ 

104 

105 :param input_dict: input dictionary containing estimate data 

106 :type input_dict: dict 

107 :return: None 

108 :rtype: None 

109 

110 """ 

111 helpers._read_element(self, input_dict, "estimate") 

112 

113 def to_xml(self, string: bool = False, required: bool = True): 

114 """ 

115 

116 :param string: return string representation, defaults to False 

117 :type string: bool, optional 

118 :param required: include only required fields, defaults to True 

119 :type required: bool, optional 

120 :return: XML representation of the estimate 

121 :rtype: str | Element 

122 

123 """ 

124 

125 root = et.Element( 

126 self.__class__.__name__.capitalize(), 

127 {"name": self.name.upper(), "type": self.type}, 

128 ) 

129 

130 et.SubElement(root, "Description").text = self.description 

131 et.SubElement(root, "ExternalUrl").text = ( 

132 str(self.external_url) if self.external_url else "" 

133 ) 

134 et.SubElement(root, "Intention").text = self.intention 

135 et.SubElement(root, "tag").text = self.tag 

136 

137 if string: 

138 return helpers.element_to_string(root) 

139 return root