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 RemoteRef(MetadataBase):
16 type: Annotated[
17 str,
18 Field(
19 default="",
20 description="type of remote referencing",
21 alias=None,
22 json_schema_extra={
23 "units": None,
24 "required": True,
25 "examples": ["robust multi-station remote referencing"],
26 },
27 ),
28 ]
29
30 def read_dict(self, input_dict):
31 """
32
33 :param input_dict: DESCRIPTION
34 :type input_dict: TYPE
35 :return: DESCRIPTION
36 :rtype: TYPE
37
38 """
39 helpers._read_element(self, input_dict, "remote_ref")
40
41 def to_xml(self, string: bool = False, required: bool = True) -> str | et.Element:
42 """
43 Convert the RemoteRef object to XML format.
44
45 Parameters
46 ----------
47 string : bool, optional
48 Whether to return the XML as a string (default is False).
49 required : bool, optional
50 Whether to include required fields (default is True).
51
52 Returns
53 -------
54 str | et.Element
55 The XML representation of the RemoteRef object.
56 """
57
58 if self.type is None:
59 self.type = ""
60
61 root = et.Element(self.__class__.__name__, {"type": self.type})
62 if string:
63 return element_to_string(root)
64 return root