-
Notifications
You must be signed in to change notification settings - Fork 10
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
Fix off-by-one Error and related WCS changes #276
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Before, this was just a multiplication by the zoom factor, which can produce wrong results even in simple cases. The solution in place now will probably only work for LINEAR WCSs.
…ntral pixel, which gets all the flux. However, this was a wrong assumption based on an effect of the off-by-one error. Given an even number of pixels along both axes of the canvas, a source perfectly in the center should be spread out over the 4 central pixels, which now works. With this change, the test still tests the exact same thing, just in a more general and correct way.
Change API of calc_footprint to return corner in the same format as astropy.wcs.WCS.calc_footprint, which is now used internally.
The affected parts could be improved, but for now just get it to work.
This should fix #209 |
Revert changes to extract_area_from_table and change mock data instead
hugobuddel
requested changes
Sep 26, 2023
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.
kernel_pixel_scale = hdr["CDELT1"] * unit_factor
now fails, because CDELT1
is not there, but CDELT1D
is. I think you made some helper function for this; I'll have a look
Sorry for not being very constructive, I'll get something better.
hugobuddel
reviewed
Sep 26, 2023
Co-authored-by: Hugo Buddelmeijer <hugo@buddelmeijer.nl>
hugobuddel
approved these changes
Sep 27, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Two important bugs were fixed
[1, 1]
, unlike the 0-indexed nature of Python[0, 0]
. Previously, there were several occurrences of this not being taken into consideration, which is fixed by this PR. Pixel coordinates which are written to afits.Header
must always follow the 1-based convention. This also ensures headers are correctly interpreted by other software.Other changes for everything to work as expected
float
toint
in a different way. I.e.,int()
,np.ceil()
andround()
are all used, but great care must be taken in deciding which is the correct function for which case.TAN
projection. Previously, sky coordinate information in headers was almost always given asTAN
, but the implementation of the conversion functions just ignored that and converted everything linearly. Changing this behavior however breaks a number of things, because the linear outcome is expected. A more permanent (and geometrically accurate) solution is needed here, but for the time being, two changes were introduced as a stop-gap solution:LINEAR
wcs axes, even if they are dealing with sky coordinates.wcs_suffix
X
is introduced, which uses sky coordinates, but withLINEAR
projection. This is currently only used for mock objects in testing.As a consequence of these changes, many test cases and mock objects had to be adapted, as they were based on erroneous assumptions and sometimes "bent" to pass with an actually wrong result.
Additional changes
optics.image_plane_utils.calc_footprint()
was changed to match that ofastropy.wcs.WCS.calc_footprint()
, i.e. a single array of shape(4, 2)
containing the corner points in clockwise order starting from the bottom left. A new functionoptics.image_plane_utils.calc_table_footprint()
is introduced to do the same forastropy.table.Table
objects.astropy.wcs.WCS
is now used internally, instead of custom implementations. In terms of performance, it seems that once theWCS
instance is created, the actual operations are faster then the self-implemented ones. The only drawback is the performance hit that results from creating theWCS
objects in the first place. This can be mitigated somewhat by keeping them around as much as possible, instead of creating them from scratch every time, in cases where this is possible. Sometimes, it may be sufficient to pass theWCS
instead of a whole header.optics.image_plane_utils
.What is still to do
deg
andarcsec
are now used internally, which actually caused the most headache in this PR. The checks and conversions need to be more robust!calc_footprint()
necessitated a number of adaptions in the code. Those were done very crudely and could be improved, in particular many tests use this as an optional feature for plotting result footprints, all of this could be factored out.astropy.wcs.WCS.calc_footprint()
has an optional argumentcenter
, which controls if the footprint is considered to go until the center of the corner pixels (where the coordinates are defined) or to the very edge, adding one fullCDELT
to the whole image. We need to decide which version to use in which cases.WCS
instances should be passed along as much as possible for performance.Canvas
class.astropy.wcs.WCS
.optics.fov_utils.is_field_in_fov
(and that whole module) could use some refactoring.optics.image_plane_utils._fix_360
was introduced to deal with "overflowing" values of deg, i.e. e.g. 359.995 instead of -0.005. This needs some more attention, unit tests, and also think about how to deal with deg vs. arcsec in this context.