diff --git a/geomagio/algorithm/FilterAlgorithm.py b/geomagio/algorithm/FilterAlgorithm.py index 085222026f6820d57a6b0dc1ea099920e739ba8a..66920c8cc8b9bb4716c5faf851a61bcdd31e2e9c 100644 --- a/geomagio/algorithm/FilterAlgorithm.py +++ b/geomagio/algorithm/FilterAlgorithm.py @@ -81,7 +81,7 @@ class FilterAlgorithm(Algorithm): trace_channels = [] for trace in stream: - trace_channels += trace.stats.channel + trace_channels += [trace.stats.channel] trace_chan_dict = dict(zip(trace_channels, self.outchannels)) @@ -92,9 +92,10 @@ class FilterAlgorithm(Algorithm): filtered = self.firfilter(data, self.window, step) stats=Stats(trace.stats) - stats.channel = trace_chan_dict[trace.stats.channels] - stats.delta = trace.delta*step - stats.pop('processing') + stats.channel = trace_chan_dict[stats.channel] + stats.delta = stats.delta*step + if 'processing' in stats: + stats.pop('processing') stats.npts = filtered.shape[0] trace_out = self.create_trace( stats.channel, stats, filtered) @@ -140,7 +141,7 @@ class FilterAlgorithm(Algorithm): as_weight_sums = np.dot(window, (~as_masked.mask).T) # mark the output locations as 'bad' that have missing input weights # that sum to greater than - as_invalid_masked = np.ma.masked_greater(as_weight_sums, allowed_bad) + as_invalid_masked = np.ma.masked_less(as_weight_sums, 1 - allowed_bad) # apply filter, using masked version of dot (in 3.5 and above, there # seems to be a move toward np.matmul and/or @ operator as opposed to diff --git a/test/algorithm_test/FilterAlgorithm_test.py b/test/algorithm_test/FilterAlgorithm_test.py index 18aadb8933d1dcebe82199d5e7b8aaa31a1cf0bf..c5d8412ef7af76361b925ae5a7cb7c3ae4086b93 100644 --- a/test/algorithm_test/FilterAlgorithm_test.py +++ b/test/algorithm_test/FilterAlgorithm_test.py @@ -13,8 +13,10 @@ def test_process(): # load boulder Jan 16 files from /etc/ directory min_iaga2002_file = open('etc/filter/BOU20180901vmin.min') min_iaga2002_string = min_iaga2002_file.read() + min_iaga2002_file.close() sec_iaga2002_file = open('etc/filter/BOU20180901vsec.sec') sec_iaga2002_string = sec_iaga2002_file.read() + sec_iaga2002_file.close() factory = i2.IAGA2002Factory() min = factory.parse_string(min_iaga2002_string) sec = factory.parse_string(sec_iaga2002_string) @@ -25,19 +27,19 @@ def test_process(): filt_bou = a.process(sec) - # unpack channels from loaded adjusted data file + # unpack channels from loaded minutes data file u = min.select(channel='MVH')[0] v = min.select(channel='MVE')[0] w = min.select(channel='MVZ')[0] f = min.select(channel='MSF')[0] - # unpack channels from adjusted processing of raw data + # unpack channels from filtered data u_filt = filt_bou.select(channel='MVH')[0] v_filt = filt_bou.select(channel='MVE')[0] w_filt = filt_bou.select(channel='MVZ')[0] f_filt = filt_bou.select(channel='MSF')[0] for r in range(min[0].data.size): - assert_almost_equals(u.data[r], u_filt.data[r], 2) - assert_almost_equals(v.data[r], v_filt.data[r], 2) - assert_almost_equals(w.data[r], w_filt.data[r], 2) - assert_almost_equals(f.data[r], f_filt.data[r], 2) + assert_almost_equals(u.data[r], u_filt.data[r], 1) + assert_almost_equals(v.data[r], v_filt.data[r], 1) + assert_almost_equals(w.data[r], w_filt.data[r], 1) + assert_almost_equals(f.data[r], f_filt.data[r], 1)