def test_latex_format(self): fl = AngleFormatterLocator(number=5, format="dd:mm:ss") assert fl.formatter([15.392231] * u.degree, None)[0] == six.u('15\xb023\'32"') from ..rc_utils import rc_context with rc_context(rc={'text.usetex': True}): assert fl.formatter([15.392231] * u.degree, None)[0] == "15$^\circ$23'32\""
def test_overlay_coords(self, tmpdir): wcs = WCS(self.msx_header) fig = plt.figure(figsize=(4,4)) canvas = fig.canvas ax = WCSAxes(fig, [0.1, 0.1, 0.8, 0.8], wcs=wcs) fig.add_axes(ax) # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join('test1.png').strpath) # Testing default displayed world coordinates string_world = ax._display_world_coords(0.523412, 0.518311) assert string_world == six.u('0\xb029\'45" -0\xb029\'20" (world)') # Test pixel coordinates event1 = KeyEvent('test_pixel_coords', canvas, 'w') fig.canvas.key_press_event(event1.key, guiEvent=event1) string_pixel = ax._display_world_coords(0.523412, 0.523412) assert string_pixel == "0.523412 0.523412 (pixel)" event3 = KeyEvent('test_pixel_coords', canvas, 'w') fig.canvas.key_press_event(event3.key, guiEvent=event3) # Test that it still displays world coords when there are no overlay coords string_world2 = ax._display_world_coords(0.523412, 0.518311) assert string_world2 == six.u('0\xb029\'45" -0\xb029\'20" (world)') overlay = ax.get_coords_overlay('fk5') # Regression test for bug that caused format to always be taken from # main world coordinates. overlay[0].set_major_formatter('d.dddd') # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join('test2.png').strpath) event4 = KeyEvent('test_pixel_coords', canvas, 'w') fig.canvas.key_press_event(event4.key, guiEvent=event4) # Test that it displays the overlay world coordinates string_world3 = ax._display_world_coords(0.523412, 0.518311) assert string_world3 == six.u('267.1757 -28\xb045\'56" (world, overlay 1)')
def formatter(self, values, spacing): if not isinstance(values, u.Quantity) and values is not None: raise TypeError("values should be a Quantities array") if len(values) > 0: if self.format is None: spacing = spacing.to(u.arcsec).value if spacing > 3600: fields = 1 precision = 0 elif spacing > 60: fields = 2 precision = 0 elif spacing > 1: fields = 3 precision = 0 else: fields = 3 precision = -int(np.floor(np.log10(spacing))) decimal = False unit = u.degree else: fields = self._fields precision = self._precision decimal = self._decimal unit = self._unit if decimal: sep = None elif self._sep is not None: sep = self._sep else: if unit == u.degree: if rcParams['text.usetex']: deg = r'$^\circ$' else: deg = six.u('\xb0') sep = (deg, "'", '"') else: sep = ('h', 'm', 's') angles = Angle(values) string = angles.to_string(unit=unit, precision=precision, decimal=decimal, fields=fields, sep=sep).tolist() return string else: return []
def test_cube_coords(self, tmpdir): wcs = WCS(self.cube_header) fig = plt.figure(figsize=(4,4)) canvas = fig.canvas ax = WCSAxes(fig, [0.1, 0.1, 0.8, 0.8], wcs=wcs, slices=('y', 50, 'x')) fig.add_axes(ax) # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join('test.png').strpath) # Testing default displayed world coordinates string_world = ax._display_world_coords(0.523412, 0.518311) assert string_world == six.u('2563 51\xb043\'01" (world)') # Test pixel coordinates event1 = KeyEvent('test_pixel_coords', canvas, 'w') fig.canvas.key_press_event(event1.key, guiEvent=event1) string_pixel = ax._display_world_coords(0.523412, 0.523412) assert string_pixel == "0.523412 0.523412 (pixel)"
def test_cube_coords(self, tmpdir): wcs = WCS(self.cube_header) fig = plt.figure(figsize=(4, 4)) canvas = fig.canvas ax = WCSAxes(fig, [0.1, 0.1, 0.8, 0.8], wcs=wcs, slices=('y', 50, 'x')) fig.add_axes(ax) # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join('test.png').strpath) # Testing default displayed world coordinates string_world = ax._display_world_coords(0.523412, 0.518311) assert string_world == six.u('2563 51\xb043\'01" (world)') # Test pixel coordinates event1 = KeyEvent('test_pixel_coords', canvas, 'w') fig.canvas.key_press_event(event1.key, guiEvent=event1) string_pixel = ax._display_world_coords(0.523412, 0.523412) assert string_pixel == "0.523412 0.523412 (pixel)"
1)] ## -- Options for the edit_on_github extension ---------------------------------------- if eval(setup_cfg.get('edit_on_github')): extensions += ['astropy.sphinx.ext.edit_on_github'] versionmod = __import__(setup_cfg['package_name'] + '.version') edit_on_github_project = setup_cfg['github_project'] if versionmod.release: edit_on_github_branch = "v" + versionmod.version else: edit_on_github_branch = "master" edit_on_github_source_root = "" edit_on_github_doc_root = "docs" github_issues_url = 'https://github.com/astropy/photutils/issues/' autodoc_docstring_signature = True nitpicky = True nitpick_ignore = [] for line in open('nitpick-exceptions'): if line.strip() == "" or line.startswith("#"): continue dtype, target = line.split(None, 1) target = target.strip() nitpick_ignore.append((dtype, six.u(target)))
edit_on_github_skip_regex = '_.*|api/.*' github_issues_url = 'https://github.com/astropy/astropy/issues/' # Enable nitpicky mode - which ensures that all references in the docs # resolve. nitpicky = True nitpick_ignore = [] for line in open('nitpick-exceptions'): if line.strip() == "" or line.startswith("#"): continue dtype, target = line.split(None, 1) target = target.strip() nitpick_ignore.append((dtype, six.u(target))) if six.PY2: nitpick_ignore.extend([('py:obj', six.u('bases'))]) # -- Options for the Sphinx gallery ------------------------------------------- try: import sphinx_gallery extensions += ["sphinx_gallery.gen_gallery"] sphinx_gallery_conf = { 'backreferences_dir': 'generated/modules', # path to store the module using example template 'filename_pattern': '^((?!skip_).)*$', # execute all examples except those that start with "skip_" 'examples_dirs': '..{}examples'.format(os.sep), # path to the examples scripts 'gallery_dirs': 'generated/examples', # path to save gallery generated examples
edit_on_github_skip_regex = '_.*|api/.*' github_issues_url = 'https://github.com/astropy/astropy/issues/' # Enable nitpicky mode - which ensures that all references in the docs # resolve. nitpicky = True nitpick_ignore = [] for line in open('nitpick-exceptions'): if line.strip() == "" or line.startswith("#"): continue dtype, target = line.split(None, 1) target = target.strip() nitpick_ignore.append((dtype, six.u(target))) if six.PY2: nitpick_ignore.extend([('py:obj', six.u('bases'))]) # -- Options for the Sphinx gallery ------------------------------------------- try: import sphinx_gallery extensions += ["sphinx_gallery.gen_gallery"] sphinx_gallery_conf = { 'mod_example_dir': 'generated/modules', # path to store the module using example template 'filename_pattern': '^((?!skip_).)*$', # execute all examples except those that start with "skip_" 'examples_dirs': '..{}examples'.format(os.sep), # path to the examples scripts 'gallery_dirs': 'generated/examples', # path to save gallery generated examples
edit_on_github_source_root = "" edit_on_github_doc_root = "docs" github_issues_url = "https://github.com/astropy/photutils/issues/" autodoc_docstring_signature = True nitpicky = True nitpick_ignore = [] for line in open("nitpick-exceptions"): if line.strip() == "" or line.startswith("#"): continue dtype, target = line.split(None, 1) target = target.strip() nitpick_ignore.append((dtype, six.u(target))) # a simple non-configurable extension that generates Rst files from jupyter # notebooks def notebooks_to_rst(app): from glob import glob try: # post "big-split", nbconvert is a separate namespace from nbconvert.nbconvertapp import NbConvertApp from nbconvert.writers import FilesWriter from nbconvert.preprocessors import Preprocessor, ExecutePreprocessor, execute from nbconvert.exporters import RSTExporter from nbformat import NotebookNode except ImportError:
# Don't import the module as "version" or it will override the # "version" configuration parameter from astropy import version as versionmod edit_on_github_project = "astropy/astropy" if versionmod.release: edit_on_github_branch = "v{0}.{1}.x".format(versionmod.major, versionmod.minor) else: edit_on_github_branch = "master" edit_on_github_source_root = "" edit_on_github_doc_root = "docs" github_issues_url = "https://github.com/astropy/astropy/issues/" # Enable nitpicky mode - which ensures that all references in the docs # resolve. nitpicky = True nitpick_ignore = [] for line in open("nitpick-exceptions"): if line.strip() == "" or line.startswith("#"): continue dtype, target = line.split(None, 1) target = target.strip() nitpick_ignore.append((dtype, six.u(target))) if six.PY2: nitpick_ignore.extend([("py:obj", six.u("bases"))])
def test_overlay_coords(self, tmpdir): wcs = WCS(self.msx_header) fig = plt.figure(figsize=(4, 4)) canvas = fig.canvas ax = WCSAxes(fig, [0.1, 0.1, 0.8, 0.8], wcs=wcs) fig.add_axes(ax) # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join('test1.png').strpath) # Testing default displayed world coordinates string_world = ax._display_world_coords(0.523412, 0.518311) assert string_world == six.u('0\xb029\'45" -0\xb029\'20" (world)') # Test pixel coordinates event1 = KeyEvent('test_pixel_coords', canvas, 'w') fig.canvas.key_press_event(event1.key, guiEvent=event1) string_pixel = ax._display_world_coords(0.523412, 0.523412) assert string_pixel == "0.523412 0.523412 (pixel)" event3 = KeyEvent('test_pixel_coords', canvas, 'w') fig.canvas.key_press_event(event3.key, guiEvent=event3) # Test that it still displays world coords when there are no overlay coords string_world2 = ax._display_world_coords(0.523412, 0.518311) assert string_world2 == six.u('0\xb029\'45" -0\xb029\'20" (world)') overlay = ax.get_coords_overlay('fk5') # Regression test for bug that caused format to always be taken from # main world coordinates. overlay[0].set_major_formatter('d.ddd') # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join('test2.png').strpath) event4 = KeyEvent('test_pixel_coords', canvas, 'w') fig.canvas.key_press_event(event4.key, guiEvent=event4) # Test that it displays the overlay world coordinates string_world3 = ax._display_world_coords(0.523412, 0.518311) assert string_world3 == six.u( '267.176 -28\xb045\'56" (world, overlay 1)') overlay = ax.get_coords_overlay(FK5()) # Regression test for bug that caused format to always be taken from # main world coordinates. overlay[0].set_major_formatter('d.ddd') # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join('test3.png').strpath) event5 = KeyEvent('test_pixel_coords', canvas, 'w') fig.canvas.key_press_event(event4.key, guiEvent=event4) # Test that it displays the overlay world coordinates string_world4 = ax._display_world_coords(0.523412, 0.518311) assert string_world4 == six.u( '267.176 -28\xb045\'56" (world, overlay 2)') overlay = ax.get_coords_overlay(FK5(equinox=Time("J2030"))) # Regression test for bug that caused format to always be taken from # main world coordinates. overlay[0].set_major_formatter('d.ddd') # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join('test4.png').strpath) event6 = KeyEvent('test_pixel_coords', canvas, 'w') fig.canvas.key_press_event(event5.key, guiEvent=event4) # Test that it displays the overlay world coordinates string_world5 = ax._display_world_coords(0.523412, 0.518311) assert string_world5 == six.u( '267.652 -28\xb046\'23" (world, overlay 3)')
class TestAngleFormatterLocator(object): def test_no_options(self): fl = AngleFormatterLocator() assert fl.values is None assert fl.number == 5 assert fl.spacing is None 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_values(self): fl = AngleFormatterLocator(values=[0.1, 1., 14.] * u.degree) assert fl.values.to(u.degree).value.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(u.degree).value, [0.1, 1., 14.]) 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(u.degree).value, [35., 40., 45., 50., 55.]) values, spacing = fl.locator(34.3, 36.1) assert_almost_equal( values.to(u.degree).value, [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(u.degree).value, [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(u.degree).value, [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(u.degree).value, [34.5, 35., 35.5, 36.]) fl.format = 'dd' values, spacing = fl.locator(34.3, 36.1) assert_almost_equal(values.to(u.degree).value, [35., 36.]) 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(u.degree).value, [ 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(u.degree).value, [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(u.degree).value, []) @pytest.mark.parametrize(('format', 'string'), [ ('dd', six.u('15\xb0')), ('dd:mm', six.u('15\xb024\'')), ('dd:mm:ss', six.u('15\xb023\'32"')), ('dd:mm:ss.s', six.u('15\xb023\'32.0"')), ('dd:mm:ss.ssss', six.u('15\xb023\'32.0316"')), ('hh', '1h'), ('hh:mm', '1h02m'), ('hh:mm:ss', '1h01m34s'), ('hh:mm:ss.s', '1h01m34.1s'), ('hh:mm:ss.ssss', '1h01m34.1354s'), ('d', '15'), ('d.d', '15.4'), ('d.dd', '15.39'), ('d.ddd', '15.392'), ('m', '924'), ('m.m', '923.5'), ('m.mm', '923.53'), ('s', '55412'), ('s.s', '55412.0'), ('s.ss', '55412.03'), ]) def test_format(self, format, string): fl = AngleFormatterLocator(number=5, format=format) assert fl.formatter([15.392231] * u.degree, None)[0] == string @pytest.mark.parametrize(('separator', 'format', 'string'), [ (('deg', "'", '"'), 'dd', '15deg'), (('deg', "'", '"'), 'dd:mm', '15deg24\''), (('deg', "'", '"'), 'dd:mm:ss', '15deg23\'32"'), ((':', "-", 's'), 'dd:mm:ss.s', '15:23-32.0s'), (':', 'dd:mm:ss.s', '15:23:32.0'), ((':', ":", 's'), 'hh', '1:'), (('-', "-", 's'), 'hh:mm:ss.ssss', '1-01-34.1354s'), (('d', ":", '"'), 'd', '15'), (('d', ":", '"'), 'd.d', '15.4'), ]) 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 def test_latex_format(self): fl = AngleFormatterLocator(number=5, format="dd:mm:ss") assert fl.formatter([15.392231] * u.degree, None)[0] == six.u('15\xb023\'32"') from ..rc_utils import rc_context with rc_context(rc={'text.usetex': True}): assert fl.formatter([15.392231] * u.degree, None)[0] == "15$^\circ$23'32\"" @pytest.mark.parametrize(('format'), ['x.xxx', 'dd.ss', 'dd:ss', 'mdd:mm:ss']) 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 @pytest.mark.parametrize(('format', 'base_spacing'), [ ('dd', 1. * u.deg), ('dd:mm', 1. * u.arcmin), ('dd:mm:ss', 1. * u.arcsec), ('dd:mm:ss.ss', 0.01 * u.arcsec), ('hh', 15. * u.deg), ('hh:mm', 15. * u.arcmin), ('hh:mm:ss', 15. * u.arcsec), ('hh:mm:ss.ss', 0.15 * u.arcsec), ('d', 1. * u.deg), ('d.d', 0.1 * u.deg), ('d.dd', 0.01 * u.deg), ('d.ddd', 0.001 * u.deg), ('m', 1. * u.arcmin), ('m.m', 0.1 * u.arcmin), ('m.mm', 0.01 * u.arcmin), ('s', 1. * u.arcsec), ('s.s', 0.1 * u.arcsec), ('s.ss', 0.01 * u.arcsec), ]) def test_base_spacing(self, format, base_spacing): fl = AngleFormatterLocator(number=5, format=format) assert fl.base_spacing == base_spacing def test_incorrect_spacing(self): fl = AngleFormatterLocator() fl.spacing = 0.032 * u.deg fl.format = 'dd:mm:ss' assert_almost_equal(fl.spacing.to(u.arcsec).value, 115.) @pytest.mark.parametrize(('spacing', 'string'), [(2 * u.deg, six.u('15\xb0')), (2 * u.arcmin, six.u('15\xb024\'')), (2 * u.arcsec, six.u('15\xb023\'32"')), (0.1 * u.arcsec, six.u('15\xb023\'32.0"'))]) def test_formatter_no_format(self, spacing, string): fl = AngleFormatterLocator() assert fl.formatter([15.392231] * u.degree, spacing)[0] == string
def test_overlay_coords(self, tmpdir): wcs = WCS(self.msx_header) fig = plt.figure(figsize=(4, 4)) canvas = fig.canvas ax = WCSAxes(fig, [0.1, 0.1, 0.8, 0.8], wcs=wcs) fig.add_axes(ax) # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join("test1.png").strpath) # Testing default displayed world coordinates string_world = ax._display_world_coords(0.523412, 0.518311) assert string_world == six.u("0\xb029'45\" -0\xb029'20\" (world)") # Test pixel coordinates event1 = KeyEvent("test_pixel_coords", canvas, "w") fig.canvas.key_press_event(event1.key, guiEvent=event1) string_pixel = ax._display_world_coords(0.523412, 0.523412) assert string_pixel == "0.523412 0.523412 (pixel)" event3 = KeyEvent("test_pixel_coords", canvas, "w") fig.canvas.key_press_event(event3.key, guiEvent=event3) # Test that it still displays world coords when there are no overlay coords string_world2 = ax._display_world_coords(0.523412, 0.518311) assert string_world2 == six.u("0\xb029'45\" -0\xb029'20\" (world)") overlay = ax.get_coords_overlay("fk5") # Regression test for bug that caused format to always be taken from # main world coordinates. overlay[0].set_major_formatter("d.ddd") # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join("test2.png").strpath) event4 = KeyEvent("test_pixel_coords", canvas, "w") fig.canvas.key_press_event(event4.key, guiEvent=event4) # Test that it displays the overlay world coordinates string_world3 = ax._display_world_coords(0.523412, 0.518311) assert string_world3 == six.u("267.176 -28\xb045'56\" (world, overlay 1)") overlay = ax.get_coords_overlay(FK5()) # Regression test for bug that caused format to always be taken from # main world coordinates. overlay[0].set_major_formatter("d.ddd") # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join("test3.png").strpath) event5 = KeyEvent("test_pixel_coords", canvas, "w") fig.canvas.key_press_event(event4.key, guiEvent=event4) # Test that it displays the overlay world coordinates string_world4 = ax._display_world_coords(0.523412, 0.518311) assert string_world4 == six.u("267.176 -28\xb045'56\" (world, overlay 2)") overlay = ax.get_coords_overlay(FK5(equinox=Time("J2030"))) # Regression test for bug that caused format to always be taken from # main world coordinates. overlay[0].set_major_formatter("d.ddd") # On some systems, fig.canvas.draw is not enough to force a draw, so we # save to a temporary file. fig.savefig(tmpdir.join("test4.png").strpath) event6 = KeyEvent("test_pixel_coords", canvas, "w") fig.canvas.key_press_event(event5.key, guiEvent=event4) # Test that it displays the overlay world coordinates string_world5 = ax._display_world_coords(0.523412, 0.518311) assert string_world5 == six.u("267.652 -28\xb046'23\" (world, overlay 3)")