Skip to content

Added a new function to convert SkyCoord to pixel coordinates - #2885

Merged
astrofrog merged 12 commits into
astropy:masterfrom
astrofrog:skycoord-to-pixel
Sep 30, 2014
Merged

astrofrog merged 12 commits into
astropy:masterfrom
astrofrog:skycoord-to-pixel

Conversation

@astrofrog

Copy link
Copy Markdown
Member

@mdboom @nden - would something like this be acceptable in astropy.wcs? I need it in various project and it will also make the implementation of #2210 easy.

If you think it would be ok, then I can go ahead and add some tests and a changelog entry.

@astrofrog

Copy link
Copy Markdown
Member Author

There is the question of whether we can in some cases interpret the third coordinate of SkyCoord (if present but I can't think of a WCS where this would be appropriate).

cc @eteq and @taldcroft, since they've also thought a lot about coordinates :)

@astrofrog

Copy link
Copy Markdown
Member Author

Of course, I could easily add pixel_to_skycoord too :)

Comment thread astropy/wcs/utils.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

perhaps the origin keyword should be available in the convinience function? That is, change the signature of this function to (coords, wcs, wcsorigin=0), and then to the world2pix call as wcs.wcs_world2pix(lon, lat, origin)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah yes, of course

@eteq

eteq commented Aug 22, 2014

Copy link
Copy Markdown
Member

👍 to this, but I would say it should also include pixel_to_skycoord (although of course no point in doing so if other people are against this for some reason)

@astrofrog

Copy link
Copy Markdown
Member Author

@eteq - yes, I'll wait to make sure there are no objections, the inverse function is trivial to add.

@mdboom

mdboom commented Aug 25, 2014

Copy link
Copy Markdown
Contributor

I have no objections. Should this be a free function or a method though?

EDIT: I see with #2210 where this is ultimately going, so this is fine as-is.

Comment thread astropy/wcs/utils.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there no better way of doing this? The reason I ask is SunPy uses a custom spherical representation to deal with 180 wrapping, which this will undo.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I can use coords.data.lon instead but I should fall back on coords.spherical.lon if the representation doesn't have lon/lat.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That will probably work, still feels a little hacky (in general) though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Using data.lon shouldn't be hacky in the sense that this is the true underlying representation. In your view, should creating a new spherical representation preserve the Longitude/Latitude classes/settings? If so, it might make sense to open a new issue for this to discuss it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having it do that would be easier, but it might not always be the desired behaviour. I am just concerned that in general there is no real provision for extracting data in predictable fashion which preserved things like custom representations.

(as an aside, I think there should be a way to convert a representation to a Quantity object for piping into different code)

@astrofrog

Copy link
Copy Markdown
Member Author

@mdboom - I've added a pixel to skycoord conversion function to. So at the moment my open questions are:

  • the functions use the wcs.wcs_* functions but of course maybe we want to use all_* or maybe allow both (or more?)
  • at the moment, only 2-d WCS are supported because otherwise if one has a 3-d cube where the celestial WCS is correlated with the spectral dimension, things won't work properly.

I'm not sure what the preferred solution is in each case - @mdboom, do you have any suggestions?

@astrofrog

Copy link
Copy Markdown
Member Author

@mdboom - do you have any thoughts on the questions I had above? The issue of 2d vs higher dimensional is probably less urgent, but I'm not sure what the best approach is for allowing the user to select between the different functions. Maybe it would be better after all to simply integrate this at the WCS level rather than having separate functions?

@astrofrog

Copy link
Copy Markdown
Member Author

@mdboom - just a reminder, if you get a chance, could you let me know what you think about the possible solutions described above?

@mdboom

mdboom commented Sep 19, 2014

Copy link
Copy Markdown
Contributor

@astrofrog wrote:

the functions use the wcs.wcs_* functions but of course maybe we want to use all_* or maybe allow both (or more?)

I think using all_* is the least confusing, except that it may result in an iterative solution is a distortion image is included in the WCS. I guess make it an kwarg, with all being the default.

@astrofrog wrote:

at the moment, only 2-d WCS are supported because otherwise if one has a 3-d cube where the celestial WCS is correlated with the spectral dimension, things won't work properly.

This won't work if there are SIP or distortion information, but if you call sub(WCSSUB_CELESTIAL) it will extract the celestial axes and fail if they are corelated with any other axes.

So maybe do this: If there is sip or distortion, and naxis != 2, throw an exception. If there is neither sip or distorion, call sub(WCSSUB_CELESTIAL), and let the exception bubble out if it fails.

@astrofrog

Copy link
Copy Markdown
Member Author

@mdboom - thanks, that all sounds reasonable. Since I've never really had to deal with distortions before, is it correct that I can check wcs.sip is None to check if there are SIP distorions? What other kind of distortions can be present, and how do I test for that?

@mdboom

mdboom commented Sep 19, 2014

Copy link
Copy Markdown
Contributor

Yes -- you can juts check is None for any of the distorations. There are also lookup table distortions. The complete list is here: http://docs.astropy.org/en/stable/api/astropy.wcs.WCSBase.html#wcsbase

@astrofrog astrofrog added this to the v1.0.0 milestone Sep 19, 2014
@astrofrog

Copy link
Copy Markdown
Member Author

@mdboom - ok, thanks! I've now implemented your comments, so I think this is ready for final review (after a rebase it seems)

Comment thread astropy/wcs/utils.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe make this a method on astropy.wcs.WCS?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've done this and have made it a propery

@astrofrog

Copy link
Copy Markdown
Member Author

@mdboom - I've addressed your comments, so if Travis passes this is good to go!

@astrofrog

Copy link
Copy Markdown
Member Author

@mdboom - I have now rebased this, can this be merged if Travis passes?

Comment thread astropy/wcs/wcs.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this needs a @property decorator to get the tests to pass.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oops, I think this was lost during a rebase.

@astrofrog

Copy link
Copy Markdown
Member Author

@mdboom - I addressed your comment and travis passes, so I'll go ahead and merge tomorrow if there are no remaining comments (though feel free to merge first if you come across this)

astrofrog added a commit that referenced this pull request Sep 30, 2014
Added a new function to convert SkyCoord to pixel coordinates
@astrofrog
astrofrog merged commit 820bf52 into astropy:master Sep 30, 2014
@eteq eteq mentioned this pull request Sep 30, 2014
@astrofrog
astrofrog deleted the skycoord-to-pixel branch July 5, 2016 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants