|
8 | 8 | import astropy.units as u |
9 | 9 | from astropy.coordinates import Angle, Latitude, Longitude |
10 | 10 | from astropy.uncertainty import Distribution |
11 | | -from astropy.utils import NumpyRNGContext |
12 | 11 |
|
13 | 12 |
|
14 | | -@pytest.mark.parametrize("angle_cls", [Angle, Longitude, Latitude]) |
15 | 13 | class TestAngles: |
16 | 14 | @classmethod |
17 | 15 | def setup_class(cls): |
18 | | - with NumpyRNGContext(12345): |
19 | | - cls.a = np.random.normal(10, [[0.2], [1.5], [4], [1]], size=(4, 10)) |
| 16 | + cls.a = np.arange(27.0).reshape(3, 9) |
20 | 17 | cls.d = Distribution(cls.a) |
21 | 18 | cls.q = cls.a << u.deg |
22 | 19 | cls.dq = Distribution(cls.q) |
23 | 20 |
|
| 21 | + @pytest.mark.parametrize("angle_cls", [Angle, Longitude, Latitude]) |
24 | 22 | def test_as_input_for_angle(self, angle_cls): |
25 | 23 | da = angle_cls(self.dq) |
26 | 24 | assert isinstance(da, angle_cls) |
27 | 25 | assert isinstance(da, Distribution) |
28 | 26 | assert_array_equal(da.distribution, angle_cls(self.q)) |
29 | 27 |
|
| 28 | + @pytest.mark.parametrize("angle_cls", [Angle, Longitude, Latitude]) |
30 | 29 | def test_using_angle_as_input(self, angle_cls): |
31 | 30 | a = angle_cls(self.q) |
32 | 31 | da = Distribution(a) |
33 | 32 | assert isinstance(da, angle_cls) |
34 | 33 | assert isinstance(da, Distribution) |
35 | 34 |
|
| 35 | + # Parametrize the unit to check the various branches in Latitude._validate_angles |
| 36 | + @pytest.mark.parametrize("dtype", ["f8", "f4"]) |
| 37 | + @pytest.mark.parametrize( |
| 38 | + "value", [90 * u.deg, np.pi / 2 * u.radian, 90 * 60 * u.arcmin] |
| 39 | + ) |
| 40 | + def test_at_limit_for_latitude(self, value, dtype): |
| 41 | + q = u.Quantity(value, dtype=dtype).reshape(1) |
| 42 | + qd = Distribution(q) |
| 43 | + ld = Latitude(qd) |
| 44 | + assert_array_equal(ld.distribution, Latitude(q)) |
| 45 | + |
| 46 | + # Parametrize the unit in case Longitude._wrap_at becomes unit-dependent. |
| 47 | + @pytest.mark.parametrize("dtype", ["f8", "f4"]) |
| 48 | + @pytest.mark.parametrize( |
| 49 | + "value", [360 * u.deg, 2 * np.pi * u.radian, 360 * 60 * u.arcmin] |
| 50 | + ) |
| 51 | + def test_at_wrap_angle_for_longitude(self, value, dtype): |
| 52 | + q = u.Quantity(value, dtype=dtype).reshape(1) |
| 53 | + qd = Distribution(q) |
| 54 | + ld = Longitude(qd) |
| 55 | + assert_array_equal(ld.distribution, Longitude(q)) |
| 56 | + assert np.all(ld.distribution == 0) |
| 57 | + |
| 58 | + @pytest.mark.parametrize("angle_cls", [Longitude, Latitude]) |
36 | 59 | def test_operation_gives_correct_subclass(self, angle_cls): |
37 | 60 | # Lon and Lat always fall back to Angle |
38 | 61 | da = angle_cls(self.dq) |
39 | 62 | da2 = da + da |
40 | 63 | assert isinstance(da, Angle) |
41 | 64 | assert isinstance(da, Distribution) |
42 | 65 |
|
| 66 | + @pytest.mark.parametrize("angle_cls", [Longitude, Latitude]) |
43 | 67 | def test_pdfmean_gives_correct_subclass(self, angle_cls): |
44 | 68 | # Lon and Lat always fall back to Angle |
45 | 69 | da = angle_cls(self.dq) |
|
0 commit comments