Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Refactor WCS handling #24

Merged
merged 15 commits into from Apr 23, 2014
Merged

Refactor WCS handling #24

merged 15 commits into from Apr 23, 2014

Conversation

astrofrog
Copy link
Owner

This is work in progress, and includes the refactoring carried out during the ALMA software development workshop at NRAO.

cc @ChrisBeaumont - there are still a couple of things to add, but this will then be ready for you to test with glue and optimize if needed.

@astrofrog
Copy link
Owner Author

@ChrisBeaumont - this is ready for testing in Glue if you are interested. You now no longer need the WCSSlice object. You can do:

fig = plt.figure()
ax = WCSAxes(fig, [0.1, 0.1, 0.8, 0.8], w, slices=(100, 'y', 'x'))
fig.add_axes(ax)
ax.imshow(image[:,:,100].transpose(), cmap=plt.cm.gist_heat)

if you want to show a grid, you can, but when you call grid() you should pass the grid_type='contours' option. The grid will likely slow things down, so you are better off not using it if not needed.

Regardless of the grid type, all other transformations are now pixel to world, so should work on any arbitrary slices and images with distortions!

@ChrisBeaumont
Copy link
Contributor

cool, will try to look at this tomorrow

@ChrisBeaumont
Copy link
Contributor

Playing with this now, a few things seem broken:

  • RA ticks are bonkers
  • Extra unlabeled Dec ticks
  • X axis formatting on bottom + top, not just bottom

I'll keep investigating

from astropy.io import fits
from astropy.wcs import WCS
from wcsaxes import WCSAxes
import matplotlib.pyplot as plt

data = fits.open('/Users/beaumont/perseus/12co.fits')[0].data
wcs = WCS('/Users/beaumont/perseus/12co.fits')

fig = plt.figure()
ax = WCSAxes(fig, (.1, .1, .8, .8), wcs, slices=(100, 'y', 'x'))
fig.add_axes(ax)
ax.imshow(data[100, :, :], vmin=0, vmax=5)
plt.savefig('test.png')

test

@astrofrog
Copy link
Owner Author

@ChrisBeaumont - can you share the file?

@ChrisBeaumont
Copy link
Contributor

https://www.dropbox.com/s/wpr4wfavrif0q9u/12co.fits

On Mon, Apr 21, 2014 at 4:01 PM, Thomas Robitaille <notifications@github.com

wrote:

@ChrisBeaumont https://github.com/ChrisBeaumont - can you share the
file?


Reply to this email directly or view it on GitHubhttps://github.com//pull/24#issuecomment-40970788
.


Chris Beaumont
Graduate Student
Institute for Astronomy
University of Hawaii at Manoa
2680 Woodlawn Drive
Honolulu, HI 96822
www.ifa.hawaii.edu/~beaumont


@astrofrog
Copy link
Owner Author

@ChrisBeaumont - the solution turned out to be very simple - the slices argument is in the wrong order, so you are getting velocity ticks (which explains the values). Try using slices=('x', 'y', 100) and it should work better. I'm not sure what the best way to avoid this. Documentation? Or do you think the order is unnatural?

@astrofrog
Copy link
Owner Author

@ChrisBeaumont - I nevertheless found a few small things that should be fixed - namely that in this case, only the ticks for the non-sliced coordinate should be shown by default. I've pushed a fix.

self.coords[1].set_axislabel_position('l')
self.coords[0].set_ticklabel_position('b')
self.coords[1].set_ticklabel_position('l')
for coord_index in range(len(slices)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a graceful fallback here for slices=None. Something like for coord_index in range(len(slices or []))

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -9,7 +9,7 @@ def wrap_180(values):
return values_new


def find_coordinate_range(transform, extent, x_type='scalar', y_type='scalar'):
def find_coordinate_range(transform, extent, coord_types):
'''
Find the range of coordinates to use for ticks/grids

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extent isn't iterable, but list-like (you need random access)

@ChrisBeaumont
Copy link
Contributor

I proposed some improvements and a bugfix in #25, but otherwise this looks good to me!

astrofrog added a commit that referenced this pull request Apr 23, 2014
@astrofrog astrofrog merged commit 99a1666 into master Apr 23, 2014
astrofrog added a commit that referenced this pull request Nov 28, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants