Пример #1
0
    def test_get_rphialpha_coordinates(self):
        cluster = Mock()

        # Trivial
        cluster.get_xyalpha_coordinates.return_value = (0, 0, 0)
        station = clusters.Station(cluster,
                                   1,
                                   position=(0, 0),
                                   angle=0,
                                   detectors=[(0, 0, 'LR')])
        coordinates = station.get_rphialpha_coordinates()
        self.assertEqual(coordinates, (0, 0, 0))

        # Cluster not in origin and rotated
        cluster.get_xyalpha_coordinates.return_value = (sqrt(2) / 2,
                                                        sqrt(2) / 2, pi / 8)
        station = clusters.Station(cluster, 1, (0, 0), 0, [(0, 0, 'LR')])
        coordinates = station.get_rphialpha_coordinates()
        self.assertTupleAlmostEqual(coordinates, (1, pi / 4, pi / 8))

        # Station *and* cluster not in origin and cluster rotated
        cluster.get_xyalpha_coordinates.return_value = (0, 10, pi / 2)
        station = clusters.Station(cluster, 1, (0, 5), 0, [(0, 0, 'LR')])
        coordinates = station.get_rphialpha_coordinates()
        self.assertTupleAlmostEqual(coordinates,
                                    (sqrt(125), 2.0344439357957027, pi / 2))

        # Station *and* cluster not in origin and cluster *and* station rotated
        cluster.get_xyalpha_coordinates.return_value = (0, 10, pi / 2)
        station = clusters.Station(cluster, 1, (0, 5), pi / 4, [(0, 0, 'LR')])
        coordinates = station.get_rphialpha_coordinates()
        self.assertTupleAlmostEqual(
            coordinates, (sqrt(125), 2.0344439357957027, 3 * pi / 4))
Пример #2
0
    def test_get_xyalpha_coordinates(self):
        with patch('sapphire.clusters.Detector') as mock_detector:
            cluster = Mock()

            # Trivial
            cluster.get_xyalpha_coordinates.return_value = (0, 0, 0)
            station = clusters.Station(cluster,
                                       1,
                                       position=(0, 0),
                                       angle=0,
                                       detectors=[(0, 0, 'LR')])
            coordinates = station.get_xyalpha_coordinates()
            self.assertEqual(coordinates, (0, 0, 0))

            # Cluster not in origin and rotated
            cluster.get_xyalpha_coordinates.return_value = (sqrt(2) / 2,
                                                            sqrt(2) / 2,
                                                            pi / 8)
            station = clusters.Station(cluster, 1, (0, 0), 0, [(0, 0, 'LR')])
            coordinates = station.get_xyalpha_coordinates()
            self.assertTupleAlmostEqual(coordinates,
                                        (sqrt(2) / 2, sqrt(2) / 2, pi / 8))

            # Station *and* cluster not in origin and cluster rotated
            cluster.get_xyalpha_coordinates.return_value = (0, 10, pi / 2)
            station = clusters.Station(cluster, 1, (0, 5), 0, [(0, 0, 'LR')])
            coordinates = station.get_xyalpha_coordinates()
            self.assertTupleAlmostEqual(coordinates, (-5, 10, pi / 2))

            # Station *and* cluster not in origin and cluster *and* station rotated
            cluster.get_xyalpha_coordinates.return_value = (0, 10, pi / 2)
            station = clusters.Station(cluster, 1, (0, 5), pi / 4,
                                       [(0, 0, 'LR')])
            coordinates = station.get_xyalpha_coordinates()
            self.assertTupleAlmostEqual(coordinates, (-5, 10, 3 * pi / 4))
Пример #3
0
    def test_add_detector_for_one_instance(self):
        """
        Unfortunately, if you naively declare __detectors = [] as a *class*
        variable, you will share the same list with *all instances*.

        """
        with patch('sapphire.clusters.Detector') as mock_detector:
            cluster = Mock()
            mock_detector.return_value = Mock()
            station1 = clusters.Station(cluster, 1, (0, 1), 2, [(3, 4, 'LR')])
            mock_detector.return_value = Mock()
            station2 = clusters.Station(cluster, 2, (0, 1), 2, [(0, 1, 'LR')])
            self.assertNotEqual(station1.detectors[0], station2.detectors[0])
Пример #4
0
 def setUp(self):
     with patch('sapphire.clusters.Detector') as mock_detector:
         self.cluster = Mock()
         self.station_1 = clusters.Station(self.cluster, 1, (0, 1, 2), pi / 4,
                                           [((3, 4), 'LR')])
         self.station_s = clusters.Station(self.cluster, sentinel.id,
                                           (sentinel.x, sentinel.y, sentinel.z),
                                           sentinel.angle, [],
                                           number=sentinel.number)
         self.station_4d = clusters.Station(self.cluster, 4,
                                            ([0, 5], [0, 5], [0, 5]), (0, pi),
                                            station_timestamps=[0, 5])
         self.mock_detector_instance = mock_detector.return_value
Пример #5
0
    def test_calc_r_and_phi_for_detectors(self):
        cluster = Mock()
        cluster.get_coordinates.return_value = (0, 0, 0, 0)
        station = clusters.Station(cluster, 1, position=(0, 0), angle=0,
                                   detectors=[((0, 0), 'LR'), ((10., 10.), 'LR')])

        r, phi = station.calc_r_and_phi_for_detectors(0, 1)
        self.assertAlmostEqual(r ** 2, 10 ** 2 + 10 ** 2)
        self.assertAlmostEqual(phi, pi / 4)
Пример #6
0
 def test_calc_center_of_mass_coordinates(self):
     cluster = Mock()
     cluster.get_coordinates.return_value = (0, 0, 0, 0)
     station = clusters.Station(cluster, 1, position=(0, 0), angle=0,
                                detectors=[((0, 0, 0), 'LR'), ((10, 9, 1), 'LR'),
                                           ((nan, nan, nan), 'LR'), ((nan, nan, nan), 'LR')])
     center = station.calc_xy_center_of_mass_coordinates()
     self.assert_tuple_almost_equal(center, (5, 4.5))
     center = station.calc_center_of_mass_coordinates()
     self.assert_tuple_almost_equal(center, (5, 4.5, 0.5))
Пример #7
0
    def test_unit_get_polar_alpha_coordinates(self):
        station_coordinates = (sqrt(2), sqrt(2), 0, pi / 4)

        cluster = Mock()
        station = clusters.Station(cluster, 1, (0, 0), 0, [])

        with patch.object(clusters.Station, 'get_coordinates') as mock_coor:
            mock_coor.return_value = station_coordinates

            r, phi, beta = station.get_polar_alpha_coordinates()
            self.assertTrue(mock_coor.called)
            self.assertAlmostEqual(r, 2)
            self.assertAlmostEqual(phi, pi / 4)
            self.assertAlmostEqual(beta, pi / 4)
Пример #8
0
    def test_unit_get_rphialpha_coordinates(self):
        station_xyalpha = (sqrt(2), sqrt(2), pi / 4)

        cluster = Mock()
        station = clusters.Station(cluster, 1, Mock(), Mock(), [])

        with patch.object(clusters.Station,
                          'get_xyalpha_coordinates') as mock_xyalpha:
            mock_xyalpha.return_value = station_xyalpha

            r, phi, beta = station.get_rphialpha_coordinates()
            self.assertTrue(mock_xyalpha.called)
            self.assertAlmostEqual(r, 2)
            self.assertAlmostEqual(phi, pi / 4)
            self.assertAlmostEqual(beta, pi / 4)
Пример #9
0
 def test_detector_called(self):
     with patch('sapphire.clusters.Detector') as mock_detector:
         cluster = Mock()
         station = clusters.Station(cluster, 1, (0, 1), 2, [(3, 4, 'LR')])
         mock_detector.assert_called_with(station, 3, 4, 'LR')
Пример #10
0
 def setUp(self):
     with patch('sapphire.clusters.Detector') as mock_detector:
         self.cluster = Mock()
         self.station_1 = clusters.Station(self.cluster, 1, (0, 1), pi / 4,
                                           [(3, 4, 'LR')])
         self.mock_detector_instance = mock_detector.return_value
Пример #11
0
 def test_detector_called(self):
     with patch('sapphire.clusters.Detector') as mock_detector:
         cluster = Mock()
         station = clusters.Station(cluster, 1, (0, 1, 2), pi,
                                    [((4, 5, 0), 'LR')])
         mock_detector.assert_called_with(station, (4, 5, 0), 'LR', [0])