Newer
Older
from typing import Optional
from ..geomag_types import DataInterval, DataType
from .SNCL import SNCL, get_channel, get_location, _get_channel_start
class IRISSNCL(SNCL):
@classmethod
def get_sncl(
cls,
data_type: DataType,
element: str,
interval: DataInterval,
station: str,
network: str = "NT",
location: Optional[str] = None,
) -> "IRISSNCL":
if (
network == "IU"
and location == "40"
and data_type not in ["40", "variation"] # ASL only supports variation data
):
raise ValueError(f"Unsupported data type: {data_type}")
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
location = location or get_location(element=element, data_type=data_type)
return IRISSNCL(
station=station,
network=network,
channel=get_iris_channel(
element=element,
data_type=data_type,
interval=interval,
network=network,
location=location,
),
location=location,
)
@property
def data_type(self) -> str:
if self.location == "40" and self.network == "IU":
return "variation"
return super().data_type
@property
def element(self) -> str:
if self.location == "40" and self.network == "IU":
return _get_iris_element(channel=self.channel)
return super().element
def _get_iris_element(channel: str) -> str:
channel_end = channel[1:]
if channel_end == "F1":
return "U"
elif channel_end == "F2":
return "V"
elif channel_end == "FZ":
return "W"
raise ValueError(f"Unsupported channel: {channel}")
def get_iris_channel(
element: str,
data_type: DataType,
interval: DataInterval,
network: Optional[str] = None,
location: Optional[str] = None,
) -> str:
if location == "40" and network == "IU":
return _get_channel_start(interval=interval) + _get_channel_end(element=element)
return get_channel(element=element, interval=interval, data_type=data_type)
def _get_channel_end(element: str) -> str:
if element in ["H", "U"]:
return "F1"
elif element in ["E", "V"]:
return "F2"
elif element in ["Z", "W"]:
return "FZ"
elif element[0:2] == "LF": # predefined element
return element[1:]
raise ValueError(f"Unsupported element: {element}")