Add unittest for frame splitting action
This commit is contained in:
@@ -46,7 +46,7 @@ class MockEventData:
|
||||
# list of data packates containing previous events
|
||||
packets = np.recarray((1000,), dtype=PACKET_TYPE)
|
||||
packets.start_index = np.linspace(0, events.shape[0]-1, packets.shape[0], dtype=np.uint32)
|
||||
packets.time = np.linspace(1700000000000000000, 1700000000000000000+3_600_000_000,
|
||||
packets.time = np.linspace(1700000000000000000, 1700000000000000000+3_600_000_000_000,
|
||||
packets.shape[0], dtype=np.int64)
|
||||
|
||||
# chopper pulses within the measurement time
|
||||
@@ -58,7 +58,7 @@ class MockEventData:
|
||||
proton_current = np.recarray((50,), dtype=PC_TYPE)
|
||||
proton_current.current = 1500.0
|
||||
proton_current[np.random.randint(0, proton_current.shape[0]-1, 10)] = 0. # random time with no current
|
||||
proton_current.time = np.linspace(1700000000000000300, 1700000000000000000+3_600_000_000,
|
||||
proton_current.time = np.linspace(1700000000000000300, 1700000000000000000+3_600_000_000_000,
|
||||
proton_current.shape[0], dtype=np.int64)
|
||||
|
||||
self.data = AmorEventStream(events, packets, pulses, proton_current)
|
||||
@@ -420,20 +420,30 @@ class TestSimpleActions(TestCase):
|
||||
dtype=np.int32))
|
||||
|
||||
def test_merge_frames(self):
|
||||
action = MergeFrames(lamdaCut=0.0)
|
||||
action = MergeFrames(lamdaCut=0.0, preciseTime=False)
|
||||
action.perform_action(self.d)
|
||||
self.assertEqual(self.d.data.events.tof.shape, self.d.orig_data.events.tof.shape)
|
||||
np.testing.assert_array_compare(lambda x,y: x<=y, self.d.data.events.tof, self.d.orig_data.events.tof)
|
||||
self.assertTrue((-self.d.timing.tau<=self.d.data.events.tof).all())
|
||||
np.testing.assert_array_less(self.d.data.events.tof, self.d.timing.tau)
|
||||
|
||||
action = MergeFrames(lamdaCut=2.0)
|
||||
action = MergeFrames(lamdaCut=2.0, preciseTime=False)
|
||||
self.d.data.events.tof = self.d.orig_data.events.tof[:]
|
||||
action.perform_action(self.d)
|
||||
tofCut = 2.0*self.d.geometry.chopperDetectorDistance/const.hdm*1e-13
|
||||
self.assertTrue((tofCut-self.d.timing.tau<=self.d.data.events.tof).all())
|
||||
self.assertTrue((self.d.data.events.tof<=tofCut+self.d.timing.tau).all())
|
||||
|
||||
def test_merge_frames_splitting(self):
|
||||
action = MergeFrames(lamdaCut=0.0, preciseTime=True)
|
||||
self._extract_walltime()
|
||||
action.perform_action(self.d)
|
||||
self.assertEqual(self.d.data.events.tof.shape, self.d.orig_data.events.tof.shape)
|
||||
np.testing.assert_array_compare(lambda x,y: x<=y, self.d.data.events.tof, self.d.orig_data.events.tof)
|
||||
self.assertEqual(self.d.data.pulses.shape[0], self.d.orig_data.pulses.shape[0]*2+1)
|
||||
np.testing.assert_array_less(self.d.orig_data.pulses.time[:-1], self.d.orig_data.pulses.time[1:])
|
||||
np.testing.assert_array_less(self.d.data.pulses.time[:-1], self.d.data.pulses.time[1:])
|
||||
|
||||
def test_analyze_pixel_ids(self):
|
||||
action = AnalyzePixelIDs((1000, 1001))
|
||||
action.perform_action(self.d)
|
||||
|
||||
Reference in New Issue
Block a user