diff --git a/geomagio/edge/FDSNSNCL.py b/geomagio/edge/FDSNSNCL.py index c1ff5e38c85e8e221821907806acfa0e137c7dd3..be8bdfcfa22c734b5ca6441b6a4772c96025e927 100644 --- a/geomagio/edge/FDSNSNCL.py +++ b/geomagio/edge/FDSNSNCL.py @@ -22,10 +22,11 @@ class FDSNSNCL(SNCL): ): raise ValueError(f"Unsupported data type: {data_type}") location = location or get_location(element=element, data_type=data_type) + return FDSNSNCL( station=station, network=network, - channel=get_iris_channel( + channel=get_FDSN_channel( element=element, data_type=data_type, interval=interval, @@ -44,11 +45,27 @@ class FDSNSNCL(SNCL): @property def element(self) -> str: if self.location == "40" and self.network == "IU": - return _get_iris_element(channel=self.channel) + return _get_FDSN_element(channel=self.channel) return super().element + + @property + def interval(self) -> str: + """Translates beginning of channel to interval""" + channel_start = self.channel[0] + if channel_start == "B": + return "tenhertz" + elif channel_start == "L": + return "second" + elif channel_start == "U": + return "minute" + elif channel_start == "R": + return "hour" + elif channel_start == "P": + return "day" + raise ValueError(f"Unexcepted interval code: {channel_start}") -def _get_iris_element(channel: str) -> str: +def _get_FDSN_element(channel: str) -> str: channel_end = channel[1:] if channel_end == "F1": return "V" @@ -59,7 +76,7 @@ def _get_iris_element(channel: str) -> str: raise ValueError(f"Unsupported channel: {channel}") -def get_iris_channel( +def get_FDSN_channel( element: str, data_type: DataType, interval: DataInterval, diff --git a/test/edge_test/FDSNSNCL_test.py b/test/edge_test/FDSNSNCL_test.py new file mode 100644 index 0000000000000000000000000000000000000000..448bc11c936cb8a8d7bec0124ff9f94bb317e4d5 --- /dev/null +++ b/test/edge_test/FDSNSNCL_test.py @@ -0,0 +1,159 @@ +import pytest + +from geomagio.edge import FDSNSNCL +from geomagio.edge.FDSNSNCL import get_FDSN_channel, get_location + + +def test_data_type(): + """edge_test.IRISSNCL_test.test_data_type()""" + assert ( + FDSNSNCL(station="ANMO", network="IU", channel="LF1", location="40").data_type + == "variation" + ) + + +def test_element(): + """edge_test.FDSNSNCL_test.test_element()""" + assert ( + FDSNSNCL(station="ANMO", network="IU", channel="LF1", location="40").element + == "V" + ) + assert ( + FDSNSNCL(station="ANMO", network="IU", channel="LF2", location="40").element + == "U" + ) + assert ( + FDSNSNCL(station="ANMO", network="IU", channel="LFZ", location="40").element + == "W" + ) + with pytest.raises(ValueError) as error: + FDSNSNCL(station="ANMO", network="IU", channel="LFH", location="40").element + assert error.value == "Unsupported channel LFH" + + +def test_get_FDSN_channel(): + """edge_test.FDSNSNCL_test.test_get_FDSN_channel()""" + assert ( + get_FDSN_channel( + element="E", + interval="second", + data_type="variation", + network="IU", + location="40", + ) + == "LF1" + ) + assert ( + get_FDSN_channel( + element="V", + interval="second", + data_type="variation", + network="IU", + location="40", + ) + == "LF1" + ) + assert ( + get_FDSN_channel( + element="H", + interval="second", + data_type="variation", + network="IU", + location="40", + ) + == "LF2" + ) + assert ( + get_FDSN_channel( + element="U", + interval="second", + data_type="variation", + network="IU", + location="40", + ) + == "LF2" + ) + assert ( + get_FDSN_channel( + element="W", + interval="second", + data_type="variation", + network="IU", + location="40", + ) + == "LFZ" + ) + # predefined channel + assert ( + get_FDSN_channel( + element="LFZ", + interval="second", + data_type="variation", + network="IU", + location="40", + ) + == "LFZ" + ) + with pytest.raises(ValueError) as error: + get_FDSN_channel( + element="D", + interval="second", + data_type="variation", + network="IU", + location="40", + ) + assert error.value == "Unsupported element: D" + + +def test_get_sncl(): + """edge_test.IRISSNCL_test.test_get_sncl()""" + assert FDSNSNCL.get_sncl( + data_type="variation", + element="H", + interval="second", + station="ANMO", + network="IU", + location="40", + ) == FDSNSNCL(station="ANMO", network="IU", channel="LF2", location="40") + with pytest.raises(ValueError) as error: + FDSNSNCL.get_sncl( + data_type="adjusted", + element="H", + interval="second", + station="ANMO", + network="IU", + location="40", + ) + assert error.value == "Unsupported data type: adjusted" + assert FDSNSNCL.get_sncl( + data_type="adjusted", + element="H", + interval="second", + station="BOU", + ) == FDSNSNCL(station="BOU", network="NT", channel="LFH", location="A0") + + +def test_interval(): + """edge_test.FDSNSNCL_test.test_interval()""" + assert ( + FDSNSNCL( + station="ANMO", + network="IU", + channel="LF1", + location="40", + ).interval + == "second" + ) + + +def test_parse_sncl(): + """edge_test.FDSNSNCL_test.test_parse_sncl()""" + assert FDSNSNCL( + station="ANMO", network="IU", channel="LF1", location="40" + ).parse_sncl() == { + "station": "ANMO", + "network": "IU", + "data_type": "variation", + "element": "V", + "interval": "second", + }