remove_files_dirs(self.infile)
remove_files_dirs(self.outroot)
def _setup_input_data(self, spikes):
with table_manager(self.infile, nomodify=False) as tb:
data = tb.getcell('FLOAT_DATA', 0)
for ipol in range(len(data)):
# base data by repeating 1 and -1 - this has mean=0, sigma=1
# base data by repeating 1 and -1 - this has mean=5, sigma=1
for ichan in range(len(data[0])):
data[ipol][ichan] = 1.0 if ichan % 2 == 0 else -1.0
data[ipol][ichan] = 5.0 + (1.0 if ichan % 2 == 0 else -1.0)
for chan, value in spikes:
tb.putcell('FLOAT_DATA', 0, data)
def _set_params(self, blfunc, outbl, clipniter, thres):
self.params['blfunc'] = blfunc
self.params['blformat'] = 'csv' if outbl else ''
self.params['clipniter'] = clipniter
self.params['clipthresh'] = thres
f.write(f'1,1,,{clipniter},{thres},false,,,,,cspline,,1,[]')
def _run_test(self, blfunc='poly', spikes=[(4000, 100000.0)], thres=3.0, ifclipped=True):
self._setup_input_data(spikes=spikes)
lst = [(outbl, clipniter) for outbl in bools for clipniter in [0, 1]]
for outbl, clipniter in lst:
self._exec_sdbaseline(blfunc, outbl, clipniter, thres)
# if clipping is turned on, output of sdbaseline must be identical
# when clipping is turned on, output of sdbaseline must be identical
# regardless of whether blformat is empty or not
self.assertTrue(np.allclose(self._result(False, 1), self._result(True, 1)),
msg='unexpected result; result differs with different blformat.')
# with iterative clipping, output of sdbaseline must be different from that
# when clipping is turned off, output of sdbaseline must be identical
# regardless of whether blformat is empty or not
self.assertTrue(np.allclose(self._result(False, 0), self._result(True, 0)),
msg='unexpected result; result differs with different blformat.')
# when clipping is turned on, output of sdbaseline must be different from that
# without clipping, regardless of whether blformat is empty or not
self.assertFalse(np.allclose(self._result(blout, 1), self._result(blout, 0)),
msg='unexpected result; clipping is not working.')
self.assertTrue(np.allclose(self._result(blout, 1), self._result(blout, 0)),
msg='unexpected result; clipping is done.')
def _run_test_multiple_clipping(self, spikes, thres=3.0):
# using a data with two spikes with different values.
# this test is to confirm if the larger spike is clipped in the first turn
# and if the smaller spike is clipped in the second turn
# and if no more data is clipped afterwards.
self._setup_input_data(spikes=[(2000, 1000.0), (4000, 100000.0)])
for niter in range(maxiter):
self._exec_sdbaseline(blfunc='poly', outbl=True, clipniter=niter, thres=thres)
self._exec_sdbaseline(blfunc='poly', outbl=outbl, clipniter=niter, thres=thres)
# checking for every iteration if output spectrum is identical
# regardless of whether bloutput is empty or not
self.assertTrue(np.allclose(self._result(False, niter), self._result(True, niter)),
msg='unexpected result; result differs with different blformat.')
# checking for every iteration if output mask is correct
answer_mask_before = '[[0;8191]]'
self.assertEqual(self._resmask(0), answer_mask_before)
answer_mask_after_1clip = '[[0;3999];[4001;8191]]' # channel 4000 is clipped
self.assertEqual(self._resmask(1), answer_mask_after_1clip)
answer_mask_after_2clip = '[[0;1999];[2001;3999];[4001;8191]]' # channel 2000 is clipped
for i in range(2, maxiter):
self.assertEqual(self._resmask(i), answer_mask_after_2clip)
# test000 : to confirm if clipping works regardless of blformat when blfunc='poly'