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

20 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 ElementTree as et 

6 

7import numpy as np 

8import pandas as pd 

9from pydantic import Field, field_validator 

10 

11from mt_metadata.common import Software 

12from mt_metadata.common.mttime import MTime 

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

14 

15 

16# ===================================================== 

17class ProcessingSoftware(Software): 

18 last_mod: Annotated[ 

19 MTime | str | float | int | np.datetime64 | pd.Timestamp | None, 

20 Field( 

21 default_factory=lambda: MTime(time_stamp=None), 

22 description="Date the software was last modified", 

23 alias=None, 

24 json_schema_extra={ 

25 "units": None, 

26 "required": False, 

27 "examples": ["2020-01-01"], 

28 }, 

29 ), 

30 ] 

31 

32 @field_validator("last_mod", mode="before") 

33 @classmethod 

34 def validate_last_mod( 

35 cls, field_value: MTime | float | int | np.datetime64 | pd.Timestamp | str 

36 ): 

37 if isinstance(field_value, MTime): 

38 return field_value 

39 return MTime(time_stamp=field_value) 

40 

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

42 """ 

43 Read processing software information from a dictionary. 

44 

45 Parameters 

46 ---------- 

47 input_dict : dict 

48 A dictionary containing processing software information. 

49 """ 

50 helpers._read_element(self, input_dict, "processing_software") 

51 

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

53 """Convert the processing software information to XML format. 

54 

55 Parameters 

56 ---------- 

57 string : bool, optional 

58 If True, return the XML as a string. If False, return an ElementTree element. 

59 required : bool, optional 

60 If True, include all required fields in the XML. 

61 

62 Returns 

63 ------- 

64 str | et.Element 

65 The XML representation of the processing software information. 

66 """ 

67 

68 return helpers.to_xml( 

69 self, 

70 string=string, 

71 required=required, 

72 order=["name", "last_mod", "author"], 

73 )