diff --git a/test/edge_test/MiniSeedFactory_test.py b/test/edge_test/MiniSeedFactory_test.py index 555635f360ca3a099380d10eb27556d7f94859f1..4858bc47510da1e9f259318693cbef3054871653 100644 --- a/test/edge_test/MiniSeedFactory_test.py +++ b/test/edge_test/MiniSeedFactory_test.py @@ -66,6 +66,39 @@ def test_get_calculated_timeseries(miniseed_factory, shu_u_metadata): assert_array_equal(result.data, expected) +def test__get_timeseries_add_empty_channels(miniseed_factory: MiniSeedFactory): + """test.edge_test.MiniSeedFactory_test.test__get_timeseries_add_empty_channels()""" + miniseed_factory.client.return_empty = True + starttime = UTCDateTime("2021-09-07") + endtime = UTCDateTime("2021-09-07T00:10:00Z") + trace = miniseed_factory._get_timeseries( + starttime=starttime, + endtime=endtime, + observatory="SHU", + channel="U", + type="variation", + interval="tenhertz", + add_empty_channels=True, + )[0] + assert_array_equal(trace.data, numpy.ones(trace.stats.npts) * numpy.nan) + assert trace.stats.starttime == starttime + assert trace.stats.endtime == endtime + assert ( + trace.stats.npts == ((endtime.timestamp - starttime.timestamp) * 10.0) + 1 + ) # tenhertz sampling rate + + with pytest.raises(IndexError): + trace = miniseed_factory._get_timeseries( + starttime=starttime, + endtime=endtime, + observatory="SHU", + channel="U", + type="variation", + interval="tenhertz", + add_empty_channels=False, + )[0] + + def test__get_timeseries_misaligned(misaligned_miniseed_factory: MiniSeedFactory): """test.edge_test.MiniSeedFactory_test.test__get_timeseries_misaligned()""" u_trace = misaligned_miniseed_factory._get_timeseries( diff --git a/test/edge_test/mseed_test_clients.py b/test/edge_test/mseed_test_clients.py index 9fd62bb797e5f515acce0f6dd7f8b4eb24bbfa2d..d706113d2968582962b71e927a53dfe456f8b286 100644 --- a/test/edge_test/mseed_test_clients.py +++ b/test/edge_test/mseed_test_clients.py @@ -7,7 +7,13 @@ from geomagio.edge import SNCL class MockMiniSeedClient(Client): - """replaces default obspy miniseed client's get_waveforms method to return trace of ones""" + """replaces default obspy miniseed client's get_waveforms method to return trace of ones + + Note: includes 'return_empty' parameter to simulate situations where no data is received + """ + + def __init__(self, return_empty: bool = False): + self.return_empty = return_empty def get_waveforms( self, @@ -18,6 +24,8 @@ class MockMiniSeedClient(Client): starttime: UTCDateTime, endtime: UTCDateTime, ): + if self.return_empty: + return Stream() sncl = SNCL( station=station, network=network, @@ -42,7 +50,8 @@ class MockMiniSeedClient(Client): class MisalignedMiniSeedClient(MockMiniSeedClient): """mock client that adds an offset value to endtime""" - def __init__(self, increment: int = 1): + def __init__(self, return_empty: bool = False, increment: int = 1): + super().__init__(return_empty=return_empty) self.increment = increment self.offset = 0