Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
from __future__ import annotations
from typing import Optional
from .SNCL import SNCL
ELEMENT_CONVERSIONS = {
# e-field
"E-E": "QE",
"E-N": "QN",
# derived indicies
"SQ": "SQ",
"SV": "SV",
"DIST": "DT",
"DST": "GD",
}
CHANNEL_CONVERSIONS = {
ELEMENT_CONVERSIONS[key]: key for key in ELEMENT_CONVERSIONS.keys()
}
class LegacySNCL(SNCL):
def get_sncl(
self,
station: str,
data_type: str,
interval: str,
element: str,
) -> LegacySNCL:
from .SNCLFactory import SNCLFactory
factory = SNCLFactory(data_format="legacy")
return LegacySNCL(
station=station,
network=self.network,
channel=factory.get_channel(element=element, interval=interval),
location=factory.get_location(element=element, data_type=data_type),
)
@property
def element(self) -> str:
predefined_element = self.__check_predefined_element()
element = self.__get_element()
return predefined_element or element
@property
def interval(self) -> str:
channel_start = self.channel[0]
if channel_start == "S":
return "second"
elif channel_start == "M":
return "minute"
elif channel_start == "H":
return "hour"
elif channel_start == "D":
return "day"
raise ValueError(f"Unexcepted interval code: {channel_start}")
def __get_element(self):
"""Translates channel/location to element"""
element_start = self.channel[2]
channel = self.channel
channel_middle = channel[1]
location_end = self.location[1]
if channel_middle in ["Q", "E"]:
element_end = "_Volt"
elif channel_middle == "Y":
element_end = "_Bin"
elif channel_middle == "K":
element_end = "_Temp"
elif location_end == "1":
element_end = "_Sat"
else:
element_end = ""
return element_start + element_end
def __check_predefined_element(self) -> Optional[str]:
channel = self.channel
channel_end = channel[1:]
if channel_end in CHANNEL_CONVERSIONS:
return CHANNEL_CONVERSIONS[channel_end]
return None