-
-
Notifications
You must be signed in to change notification settings - Fork 54
Fix Errors in computation in ResampledLowLevelWCS #857
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
base: main
Are you sure you want to change the base?
Changes from all commits
9d2badc
44c6d03
34c7fdd
8530b22
7907b92
c22d90e
d52c391
b6cc563
c63534b
9b986de
8f910be
7740fd3
d7f8bbc
005f6f8
49c60ee
47e438f
9101001
0207155
fc0ff33
fb8141a
fe63449
62e5b2e
f91c5e8
8de296d
343a12e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix translations in `~ndcube.wcs.wrappers.resampled_wcs.ResampledLowLevelWCS` between original and resampled pixel grids. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
import numpy as np | ||
|
||
from astropy.wcs.wcsapi.wrappers.base import BaseWCSWrapper | ||
|
@@ -20,9 +21,59 @@ class ResampledLowLevelWCS(BaseWCSWrapper): | |
axis. If a scalar, the same factor is used for all axes. | ||
|
||
offset: `int` or `float` or iterable of the same | ||
The location on the underlying pixel grid which corresponds | ||
to zero on the top level pixel grid. If a scalar, the grid will be | ||
shifted by the same amount in all dimensions. | ||
Comment on lines
-23
to
-25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might actually be the source of the "bug". We previously defined There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a bug fix in that we can define it like that as much as we want but that's not how we were using it in rebin 😆 |
||
The shift of the lower edge of the 0th pixel (i.e. the pixel | ||
coordinate -0.5) of the resampled grid relative to the lower | ||
edge of the 0th pixel in the original underlying pixel grid, | ||
in units of original pixel widths. (See the schematic in the | ||
Notes section for a graphical example.) If a scalar, the grid | ||
will be shifted by the same amount in all dimensions. | ||
|
||
Notes | ||
----- | ||
Below is a schematic of how ResampledLowLevelWCS works. The asterisks show the | ||
corners of pixels in a grid before resampling, while the dashes and | ||
pipes show the edges of the resampled pixels. The resampling along the | ||
x-axis has been performed using a factor of 2 and offset of 1, respectively, | ||
while the resampling of the y-axis uses a factor of 3 and offset of 2. | ||
The right column and upper row of numbers along the side and bottom of the | ||
grids denote the edges and centres of the original pixel grid in the original | ||
pixel coordinates. The left column and lower row gives the same locations in | ||
the pixel coordinates of the resampled grid. Note that the resampled pixels | ||
have an (x, y) shape of (2, 3) relative to the original pixel grid. | ||
Also note, the left/lower edge of the 0th pixel in the resampled grid (i.e. pixel | ||
coord -0.5) is shifted relative to the left/lower edge of the original 0th pixel, | ||
and that shift is given by the offset (+1 in the x-axis and +2 along the y-axis), | ||
which is in units of original pixel widths. | ||
|
||
:: | ||
|
||
resampled original | ||
factor=3 | ||
offset=2 | ||
|
||
0.5 4.5 *-----------*-----------*-----------*-----------* | ||
| | | ||
2/6 4 | | | ||
| | | ||
1/6 3.5 * * * * * | ||
| | | ||
0 3 | | | ||
| | | ||
-1/3 2.5 * * * * * | ||
| | | ||
-2/6 2 | | | ||
| | | ||
-0.5 1.5 *-----------*-----------*-----------*-----------* | ||
| | | ||
-4/6 1 | | | ||
| | | ||
-5/6 0.5 * * * * * | ||
| | | ||
-1 0 | | | ||
| | | ||
-1-1/6 -0.5 * * * * * | ||
-0.5 0 0.5 1 1.5 2 2.5 3 3.5 original pixel indices | ||
-1 -0.75 -0.5 -0.25 0 0.25 0.5 0.75 1 resampled pixel indices: factor=2, offset=1 | ||
""" | ||
|
||
def __init__(self, wcs, factor, offset=0): | ||
|
@@ -42,13 +93,13 @@ def _top_to_underlying_pixels(self, top_pixels): | |
# Convert user-facing pixel indices to the pixel grid of underlying WCS. | ||
factor = self._pad_dims(self._factor, top_pixels.ndim) | ||
offset = self._pad_dims(self._offset, top_pixels.ndim) | ||
return top_pixels * factor + offset | ||
return (top_pixels + 0.5) * factor - 0.5 + offset | ||
|
||
def _underlying_to_top_pixels(self, underlying_pixels): | ||
# Convert pixel indices of underlying pixel grid to user-facing grid. | ||
factor = self._pad_dims(self._factor, underlying_pixels.ndim) | ||
offset = self._pad_dims(self._offset, underlying_pixels.ndim) | ||
return (underlying_pixels - offset) / factor | ||
return (underlying_pixels + 0.5 - offset) / factor - 0.5 | ||
|
||
def _pad_dims(self, arr, ndim): | ||
# Pad array with trailing degenerate dimensions. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming this was manifesting as errors in accuracy in rebin, we should probably call that out too?