Skip to content

More WCS convenience functions: pixel_scale, celestial - #2832

Merged
mdboom merged 31 commits into
astropy:masterfrom
keflavich:pixscale
Sep 22, 2014
Merged

mdboom merged 31 commits into
astropy:masterfrom
keflavich:pixscale

Conversation

@keflavich

Copy link
Copy Markdown
Contributor

Some more WCS convenience attributes:

wcs.pixel_scale returns the pixel scale ("plate scale") in degrees in the celestial dimensions if the pixels are symmetric (otherwise, it raises an exception)
wcs.celestial returns a copy of the celestial component of the WCS

Question: Should wcs.pixel_scale return a Quantity?

cc @mdboom

@keflavich

Copy link
Copy Markdown
Contributor Author

cc @astrofrog too

To any: are there cases I might be missing? i.e., are there occasions in which pc should be checked?

EDIT: There are errors here - this only works if the pixels are aligned with the grid at the moment

Comment thread astropy/wcs/wcs.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.

From experience with APLpy, I think the correct approach is:

https://github.com/aplpy/aplpy/blob/master/aplpy/wcs_util.py#L83

This was the result of many iterations :)

@astrofrog

Copy link
Copy Markdown
Member

I have mixed feelings about this - strictly speaking the pixel scale changes over the image with the exception of the CAR projection. In addition, it is only really meaningful for WCS with celestial axes. I wonder whether this could not be a function rather than a method on the class (I find it more acceptable to have a function that only works in very specific instances compared to a method, which makes it seem more general).

@keflavich

Copy link
Copy Markdown
Contributor Author

Good points @astrofrog, I'll address these comments. I am a bit tired of having to recalculate pixel scale "from scratch" all the time; for the vast majority of my work the square-pixel approximation is perfect. But, I concede the point that the pixel size is not uniform, so a warning will be included.

However, I must be writing my test incorrectly, because I get a failure for a filled CD matrix when trying the aplpy approach.

Comment thread astropy/wcs/tests/test_utils.py Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This doesn't work: recwarn.list is empty. Why?

@keflavich

Copy link
Copy Markdown
Contributor Author

@astrofrog ready for final review

@astrofrog

Copy link
Copy Markdown
Member

@keflavich - will review this later today, but what do you think of my suggestion of moving these into utils rather than have them be methods of WCS? Also, I think we should maybe rename get_pixel_scale to get_celestial_pixel_scale since it only really applies to those projections, right?

@keflavich

Copy link
Copy Markdown
Contributor Author

I don't like the idea of moving these to utils - especially celestial is pointless unless it's an attribute, because it's just a very slim wrapper around wcs.sub, but I think it is a more intuitive interface for those not familiar with the wcslib internals. get_pixel_scale I think should be kept in the same location as get_cdelt since it's a comparable concept.

However, renaming sounds appropriate - it's a bit verbose, but that's OK. get_plate_scale would also be appropriate, but I think that terminology is CCD-specific.

@astrofrog

Copy link
Copy Markdown
Member

@keflavich what about get_celestial_scale and drop the pixel?

@keflavich

Copy link
Copy Markdown
Contributor Author

@astrofrog - that sounds good. Might be worth bouncing it off one or two others... just ask someone down the hall what they think get_celestial_scale means?

@astrofrog

Copy link
Copy Markdown
Member

@keflavich - I was thinking about this some more and I really do think that while celestial is fine in WCS, get_celestial_scale is specific enough that it really does belong in the utils as a standalone function. I think it would make sense to have get_pixel_scale in WCS if it did actually work for any WCS. Having said that, I think that the logic of the matrix multiplication (before you do the squaring stuff) could belong in a more general method on WCS and could work with any WCS. What do you think? So basically having a way of returning that final matrix so we don't have to mess around with pc, cdelt, etc.

@keflavich

Copy link
Copy Markdown
Contributor Author

That last bit is a pretty good idea, and easy to implement - what should we call it? wcs.cd_matrix? wcs.transform_matrix? I like the latter for semantically distinguishing it from the FITS WCS keywords.

I guess I can move get_celestial_scale to utils. I should probably just rename it celestial_scale in that case, since get implies a class method?

@astrofrog

Copy link
Copy Markdown
Member

@keflavich - not sure if I'd call it cd_matrix since there's already get_cd, right? (but that doesn't work when there's no actual CD matrix?). What about pixel_scale_matrix.

+1 to celestial_scale for the utils function.

@keflavich

Copy link
Copy Markdown
Contributor Author

Added the matrix. No time for tests now.

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.

Here I think you can then make use of the pixel scale matrix?

@astrofrog

Copy link
Copy Markdown
Member

@nden - since you are familiar with the WCS code, do you have any thoughts on this pull request so far?

@astrofrog

Copy link
Copy Markdown
Member

What would be nice in future would be to have a way of computing the pixel scale at a specific position. This would then make it easy to check how much the pixel scale is changing over the image and emit a warning if needed.

@nden

nden commented Aug 21, 2014

Copy link
Copy Markdown
Contributor

It looks good to me. I think it makes sense to name the function reference_celestial_scale or something similar which clarifies the intention and get rid of the warning.
Out of curiosity, why not return both scale values and issue a warning if they are different instead of raise an error? (I don't know how this is intended to be used but for HST, for examle, it will always raise an error.)

@keflavich

Copy link
Copy Markdown
Contributor Author

@astrofrog - this includes many of the changes from aplpy/aplpy#211 now and is much more flexible.

Can anyone provide a sanity check on the test parameters?

Comment thread CHANGES.rst 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.

pixel_scale -> pixel_scale_matrix

@keflavich

Copy link
Copy Markdown
Contributor Author

Bump - this is ready for review.

@mdboom

mdboom commented Sep 22, 2014

Copy link
Copy Markdown
Contributor

Cool!

mdboom added a commit that referenced this pull request Sep 22, 2014
More WCS convenience functions: pixel_scale, celestial
@mdboom
mdboom merged commit 0c4d4f4 into astropy:master Sep 22, 2014
@keflavich
keflavich deleted the pixscale branch September 22, 2014 14:05
@embray embray added this to the v1.0.0 milestone Feb 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants