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

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 

5from xml.etree import cElementTree as et 

6 

7from pydantic import Field 

8 

9from mt_metadata.base import MetadataBase 

10from mt_metadata.common.enumerations import ChannelOrientationEnum 

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

12 

13 

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

15 

16 

17class Orientation(MetadataBase): 

18 angle_to_geographic_north: Annotated[ 

19 float, 

20 Field( 

21 default=0.0, 

22 description="Angle to geographic north of the station orientation", 

23 alias=None, 

24 json_schema_extra={ 

25 "units": "degrees", 

26 "required": True, 

27 "examples": [0], 

28 }, 

29 ), 

30 ] 

31 

32 layout: Annotated[ 

33 ChannelOrientationEnum, 

34 Field( 

35 default=ChannelOrientationEnum.orthogonal, 

36 description="Orientation of channels relative to each other", 

37 alias=None, 

38 json_schema_extra={ 

39 "units": None, 

40 "required": True, 

41 "examples": ["orthogonal"], 

42 }, 

43 ), 

44 ] 

45 

46 def read_dict(self, input_dict): 

47 """ 

48 

49 :param input_dict: DESCRIPTION 

50 :type input_dict: TYPE 

51 :return: DESCRIPTION 

52 :rtype: TYPE 

53 

54 """ 

55 element_dict = {self._class_name: input_dict[self._class_name]} 

56 if isinstance(element_dict[self._class_name], str): 

57 element_dict[self._class_name] = {"layout": element_dict[self._class_name]} 

58 

59 self.from_dict(element_dict) 

60 

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

62 """ 

63 Overwrite to XML to follow EMTF XML format 

64 

65 :param string: DESCRIPTION, defaults to False 

66 :type string: TYPE, optional 

67 :param required: DESCRIPTION, defaults to True 

68 :type required: TYPE, optional 

69 :return: DESCRIPTION 

70 :rtype: TYPE 

71 

72 """ 

73 

74 if self.layout == "orthogonal": 

75 if self.angle_to_geographic_north is None: 

76 self.angle_to_geographic_north = 0.0 

77 root = et.Element( 

78 self.__class__.__name__.capitalize(), 

79 {"angle_to_geographic_north": f"{self.angle_to_geographic_north:.3f}"}, 

80 ) 

81 root.text = self.layout 

82 else: 

83 root = et.Element(self.__class__.__name__.capitalize()) 

84 root.text = self.layout 

85 

86 if not string: 

87 return root 

88 else: 

89 return helpers.element_to_string(root)