Skip to content
Snippets Groups Projects
Commit 6f9391c6 authored by Kien Le's avatar Kien Le
Browse files

Add tests for trim_downsample_SOHChan

parent a286221e
No related branches found
No related tags found
1 merge request!27Draft: Add tests for functions in handling_data.py
...@@ -33,7 +33,8 @@ from sohstationviewer.model.handling_data import ( ...@@ -33,7 +33,8 @@ from sohstationviewer.model.handling_data import (
sortData, sortData,
squash_gaps, squash_gaps,
downsample, downsample,
chunk_minmax chunk_minmax,
trim_downsample_SOHChan
) )
from sohstationviewer.model.reftek.from_rt2ms.core import Reftek130 from sohstationviewer.model.reftek.from_rt2ms.core import Reftek130
...@@ -854,3 +855,119 @@ class TestChunkMinmax(TestCase): ...@@ -854,3 +855,119 @@ class TestChunkMinmax(TestCase):
times, data = chunk_minmax(self.times, self.data, req_points) times, data = chunk_minmax(self.times, self.data, req_points)
self.assertEqual(times.size, 0) self.assertEqual(times.size, 0)
self.assertEqual(data.size, 0) self.assertEqual(data.size, 0)
class TestTrimDownsampleSohChan(TestCase):
@staticmethod
def downsample(times, data, req_points):
return times, data
def setUp(self) -> None:
self.channel_info = {}
self.org_trace = {
'times': np.arange(1000),
'data': np.arange(1000)
}
self.channel_info['orgTrace'] = self.org_trace
self.start_time = 250
self.end_time = 750
self.first_time = False
patcher = patch('sohstationviewer.model.handling_data.downsample')
self.addCleanup(patcher.stop)
self.mock_downsample = patcher.start()
self.mock_downsample.side_effect = self.downsample
def num_points_outside_time_range(self, start_time, end_time):
return len([data_point
for data_point in self.org_trace['times']
if not start_time <= data_point <= end_time])
def test_mseed_start_time_later_than_times_data(self):
self.start_time = 250
self.end_time = 1250
trim_downsample_SOHChan(self.channel_info, self.start_time,
self.end_time, self.first_time)
self.assertGreaterEqual(self.channel_info['times'].min(),
self.start_time)
self.assertEqual(
self.org_trace['times'].size - self.channel_info['times'].size,
self.num_points_outside_time_range(self.start_time, self.end_time)
)
def test_mseed_end_time_earlier_than_times_data(self):
self.start_time = -250
self.end_time = 750
trim_downsample_SOHChan(self.channel_info, self.start_time,
self.end_time, self.first_time)
self.assertLessEqual(self.channel_info['times'].max(),
self.end_time)
self.assertEqual(
self.org_trace['times'].size - self.channel_info['times'].size,
self.num_points_outside_time_range(self.start_time, self.end_time)
)
def test_mseed_start_time_earlier_than_times_data(self):
self.start_time = -250
self.end_time = 750
trim_downsample_SOHChan(self.channel_info, self.start_time,
self.end_time, self.first_time)
self.assertEqual(self.channel_info['times'].min(),
self.channel_info['orgTrace']['times'].min())
self.assertEqual(
self.org_trace['times'].size - self.channel_info['times'].size,
self.num_points_outside_time_range(self.start_time, self.end_time)
)
def test_mseed_end_time_later_than_times_data(self):
self.start_time = 250
self.end_time = 1250
trim_downsample_SOHChan(self.channel_info, self.start_time,
self.end_time, self.first_time)
self.assertEqual(self.channel_info['times'].max(),
self.channel_info['orgTrace']['times'].max())
self.assertEqual(
self.org_trace['times'].size - self.channel_info['times'].size,
self.num_points_outside_time_range(self.start_time, self.end_time)
)
def test_mseed_times_data_contained_in_time_range(self):
self.start_time = -250
self.end_time = 1250
trim_downsample_SOHChan(self.channel_info, self.start_time,
self.end_time, self.first_time)
np.testing.assert_array_equal(self.channel_info['times'],
self.org_trace['times'])
def test_mseed_time_range_is_the_same_as_times_data(self):
self.start_time = 0
self.end_time = 999
trim_downsample_SOHChan(self.channel_info, self.start_time,
self.end_time, self.first_time)
np.testing.assert_array_equal(self.channel_info['times'],
self.org_trace['times'])
def test_mseed_time_range_does_not_overlap_times_data(self):
self.start_time = 2000
self.end_time = 3000
trim_downsample_SOHChan(self.channel_info, self.start_time,
self.end_time, self.first_time)
self.assertEqual(self.channel_info['times'].size, 0)
self.assertEqual(self.channel_info['data'].size, 0)
def test_mseed_data_is_downsampled(self):
trim_downsample_SOHChan(self.channel_info, self.start_time,
self.end_time, self.first_time)
self.assertTrue(self.mock_downsample.called)
def test_mseed_processed_data_is_stored_in_appropriate_location(self):
trim_downsample_SOHChan(self.channel_info, self.start_time,
self.end_time, self.first_time)
expected_keys = ('orgTrace', 'times', 'data')
self.assertTupleEqual(tuple(self.channel_info.keys()),
expected_keys)
@expectedFailure
def test_reftek(self):
self.fail()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment