Example #1
0
    def test_values_unit(self):

        # Make sure that the intrinsic unit and format unit are correctly
        # taken into account when using the locator

        fl = AngleFormatterLocator(unit=u.arcsec,
                                   format_unit=u.arcsec,
                                   decimal=True)
        assert_quantity_allclose(
            fl.locator(850, 2150)[0],
            [1000., 1200., 1400., 1600., 1800., 2000.] * u.arcsec)

        fl = AngleFormatterLocator(unit=u.arcsec,
                                   format_unit=u.degree,
                                   decimal=False)
        assert_quantity_allclose(
            fl.locator(850, 2150)[0], [15., 20., 25., 30., 35.] * u.arcmin)

        fl = AngleFormatterLocator(unit=u.arcsec,
                                   format_unit=u.hourangle,
                                   decimal=False)
        assert_quantity_allclose(
            fl.locator(850, 2150)[0],
            [60., 75., 90., 105., 120., 135.] * (15 * u.arcsec))

        fl = AngleFormatterLocator(unit=u.arcsec)
        fl.format = 'dd:mm:ss'
        assert_quantity_allclose(fl.locator(0.9, 1.1)[0], [1] * u.arcsec)

        fl = AngleFormatterLocator(unit=u.arcsec, spacing=0.2 * u.arcsec)
        assert_quantity_allclose(
            fl.locator(0.3, 0.9)[0], [0.4, 0.6, 0.8] * u.arcsec)
Example #2
0
    def test_minor_locator(self):

        fl = AngleFormatterLocator()

        values, spacing = fl.locator(34.3, 55.4)

        minor_values = fl.minor_locator(spacing, 5, 34.3, 55.4)

        assert_almost_equal(minor_values.to_value(u.degree), [
            36., 37., 38., 39., 41., 42., 43., 44., 46., 47., 48., 49., 51.,
            52., 53., 54.
        ])

        minor_values = fl.minor_locator(spacing, 2, 34.3, 55.4)

        assert_almost_equal(minor_values.to_value(u.degree),
                            [37.5, 42.5, 47.5, 52.5])

        fl.values = [0.1, 1., 14.] * u.degree

        values, spacing = fl.locator(34.3, 36.1)

        minor_values = fl.minor_locator(spacing, 2, 34.3, 55.4)

        assert_almost_equal(minor_values.to_value(u.degree), [])
    def test_decimal_values(self):

        # Regression test for a bug that meant that the spacing was not
        # determined correctly for decimal coordinates

        fl = AngleFormatterLocator()
        fl.format = 'd.dddd'
        assert_quantity_allclose(fl.locator(266.9730, 266.9750)[0],
                                 [266.9735, 266.9740, 266.9745, 266.9750] * u.deg)

        fl = AngleFormatterLocator(decimal=True, format_unit=u.hourangle, number=4)
        assert_quantity_allclose(fl.locator(266.9730, 266.9750)[0],
                                 [17.79825, 17.79830] * u.hourangle)
    def test_number(self):

        fl = AngleFormatterLocator(number=7)
        assert fl.values is None
        assert fl.number == 7
        assert fl.spacing is None

        values, spacing = fl.locator(34.3, 55.4)
        assert_almost_equal(values.to_value(u.degree), [35., 40., 45., 50., 55.])

        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.to_value(u.degree), [34.5, 34.75, 35., 35.25, 35.5, 35.75, 36.])

        fl.format = 'dd'
        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.to_value(u.degree), [35., 36.])
Example #5
0
    def test_values(self):

        fl = AngleFormatterLocator(values=[0.1, 1., 14.] * u.degree)
        assert fl.values.to_value(u.degree).tolist() == [0.1, 1., 14.]
        assert fl.number is None
        assert fl.spacing is None

        values, spacing = fl.locator(34.3, 55.4)
        assert_almost_equal(values.to_value(u.degree), [0.1, 1., 14.])
Example #6
0
    def test_values(self):

        fl = AngleFormatterLocator(values=[0.1, 1., 14.] * u.degree)
        assert fl.values.to_value(u.degree).tolist() == [0.1, 1., 14.]
        assert fl.number is None
        assert fl.spacing is None

        values, spacing = fl.locator(34.3, 55.4)
        assert_almost_equal(values.to_value(u.degree), [0.1, 1., 14.])
    def test_spacing(self):

        with pytest.raises(TypeError) as exc:
            AngleFormatterLocator(spacing=3.)
        assert exc.value.args[0] == "spacing should be an astropy.units.Quantity instance with units of angle"

        fl = AngleFormatterLocator(spacing=3. * u.degree)
        assert fl.values is None
        assert fl.number is None
        assert fl.spacing == 3. * u.degree

        values, spacing = fl.locator(34.3, 55.4)
        assert_almost_equal(values.to_value(u.degree), [36., 39., 42., 45., 48., 51., 54.])

        fl.spacing = 30. * u.arcmin
        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.to_value(u.degree), [34.5, 35., 35.5, 36.])

        with pytest.warns(UserWarning, match='Spacing is too small'):
            fl.format = 'dd'
        values, spacing = fl.locator(34.3, 36.1)
        assert_almost_equal(values.to_value(u.degree), [35., 36.])
Example #8
0
    def test_minor_locator(self):

        fl = AngleFormatterLocator()

        values, spacing = fl.locator(34.3, 55.4)

        minor_values = fl.minor_locator(spacing, 5, 34.3, 55.4)

        assert_almost_equal(minor_values.to_value(u.degree), [36., 37., 38.,
                            39., 41., 42., 43., 44., 46., 47., 48., 49., 51.,
                            52., 53., 54.])

        minor_values = fl.minor_locator(spacing, 2, 34.3, 55.4)

        assert_almost_equal(minor_values.to_value(u.degree), [37.5, 42.5, 47.5, 52.5])

        fl.values = [0.1, 1., 14.] * u.degree

        values, spacing = fl.locator(34.3, 36.1)

        minor_values = fl.minor_locator(spacing, 2, 34.3, 55.4)

        assert_almost_equal(minor_values.to_value(u.degree), [])
Example #9
0
    def test_values_unit(self):

        # Make sure that the intrinsic unit and format unit are correctly
        # taken into account when using the locator

        fl = AngleFormatterLocator(unit=u.arcsec, format_unit=u.arcsec, decimal=True)
        assert_quantity_allclose(fl.locator(850, 2150)[0],
                                 [1000., 1200., 1400., 1600., 1800., 2000.] * u.arcsec)

        fl = AngleFormatterLocator(unit=u.arcsec, format_unit=u.degree, decimal=False)
        assert_quantity_allclose(fl.locator(850, 2150)[0],
                                 [15., 20., 25., 30., 35.] * u.arcmin)

        fl = AngleFormatterLocator(unit=u.arcsec, format_unit=u.hourangle, decimal=False)
        assert_quantity_allclose(fl.locator(850, 2150)[0],
                                 [60., 75., 90., 105., 120., 135.] * (15 * u.arcsec))

        fl = AngleFormatterLocator(unit=u.arcsec)
        fl.format = 'dd:mm:ss'
        assert_quantity_allclose(fl.locator(0.9, 1.1)[0], [1] * u.arcsec)

        fl = AngleFormatterLocator(unit=u.arcsec, spacing=0.2 * u.arcsec)
        assert_quantity_allclose(fl.locator(0.3, 0.9)[0], [0.4, 0.6, 0.8] * u.arcsec)