Skip to content

Commit

Permalink
Add _ to separate seconds and nanoseconds part in extended timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
153957 committed May 5, 2024
1 parent 4afbba2 commit beae082
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
56 changes: 28 additions & 28 deletions sapphire/tests/analysis/test_coincidences.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ def test__retrieve_timestamps(self):
station1 = Mock()
station2 = Mock()
# Station 2 timestamps are not already correctly sorted.
station1.col.return_value = [uint64(1400000002000000050), uint64(1400000018000000500)]
station2.col.return_value = [uint64(1400000002000000510), uint64(1400000030000000000)][::-1]
station1.col.return_value = [uint64(1400000002_000000050), uint64(1400000018_000000500)]
station2.col.return_value = [uint64(1400000002_000000510), uint64(1400000030_000000000)][::-1]
stations = [station1, station2]
timestamps = self.c._retrieve_timestamps(stations)
self.assertEqual(
timestamps,
[
(uint64(1400000002000000050), 0, 0),
(uint64(1400000002000000510), 1, 1),
(uint64(1400000018000000500), 0, 1),
(uint64(1400000030000000000), 1, 0),
(uint64(1400000002_000000050), 0, 0),
(uint64(1400000002_000000510), 1, 1),
(uint64(1400000018_000000500), 0, 1),
(uint64(1400000030_000000000), 1, 0),
],
)
# Shift both
timestamps = self.c._retrieve_timestamps(stations, shifts=[1, 17])
self.assertEqual(
timestamps,
[
(uint64(1400000003000000050), 0, 0),
(uint64(1400000019000000500), 0, 1),
(uint64(1400000019000000510), 1, 1),
(uint64(1400000047000000000), 1, 0),
(uint64(1400000003_000000050), 0, 0),
(uint64(1400000019_000000500), 0, 1),
(uint64(1400000019_000000510), 1, 1),
(uint64(1400000047_000000000), 1, 0),
],
)
# Wrong value type shifts
Expand All @@ -75,43 +75,43 @@ def test__retrieve_timestamps(self):
self.assertEqual(
timestamps,
[
(uint64(1400000002000000510), 1, 1),
(uint64(1400000030000000000), 1, 0),
(uint64(1400000112000000050), 0, 0),
(uint64(1400000128000000500), 0, 1),
(uint64(1400000002_000000510), 1, 1),
(uint64(1400000030_000000000), 1, 0),
(uint64(1400000112_000000050), 0, 0),
(uint64(1400000128_000000500), 0, 1),
],
)
timestamps = self.c._retrieve_timestamps(stations, shifts=[None, 60])
self.assertEqual(
timestamps,
[
(uint64(1400000002000000050), 0, 0),
(uint64(1400000018000000500), 0, 1),
(uint64(1400000062000000510), 1, 1),
(uint64(1400000090000000000), 1, 0),
(uint64(1400000002_000000050), 0, 0),
(uint64(1400000018_000000500), 0, 1),
(uint64(1400000062_000000510), 1, 1),
(uint64(1400000090_000000000), 1, 0),
],
)
# Subsecond shifts
timestamps = self.c._retrieve_timestamps(stations, shifts=[3e-9, 5e-9])
self.assertEqual(
timestamps,
[
(uint64(1400000002000000053), 0, 0),
(uint64(1400000002000000515), 1, 1),
(uint64(1400000018000000503), 0, 1),
(uint64(1400000030000000005), 1, 0),
(uint64(1400000002_000000053), 0, 0),
(uint64(1400000002_000000515), 1, 1),
(uint64(1400000018_000000503), 0, 1),
(uint64(1400000030_000000005), 1, 0),
],
)
# Using limits
timestamps = self.c._retrieve_timestamps(stations, limit=1)

# Check accuracy of comparisons between different types
self.assertEqual(timestamps, [(1400000002000000050, 0, 0), (1400000030000000000, 1, 0)])
self.assertEqual(timestamps, [(uint64(1400000002000000050), 0, 0), (uint64(1400000030000000000), 1, 0)])
self.assertNotEqual(timestamps, [(1400000002000000049, 0, 0), (1400000030000000000, 1, 0)])
self.assertNotEqual(timestamps, [(1400000002000000051, 0, 0), (1400000030000000000, 1, 0)])
self.assertNotEqual(timestamps, [(uint64(1400000002000000049), 0, 0), (uint64(1400000030000000000), 1, 0)])
self.assertNotEqual(timestamps, [(uint64(1400000002000000051), 0, 0), (uint64(1400000030000000001), 1, 0)])
self.assertEqual(timestamps, [(1400000002_000000050, 0, 0), (1400000030_000000000, 1, 0)])
self.assertEqual(timestamps, [(uint64(1400000002_000000050), 0, 0), (uint64(1400000030_000000000), 1, 0)])
self.assertNotEqual(timestamps, [(1400000002_000000049, 0, 0), (1400000030_000000000, 1, 0)])
self.assertNotEqual(timestamps, [(1400000002_000000051, 0, 0), (1400000030_000000000, 1, 0)])
self.assertNotEqual(timestamps, [(uint64(1400000002_000000049), 0, 0), (uint64(1400000030_000000000), 1, 0)])
self.assertNotEqual(timestamps, [(uint64(1400000002_000000051), 0, 0), (uint64(1400000030_000000001), 1, 0)])

def test__do_search_coincidences(self):
# [(timestamp, station_idx, event_idx), ..]
Expand Down
4 changes: 2 additions & 2 deletions sapphire/tests/analysis/test_time_deltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def test_store_time_deltas(self):
pair = (501, 502)
node_path = '/coincidences/time_deltas/station_%d/station_%d' % pair
self.assertRaises(Exception, self.data.get_node, node_path, 'time_deltas')
self.td.store_time_deltas([12345678987654321], [2.5], pair)
self.td.store_time_deltas([12345678_987654321], [2.5], pair)
stored_data = self.data.get_node(node_path, 'time_deltas')
self.assertEqual(list(stored_data[0]), [12345678987654321, 12345678, 987654321, 2.5])
self.assertEqual(list(stored_data[0]), [12345678_987654321, 12345678, 987654321, 2.5])

def create_tempfile_from_testdata(self):
tmp_path = self.create_tempfile_path()
Expand Down

0 comments on commit beae082

Please sign in to comment.