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.)
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)
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.])
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_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)
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
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.)
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