Пример #1
0
 def test_latex_format(self):
     fl = AngleFormatterLocator(number=5, format="dd:mm:ss")
     assert fl.formatter([15.392231] * u.degree, None)[0] == '15\xb023\'32"'
     with rc_context(rc={'text.usetex': True}):
         assert fl.formatter(
             [15.392231] * u.degree,
             None)[0] == "$15^\\circ23{}^\\prime32{}^{\\prime\\prime}$"
Пример #2
0
 def test_incorrect_spacing(self):
     fl = AngleFormatterLocator()
     fl.spacing = 0.032 * u.deg
     with pytest.warns(UserWarning,
                       match=r'Spacing is not a multiple of base spacing'):
         fl.format = 'dd:mm:ss'
     assert_almost_equal(fl.spacing.to_value(u.arcsec), 115.)
Пример #3
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.])
Пример #4
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.])
Пример #5
0
 def test_formatter_no_format_with_units(self, format_unit, decimal,
                                         show_decimal_unit, spacing, ascii,
                                         latex):
     # Check the formatter works when specifying the default units and
     # decimal behavior to use.
     fl = AngleFormatterLocator(unit=u.degree,
                                format_unit=format_unit,
                                decimal=decimal,
                                show_decimal_unit=show_decimal_unit)
     assert fl.formatter([15.392231] * u.degree, spacing,
                         format='ascii')[0] == ascii
     assert fl.formatter([15.392231] * u.degree, spacing,
                         format='latex')[0] == latex
Пример #6
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_too_many_options(self):

        with pytest.raises(ValueError) as exc:
            AngleFormatterLocator(values=[1., 2.], number=5)
        assert exc.value.args[0] == "At most one of values/number/spacing can be specifed"

        with pytest.raises(ValueError) as exc:
            AngleFormatterLocator(values=[1., 2.], spacing=5. * u.deg)
        assert exc.value.args[0] == "At most one of values/number/spacing can be specifed"

        with pytest.raises(ValueError) as exc:
            AngleFormatterLocator(number=5, spacing=5. * u.deg)
        assert exc.value.args[0] == "At most one of values/number/spacing can be specifed"

        with pytest.raises(ValueError) as exc:
            AngleFormatterLocator(values=[1., 2.], number=5, spacing=5. * u.deg)
        assert exc.value.args[0] == "At most one of values/number/spacing can be specifed"
    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_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.])
    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.])
Пример #11
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), [])
Пример #12
0
 def test_format(self, format, string):
     fl = AngleFormatterLocator(number=5, format=format)
     print(fl.formatter([15.392231] * u.degree, None, format='ascii')[0], string)
     assert fl.formatter([15.392231] * u.degree, None, format='ascii')[0] == string
Пример #13
0
 def test_latex_format(self):
     fl = AngleFormatterLocator(number=5, format="dd:mm:ss")
     assert fl.formatter([15.392231] * u.degree, None)[0] == '15\xb023\'32"'
     with rc_context(rc={'text.usetex': True}):
         assert fl.formatter([15.392231] * u.degree, None)[0] == "$15^\\circ23{}^\\prime32{}^{\\prime\\prime}$"
Пример #14
0
 def test_incompatible_unit_decimal(self):
     with pytest.raises(UnitsError) as exc:
         AngleFormatterLocator(unit=u.arcmin, decimal=False)
     assert exc.value.args[
         0] == 'Units should be degrees or hours when using non-decimal (sexagesimal) mode'
Пример #15
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)
Пример #16
0
 def test_formatter_no_format(self, spacing, string):
     fl = AngleFormatterLocator()
     assert fl.formatter([15.392231] * u.degree, spacing)[0] == string
Пример #17
0
 def test_base_spacing(self, format, base_spacing):
     fl = AngleFormatterLocator(number=5, format=format)
     assert fl.base_spacing == base_spacing
Пример #18
0
 def test_invalid_formats(self, format):
     fl = AngleFormatterLocator(number=5)
     with pytest.raises(ValueError) as exc:
         fl.format = format
     assert exc.value.args[0] == "Invalid format: " + format
Пример #19
0
 def test_incorrect_spacing(self):
     fl = AngleFormatterLocator()
     fl.spacing = 0.032 * u.deg
     with pytest.warns(UserWarning, match='Spacing is not a multiple of base spacing'):
         fl.format = 'dd:mm:ss'
     assert_almost_equal(fl.spacing.to_value(u.arcsec), 115.)
Пример #20
0
 def test_invalid_formats(self, format):
     fl = AngleFormatterLocator(number=5)
     with pytest.raises(ValueError) as exc:
         fl.format = format
     assert exc.value.args[0] == "Invalid format: " + format
Пример #21
0
    def test_no_options(self):

        fl = AngleFormatterLocator()
        assert fl.values is None
        assert fl.number == 5
        assert fl.spacing is None
Пример #22
0
 def test_separator(self, separator, format, string):
     fl = AngleFormatterLocator(number=5, format=format)
     fl.sep = separator
     assert fl.formatter([15.392231] * u.degree, None)[0] == string
Пример #23
0
 def test_format(self, format, string):
     fl = AngleFormatterLocator(number=5, format=format)
     assert fl.formatter([15.392231] * u.degree, None,
                         format='ascii')[0] == string
Пример #24
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)
Пример #25
0
 def test_separator(self, separator, format, string):
     fl = AngleFormatterLocator(number=5, format=format)
     fl.sep = separator
     assert fl.formatter([15.392231] * u.degree, None)[0] == string
Пример #26
0
 def test_formatter_no_format(self, spacing, string):
     fl = AngleFormatterLocator()
     assert fl.formatter([15.392231] * u.degree, spacing)[0] == string
Пример #27
0
 def test_formatter_no_format_with_units(self, format_unit, decimal, show_decimal_unit, spacing, ascii, latex):
     # Check the formatter works when specifying the default units and
     # decimal behavior to use.
     fl = AngleFormatterLocator(unit=u.degree, format_unit=format_unit, decimal=decimal, show_decimal_unit=show_decimal_unit)
     assert fl.formatter([15.392231] * u.degree, spacing, format='ascii')[0] == ascii
     assert fl.formatter([15.392231] * u.degree, spacing, format='latex')[0] == latex