Пример #1
0
 def test__distance(self):
     x = array([-5., 4., 3.])
     y = array([2., -1., 0.])
     dist = clusters.BaseCluster()._distance(x, y)
     self.assertAlmostEqual(dist, sqrt(49 + 25 + 9))
     x = array([-5., 4.])
     y = array([2., -1.])
     dist = clusters.BaseCluster()._distance(x, y)
     self.assertAlmostEqual(dist, sqrt(49 + 25))
Пример #2
0
 def test_set_rphialpha_coordinates(self):
     cluster = clusters.BaseCluster()
     cluster.set_cylindrical_coordinates(10., pi / 2, sentinel.z, sentinel.alpha)
     self.assertAlmostEqual(cluster.x, 0.)
     self.assertAlmostEqual(cluster.y, 10.)
     self.assertAlmostEqual(cluster.z, sentinel.z)
     self.assertAlmostEqual(cluster.alpha, sentinel.alpha)
Пример #3
0
    def test_add_station_for_one_instance(self):
        """
        Unfortunately, if you naively declare __stations = [] as a *class*
        variable, you will share the same list with *all instances*.

        """
        with patch('sapphire.clusters.Station') as mock_station:
            mock_station.return_value = Mock()
            cluster1 = clusters.BaseCluster()
            cluster1._add_station((0, 0), 0, [(0, 0, 'LR')])

            mock_station.return_value = Mock()
            cluster2 = clusters.BaseCluster()
            cluster2._add_station((1, 2), 0, [(3, 0, 'LR')])

            self.assertNotEqual(cluster1.stations[0], cluster2.stations[0])
Пример #4
0
 def test_set_timestamp(self):
     with patch('sapphire.clusters.Station'):
         cluster = clusters.BaseCluster()
         cluster._add_station(sentinel.position)
         self.assertEqual(cluster._timestamp, 2147483647)
         cluster.set_timestamp(sentinel.timestamp)
         self.assertEqual(cluster._timestamp, sentinel.timestamp)
         cluster.stations[0]._update_timestamp.assert_called_with(sentinel.timestamp)
Пример #5
0
 def test_set_center_off_mass_at_origin(self):
     cluster = clusters.BaseCluster()
     cluster._add_station((0, 0), 0, [((0, 5 * sqrt(3)), 'UD'),
                                      ((0, 5 * sqrt(3) / 3), 'UD'),
                                      ((-10, 0), 'LR'), ((10, 0), 'LR')])
     cluster.set_center_off_mass_at_origin()
     center = cluster.calc_center_of_mass_coordinates()
     assert_array_almost_equal(center, [0., 0., 0.])
Пример #6
0
 def test_calc_horizontal_distance_between_stations(self):
     cluster = clusters.BaseCluster()
     cluster._add_station((0, 0, 0), 0, number=1)
     cluster._add_station((3, 4, 5), 0, number=2)
     dist = cluster.calc_horizontal_distance_between_stations(1, 2)
     self.assertAlmostEqual(dist, sqrt(9 + 16))
     dist = cluster.calc_distance_between_stations(1, 0)
     self.assertIsNone(dist)
Пример #7
0
 def test_get_coordinates(self):
     cluster = clusters.BaseCluster((10., 20., 0), pi / 2)
     coordinates = cluster.get_coordinates()
     self.assertEqual(coordinates, (10., 20., 0, pi / 2))
     coordinates = cluster.get_xyalpha_coordinates()
     self.assertEqual(coordinates, (10., 20., pi / 2))
     coordinates = cluster.get_xy_coordinates()
     self.assertEqual(coordinates, (10., 20.))
Пример #8
0
 def test_calc_xy_center_of_mass_coordinates(self):
     cluster = clusters.BaseCluster()
     cluster._add_station((0, 0), 0, [((0, 5 * sqrt(3)), 'UD'),
                                      ((0, 5 * sqrt(3) / 3), 'UD'),
                                      ((-10, 0), 'LR'), ((10, 0), 'LR')])
     x, y = cluster.calc_xy_center_of_mass_coordinates()
     self.assertAlmostEqual(x, 0)
     self.assertAlmostEqual(y, 5 * sqrt(3) / 3)
Пример #9
0
    def test_attributes(self):
        with patch('sapphire.clusters.Station') as mock_station:
            mock_station_instance = Mock()
            mock_station.return_value = mock_station_instance

            cluster = clusters.BaseCluster()
            cluster._add_station(Mock(), Mock(), Mock())
            self.assertEqual(cluster.stations, [mock_station_instance])
Пример #10
0
 def test_calc_r_and_phi_for_stations(self):
     cluster = clusters.BaseCluster()
     cluster._add_station((0, 0), 0)
     cluster._add_station((1, sqrt(3)), 0)
     r, phi, z = cluster.calc_rphiz_for_stations(0, 1)
     self.assertAlmostEqual(r, 2)
     self.assertAlmostEqual(phi, pi / 3.)
     self.assertAlmostEqual(z, 0)
Пример #11
0
 def test_calc_xy_center_of_mass_coordinates_nan_detectors(self):
     # detector locations can be nan, esp two detector stations
     cluster = clusters.BaseCluster()
     cluster._add_station((0, 0), 0, [((-10, 0), 'LR'), ((10, 0), 'LR'),
                                      ((nan, nan), 'LR'),
                                      ((nan, nan), 'LR')])
     x, y = cluster.calc_xy_center_of_mass_coordinates()
     self.assertAlmostEqual(x, 0)
     self.assertAlmostEqual(y, 0)
Пример #12
0
    def test_add_station(self):
        with patch('sapphire.clusters.Station') as mock_station:
            cluster = clusters.BaseCluster()
            self.assertFalse(mock_station.called)

            pos = Mock(name='pos')
            angle = Mock(name='angle')
            detector_list = Mock(name='detector_list')
            cluster._add_station(pos, angle, detector_list)
            mock_station.assert_called_with(cluster, 1, pos, angle,
                                            detector_list)
Пример #13
0
    def test_add_station(self):
        with patch('sapphire.clusters.Station') as mock_station:
            cluster = clusters.BaseCluster()
            self.assertFalse(mock_station.called)

            x = Mock(name='x')
            y = Mock(name='y')
            z = Mock(name='z')
            angle = Mock(name='angle')
            detector_list = Mock(name='detector_list')
            number = Mock(name='number')
            cluster._add_station((x, y, z), angle, detector_list, number=number)
            mock_station.assert_called_with(cluster, 0, (x, y, z), angle,
                                            detector_list, None, None, number)
Пример #14
0
 def test_set_rphialpha_coordinates(self):
     cluster = clusters.BaseCluster()
     cluster.set_rphialpha_coordinates(10., pi / 2, 0.)
     self.assertAlmostEqual(cluster._x, 0.)
     self.assertAlmostEqual(cluster._y, 10.)
     self.assertAlmostEqual(cluster._alpha, 0.)
Пример #15
0
 def test_set_xyalpha_coordinates(self):
     cluster = clusters.BaseCluster()
     cluster.set_xyalpha_coordinates(5., 7., pi / 2)
     self.assertEqual((cluster._x, cluster._y, cluster._alpha),
                      (5., 7., pi / 2))
Пример #16
0
 def test_get_rphialpha_coordinates(self):
     cluster = clusters.BaseCluster((-sqrt(2) / 2, sqrt(2) / 2), pi / 2)
     r, phi, alpha = cluster.get_rphialpha_coordinates()
     self.assertAlmostEqual(r, 1.)
     self.assertAlmostEqual(phi, 3 * pi / 4)
     self.assertEqual(alpha, pi / 2)
Пример #17
0
 def test_init_sets_position(self):
     cluster = clusters.BaseCluster((10., 20.), pi / 2)
     self.assertEqual(cluster._x, 10.)
     self.assertEqual(cluster._y, 20.)
     self.assertEqual(cluster._alpha, pi / 2)
Пример #18
0
 def test_set_coordinates(self):
     cluster = clusters.BaseCluster()
     cluster.set_coordinates(sentinel.x, sentinel.y, sentinel.z,
                             sentinel.alpha)
     self.assertEqual((cluster.x, cluster.y, cluster.z, cluster.alpha),
                      (sentinel.x, sentinel.y, sentinel.z, sentinel.alpha))
Пример #19
0
 def test_get_station_by_number(self):
     cluster = clusters.BaseCluster((0, 0, 0), 0)
     cluster._add_station((0, 0, 0), 0, number=501)
     self.assertEqual(cluster.get_station(501), cluster.stations[0])