def test_cube_coords_uncorr_slicing(self, tmpdir): # Regression test for a bug that occurred with coordinate formatting if # some dimensions were uncorrelated and sliced out. 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=('x', 'y', 2)) 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 == '3h26m56.6s 30\xb018\'19\" (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_plot_topo_butterfly(): "Test plot.TopoButterfly" ds = datasets.get_uts(utsnd=True) # single row p = plot.TopoButterfly('utsnd', ds=ds) p.set_time(0.2) # t keypress on topomap x, y = p.topo_axes[0].transAxes.transform((.5, .5)) event = KeyEvent('test', p.canvas, 't', x, y, wx.KeyEvent()) p._on_key_press(event) p.close() p = plot.TopoButterfly('utsnd', ds=ds, vmax=0.2, w=6) p.close() # multiple rows p = plot.TopoButterfly('utsnd', 'A%B', ds=ds, w=6) if not IS_WINDOWS: assert (*p.figure.get_size_inches(), ) == (6, 12) # t keypress on topomaps for ax in p.topo_axes: x, y = ax.transAxes.transform((.5, .5)) event = KeyEvent('test', p.canvas, 't', x, y, wx.KeyEvent()) p._on_key_press(event) p.close() p = plot.TopoButterfly('utsnd', mark=[1, 2], ds=ds) p.close() p = plot.TopoButterfly('utsnd', mark=['1', '2'], ds=ds) p.set_vlim(2) assert p.get_vlim() == (-2.0, 2.0) p.set_ylim(-1, 1) assert p.get_ylim() == (-1.0, 1.0) p.close()
def _process_event(name, ax, coords, *args): if name == "__mouse_click__": # So that the dragging callbacks don't go crazy. _process_event("button_press_event", ax, coords, *args) _process_event("button_release_event", ax, coords, *args) return display_coords = ax.transData.transform_point(coords) if name in ["button_press_event", "button_release_event", "motion_notify_event", "scroll_event"]: event = MouseEvent(name, ax.figure.canvas, *display_coords, *args) elif name in ["key_press_event", "key_release_event"]: event = KeyEvent(name, ax.figure.canvas, *args, *display_coords) else: raise ValueError("Unknown event name {!r}".format(name)) ax.figure.canvas.callbacks.process(name, event)
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 == '2563 3h26m52.0s (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_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 == '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 == '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 == '267.176\xb0 -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 == '267.176\xb0 -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=event6) # Test that it displays the overlay world coordinates string_world5 = ax._display_world_coords(0.523412, 0.518311) assert string_world5 == '267.652\xb0 -28\xb046\'23" (world, overlay 3)'