-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fixing WCS bug #116
Fixing WCS bug #116
Conversation
Codecov Report
@@ Coverage Diff @@
## main #116 +/- ##
==========================================
+ Coverage 75.13% 76.81% +1.68%
==========================================
Files 77 78 +1
Lines 6804 6953 +149
==========================================
+ Hits 5112 5341 +229
+ Misses 1692 1612 -80
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Looks like I need to add more unit tests, that will be my goal on Monday. |
I've been thinking about the world to tangent plane reference coordinate. Right now I make that a class variable for the WCS class, effectively making it a global variable. This is nice since it forces everything to be on the same tangent plane. But it is bad since anyone tinkering around can get surprised by the behavior which changes depending on which image is created first. So perhaps a better option would be to let each object have it's own reference coordinates, however if someone tries to construct an That seems more pythonic to me, so perhaps I'll refactor to make that happen. It's actually not a very big change so it shouldn't change much else. |
Ok, so now every image can have it's own reference RA, DEC. Looking closer at the fits standard it seems they keep track of the reference RA, DEC and also the point in the image that the reference corresponds to. I think I was doing this indirectly and only allowing the image center or bottom corner to be the reference point. I'll make that more general soon so there is no ambiguity. |
Converted to draft since it's clear it still needs refining and more tests. |
Ok, I have added enough generality for users to very clearly specify where images go in relation to each other. However, the |
Good luck! I've been following along and checking things out along the way. |
Thanks for checking things out along the way :) I've been trying to reconcile the |
Sounds good. I'm working on putting together a little test for something that's currently failing. (The failing is easy; making it the minimally reproducible test case is harder.) |
If the failing is something in how AstroPhot works, fell free to detail it here or on the issue and I can try to build the solution into this PR. |
Right, didn't mean to be mysterious, I just can't write a simple test case yet. The issue is that the default window doesn't always actually match the pixel values of the image. The function that generates the default window is not a separate function, but is rather wrapped into the image_header.init so I'm working on creating a minimal header that captures this. |
Ah, I see. Yes I think this is the issue I'm hoping to clear up with the next couple commits |
Here's an example of a test I added to
So, I don't exactly expect this test to pass in anything you fix. But rather I anticipate your fixes will result in a pixelscale, origin, and end that correctly recover nx, ny. |
Here's the WCS string for the relevant image. Sorry I can't format it better, but the FITS standard defines exact character chunks and I don't get things right when I try to manually line break to make the code readable.
|
More or less, yes I am working in that direction. The scope of this PR kind of expanded from what I originally intended. I could see this becoming it's own separate module like you mention (maybe one day a package, but probably not). There is a major difference from Astropy WCS though in that between the world coordinates and pixel coordinates I have the tangent plane. My goal is for multi-image analysis that the tangent plane is where everything can be matched up between images. I'm not sure this is a feature in Astropy WCS since it goes directly between world and pixel coordinates |
Actually my latest plan with the |
I think AstroPy WCS does provide the same intermediate representation through After you finish this PR, you'll probably be well-primed to read this series of WCS papers by Greisen and Calabretta talking about defining convenient intermediate representations between the sky and a detector:
And then when you've mastered that, you can go on to thinking about WCS as a way to encode spectral information :) |
Ah, looking at those references, especially: https://ui.adsabs.harvard.edu/abs/2002A%26A...395.1077C |
Ok saving progress for now. This is a major refactor. I've collected the WCS stuff into a standalone WCS class. The interface with WCS is now almost entirely through window objects. I haven't worked out all the bugs yet. But I am going to a wedding this week so I might not get much more done. I've set aside all of next week to finish this and implement the parameter DAG. It's getting close! Still some indexing bugs to iron out though. Looking back, there wasn't actually a "bug" per-se in AstroPhot before, I was just conflating world coordinates and tangent plane coordinates. But now I've come this far I really like the new system (at least once its working). It should be really easy to just give it a WCS object and go from there. |
Had some time to work on it. It now seems to be running correctly, though I've cut out a bunch of (I think) superfluous functionality. Going to add new tests that check what I actually want the WCS stuff to do. At this point I think I've added all the needed WCS functionality to fairly seamlessly work with celestial coordinates and astropy WCS objects. Also, the WCS stuff has all been abstracted away into its own class so (hopefully) it wont be too painful later to add distortion parameters. |
Yeah, I started a little thinking about where SIP might fit in to the new WCS class. Sip is pixel<->focal plane<->projection plane<->sky(ra, dec) I don't know if this should be another option under the PPCS class or an added class. |
Ok, I think this is ready to go! Sorry the scope of this PR grew well beyond the initial problem and is now at over 2,000 affected lines... I'm pretty happy with the results though! To your comment about adding SIP, I think the way to do it with the minimum change would be to make it an option for the PPCS. However, since everything is abstracted under the |
Found an indexing bug, but didn't have time to fix it today. Changed back to draft |
I've started an issues for the WCS SIP #118 and started an |
I think this PR has enough in it already, but perhaps a future update for the built-in plotting methods could map to world coordinates then use a WCS object to plot images with RA/DEC projection and also include NE arrows :) |
Ok, unit tests run and also running the tutorial notebooks seems to work too. Now I think it's finally ready! |
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.
Good work.
Consider adding some tests to make Code Coverage happy. They don't have to be deep. Just things that actually exercise the functions are worthwhile. If it works in your workflow, you might start an issue to capture adding some more tests to get the current significant improvements/fixes merged into main.
I have a bunch of small copy-edits and a few small questions, but nothing to hold up merging.
Ok, I'll try to make all the adjustments and then merge the updates :) Thanks for going through everything! |
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.
LGTM
@wmwv identified an issue in #115 which ultimately was tracked to the way AstroPhot converts world coordinates (RA,DEC) into the tangent plane where AstroPhot does it's calculations. It turns out that to a large degree the original coordinate system was implicitly defined and the conversion between world coordinates and tangent plane coordinates only really worked on the equator.
The new system makes explicit the position where the tangent plane and the celestial sphere (world coordinates) meet. The update also provides clear functions to map world to/from tangent plane and also tangent plane to/from world. A new
WCS
base class added forWindow
andImage_Header
gives them the ability to call function that map world coordinates. The new class maintains a global reference (RA_0, DEC_0) so that multi-band multi-epoch images can be mapped to the same tangent plane easily.This also comes with some nomenclature changes. The old
world_to_pixel
function(s) was pulling double duty and just causing problems so now it'sworld_to_plane
andplane_to_pixel
. Docstrings have been updated, though I may have missed some.A docs page is added to go into more detail. This can be found at
docs/coordinates.rst
and when merged it will be a new page in the docs website. It may be beneficial to create a notebook tutorial on coordinate systems for users that care deeply about exact coordinates.I have also updated the tutorial notebooks correspondingly at: https://github.com/Autostronomy/AstroPhot-tutorials/tree/wcsbug
This PR closes #115 and would constitute a version update breaking backwards compatibility. This will be version 0.12.0 unless I get the parameter DAG update done before we are happy with this WCS update.