-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pix2sky breaks at RA = +/- 180 due to reliance on floating-point arithmetic #202
Comments
(While |
Rotating the sky by 360° has no physical effect, so don't worry about map2alm or alm2map. Similarly, having postmap output coordinates that are 360° off from standard values doesn't really do anything either, it's just annoying. But it's worth it to fix that annoyance. I've made a fix, but I need a self-contained test case to test it. |
As discussed, the following example should produce an offending geometry:
gives
|
This should be fixed with commit #204 |
It seems like this may still be happening: import pixell
print(pixell.__version__)
from pixell import enmap
import numpy as np
print(np.rad2deg(enmap.pix2sky(*enmap.fullsky_geometry(res=np.deg2rad(1/120), variant='CC'), [[0], [0]])))
print(np.rad2deg(enmap.pix2sky(*enmap.fullsky_geometry(res=np.deg2rad(1/120), variant='fejer1'), [[0], [0]]))) gives
|
What's the bug here, @zatkins2? Fejer1 and CC aren't supposed to have the same coordinates for the first pixel. The output looks correct to me. |
Yes, the point of the code snippet was not that the Dec coordinates of the two geometries differ (of course they do), but rather that the RA coordinate of the first pixel is still -180 deg regardless of the ring scheme. I've just tested this again for the most-recent pixell version and it's the same: import pixell
print(pixell.__version__)
from pixell import enmap
import numpy as np
print(np.rad2deg(enmap.pix2sky(*enmap.fullsky_geometry(res=np.deg2rad(1/120), variant='CC'), [[0], [0]])))
print(np.rad2deg(enmap.pix2sky(*enmap.fullsky_geometry(res=np.deg2rad(1/120), variant='fejer1'), [[0], [0]]))) gives
|
I encountered a similar problem. A discrepancy between pixell.enmap.pix2sky and astropy.wcs.all_pix2world when converting pixel coordinates to world coordinates at the borders of a map. The RA and Dec values returned by pix2sky appear to be incorrect (Dec out of [-90, 90]), while astropy produces consistent and expected results. |
Description
enmap.pix2sky
andenmap.corners
callutils.rewind
to handle wrapping around the full-sky. The wayutils.rewind
is implemented is such that if a pixel RA center is within double precision ofnp.pi
, then the pixel returns a RA coordinate of-np.pi
(this line). In other words, the bottom-left corner of such a map,enmap.pix2sky(shape, wcs, [[0], [0]])
, will have a RA coordinate of-np.pi
, notnp.pi
as is thepixell
convention (see comment infullsky_geometry
here that the first column of pixels should correspond to RA=180).This issue is propagates to other functions that rely on
pix2sky
, e.g. toenmap.posmap
, which will give an RA array spanning(-np.pi, -3*np.pi)
instead of(np.pi, -np.pi)
as one would like, sinceenmap.unwind
"starts counting" coordinates at the leftmost pixel.When does this happen?
This issue arises (or not) in interesting cases. Oddly, the dr6v3 maps on-disk have a
wcs
(likely some floating-point arithmetic stuff with theircdelt
etc.) such that this issue just barely doesn't happen:However, if I make a downgraded geometry (e.g. by a factor of 4), whose pixel centers exactly align with pixel centers in the input geometry, this problem occurs:
If Python could do fractions exactly, we know that these two results should be the same (as a user, I would like them to both be +180.0).
Why does this happen?
Here's what I mean by "if a pixel RA center is within double precision of
np.pi
":where I have exactly copied the implementation of
pix2sky
before the call torewind
. These "true" coordinates give:Note the second value is just a smidgen closer to 180 than the dr6v3 geometry value, but it's close enough to cause this issue:
where this little arithmetic is what happens in
utils.rewind
.How to fix?
I think there are a bunch of ways, but perhaps the most explicit is to add a
recentering
function (notwcsutils.fix_wcs
) which moves the map in steps of2pi
such thatpix2sky
andcorners
always give sensible outputs. This could be a new argument likecentered=True
so that someone could get the old behavior manually if they wanted.The text was updated successfully, but these errors were encountered: