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

16 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.base.helpers import element_to_string 

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

12 

13 

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

15class PeriodRange(MetadataBase): 

16 min: Annotated[ 

17 float, 

18 Field( 

19 default=0.0, 

20 description="minimum period", 

21 alias=None, 

22 json_schema_extra={ 

23 "units": "samples per second", 

24 "required": True, 

25 "examples": ['"4.5E-5"'], 

26 }, 

27 ), 

28 ] 

29 

30 max: Annotated[ 

31 float, 

32 Field( 

33 default=0.0, 

34 description="maxmimu period", 

35 alias=None, 

36 json_schema_extra={ 

37 "units": "samples per second", 

38 "required": True, 

39 "examples": ['"4.5E5"'], 

40 }, 

41 ), 

42 ] 

43 

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

45 """ 

46 Read the period_range element from the input dictionary. 

47 

48 Parameters 

49 ---------- 

50 input_dict : dict 

51 The input dictionary containing the period_range element. 

52 """ 

53 helpers._read_element(self, input_dict, "period_range") 

54 

55 def to_xml(self, string=False, required=True) -> et.Element | str: 

56 """ 

57 Convert the period_range element to XML. 

58 

59 Parameters 

60 ---------- 

61 string : bool, optional 

62 Whether to return the XML as a string, by default False 

63 required : bool, optional 

64 Whether the element is required, by default True 

65 

66 Returns 

67 ------- 

68 et.Element | str 

69 The XML representation of the period_range element. 

70 """ 

71 

72 root = et.Element( 

73 self.__class__.__name__, 

74 { 

75 "min": f"{self.min:<16.5E}".strip(), 

76 "max": f"{self.max:<16.5E}".strip(), 

77 }, 

78 ) 

79 if string: 

80 return element_to_string(root) 

81 return root