コード例 #1
0
 def test_bad_times(self, mock_detector_arrival_time):
     mock_detector_arrival_time.return_value = nan
     station = Mock()
     dirrec = direction_reconstruction.EventDirectionReconstruction(station)
     theta, phi, ids = dirrec.reconstruct_event(
         {'timestamp': sentinel.timestamp}, detector_ids=[0, 1])
     self.assertTrue(isnan(theta))
     self.assertTrue(isnan(phi))
コード例 #2
0
 def test_set_cluster_timestamp(self):
     station = Mock()
     dirrec = direction_reconstruction.EventDirectionReconstruction(station)
     theta, phi, ids = dirrec.reconstruct_event(
         {'timestamp': sentinel.timestamp}, detector_ids=[])
     station.cluster.set_timestamp.assert_called_with(sentinel.timestamp)
     self.assertTrue(isnan(theta))
     self.assertTrue(isnan(phi))
コード例 #3
0
 def test_init(self):
     dirrec = direction_reconstruction.EventDirectionReconstruction(
         sentinel.station)
     self.assertEqual(dirrec.direct,
                      direction_reconstruction.DirectAlgorithmCartesian3D)
     self.assertEqual(dirrec.fit,
                      direction_reconstruction.RegressionAlgorithm3D)
     self.assertEqual(dirrec.station, sentinel.station)
コード例 #4
0
    def test_reconstruct_event(self, mock_detector_arrival_time):
        mock_detector_arrival_time.return_value = 0.
        station = MagicMock()
        detector = Mock()
        detector.get_coordinates.return_value = [
            sentinel.x, sentinel.y, sentinel.z
        ]
        station.detectors.__getitem__.side_effect = lambda name: detector
        dirrec = direction_reconstruction.EventDirectionReconstruction(station)
        dirrec.direct = Mock()
        dirrec.fit = Mock()
        dirrec.direct.reconstruct_common.return_value = (sentinel.theta,
                                                         sentinel.phi)
        dirrec.fit.reconstruct_common.return_value = (sentinel.theta,
                                                      sentinel.phi)
        event = {'timestamp': sentinel.timestamp}

        theta, phi, ids = dirrec.reconstruct_event(event, detector_ids=[0, 1])
        self.assertEqual(dirrec.direct.reconstruct_common.call_count, 0)
        self.assertTrue(isnan(theta))
        self.assertTrue(isnan(phi))
        self.assertEqual(len(ids), 2)

        theta, phi, ids = dirrec.reconstruct_event(event,
                                                   detector_ids=[0, 1, 2])
        dirrec.direct.reconstruct_common.assert_called_once_with(
            [0.] * 3, [sentinel.x] * 3, [sentinel.y] * 3, [sentinel.z] * 3)
        self.assertEqual(dirrec.fit.reconstruct_common.call_count, 0)
        self.assertEqual(theta, sentinel.theta)
        self.assertEqual(phi, sentinel.phi)
        self.assertEqual(len(ids), 3)

        theta, phi, ids = dirrec.reconstruct_event(event,
                                                   detector_ids=[0, 1, 2, 3])
        self.assertEqual(dirrec.direct.reconstruct_common.call_count, 1)
        dirrec.fit.reconstruct_common.assert_called_once_with([0.] * 4,
                                                              [sentinel.x] * 4,
                                                              [sentinel.y] * 4,
                                                              [sentinel.z] * 4)
        self.assertEqual(theta, sentinel.theta)
        self.assertEqual(phi, sentinel.phi)
        self.assertEqual(len(ids), 4)
        theta, phi, ids = dirrec.reconstruct_event(event, detector_ids=None)
        dirrec.fit.reconstruct_common.assert_called_with([0.] * 4,
                                                         [sentinel.x] * 4,
                                                         [sentinel.y] * 4,
                                                         [sentinel.z] * 4)
        self.assertEqual(dirrec.fit.reconstruct_common.call_count, 2)
コード例 #5
0
 def test_reconstruct_events(self, mock_reconstruct_event):
     mock_reconstruct_event.return_value = [
         sentinel.theta, sentinel.phi, sentinel.ids
     ]
     dirrec = direction_reconstruction.EventDirectionReconstruction(
         sentinel.station)
     self.assertEqual(
         dirrec.reconstruct_events([sentinel.event, sentinel.event],
                                   sentinel.detector_ids,
                                   sentinel.offsets,
                                   progress=False),
         ((sentinel.theta, sentinel.theta), (sentinel.phi, sentinel.phi),
          (sentinel.ids, sentinel.ids)))
     self.assertEqual(mock_reconstruct_event.call_count, 2)
     mock_reconstruct_event.assert_called_with(sentinel.event,
                                               sentinel.detector_ids,
                                               sentinel.offsets)
     self.assertEqual(
         dirrec.reconstruct_events([],
                                   sentinel.detector_ids,
                                   sentinel.offsets,
                                   progress=False), ((), (), ()))
     self.assertEqual(mock_reconstruct_event.call_count, 2)
コード例 #6
0
    def test_reconstruct_event(self, mock_detector_arrival_time):
        mock_detector_arrival_time.return_value = 0.
        station = MagicMock()
        detector = Mock()
        detector.get_coordinates.return_value = [
            sentinel.x, sentinel.y, sentinel.z
        ]
        station.detectors.__getitem__.side_effect = lambda name: detector
        dirrec = direction_reconstruction.EventDirectionReconstruction(station)
        dirrec.direct = Mock()
        dirrec.fit = Mock()
        dirrec.direct.reconstruct_common.return_value = (sentinel.theta,
                                                         sentinel.phi)
        dirrec.fit.reconstruct_common.return_value = (sentinel.theta,
                                                      sentinel.phi)
        event = {'timestamp': sentinel.timestamp}

        # To few detectors
        theta, phi, ids = dirrec.reconstruct_event(event, detector_ids=[0, 1])
        dirrec.direct.reconstruct_common.assert_not_called()
        self.assertTrue(isnan(theta))
        self.assertTrue(isnan(phi))
        self.assertEqual(len(ids), 2)

        # Three detections, direct reconstruction
        theta, phi, ids = dirrec.reconstruct_event(event,
                                                   detector_ids=[0, 1, 2])
        dirrec.direct.reconstruct_common.assert_called_once_with(
            [0.] * 3, [sentinel.x] * 3, [sentinel.y] * 3, [sentinel.z] * 3,
            None)
        dirrec.fit.reconstruct_common.assert_not_called()
        self.assertEqual(theta, sentinel.theta)
        self.assertEqual(phi, sentinel.phi)
        self.assertEqual(len(ids), 3)

        # Four detections, fit reconstruction
        theta, phi, ids = dirrec.reconstruct_event(event,
                                                   detector_ids=[0, 1, 2, 3])
        self.assertEqual(dirrec.direct.reconstruct_common.call_count, 1)
        dirrec.fit.reconstruct_common.assert_called_once_with([0.] * 4,
                                                              [sentinel.x] * 4,
                                                              [sentinel.y] * 4,
                                                              [sentinel.z] * 4,
                                                              None)
        self.assertEqual(theta, sentinel.theta)
        self.assertEqual(phi, sentinel.phi)
        self.assertEqual(len(ids), 4)
        theta, phi, ids = dirrec.reconstruct_event(event, detector_ids=None)
        dirrec.fit.reconstruct_common.assert_called_with([0.] * 4,
                                                         [sentinel.x] * 4,
                                                         [sentinel.y] * 4,
                                                         [sentinel.z] * 4,
                                                         None)
        self.assertEqual(dirrec.fit.reconstruct_common.call_count, 2)

        # Four detections, fit reconstruction with offsets
        offsets = MagicMock(spec=direction_reconstruction.Station)
        offsets.detector_timing_offset.return_value = [sentinel.offset] * 4
        theta, phi, ids = dirrec.reconstruct_event(event,
                                                   detector_ids=[0, 1, 2, 3],
                                                   offsets=offsets)
        offsets.detector_timing_offset.assert_called_once_with(
            sentinel.timestamp)
        mock_detector_arrival_time.assert_called_with(
            event, 3, offsets.detector_timing_offset.return_value)