-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Introducing spectral extractions for non-flat traces #148
Conversation
Codecov Report
@@ Coverage Diff @@
## main #148 +/- ##
==========================================
- Coverage 75.46% 72.98% -2.48%
==========================================
Files 9 9
Lines 693 659 -34
==========================================
- Hits 523 481 -42
- Misses 170 178 +8
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
# Choose the initial guess for the mean of | ||
# the Gaussian profile: | ||
mean_init_guess = np.broadcast_to( | ||
img.shape[crossdisp_axis] // 2, img.shape[disp_axis] | ||
) |
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.
would just swapping this out with the "remainder" from casting trace_object.trace
to their integer rolls be enough to correct the means to the actual trace position?
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 think it would improve the initial guess for the mean parameter given to the Gaussian spatial profile fit by <1 pixel.
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.
This is a creative approach that seems to work upon initial investigation. I would like to test the extractions more thoroughly, but I have some comments on the code in the meantime.
I think this is ready for a final code-review once test coverage is added. |
078b48d
to
12316d2
Compare
The remaining failure comes from astropy convolution, see astropy/astropy#14025 |
It looks like the big difference since my last check is the test, which seems reasonable. I put more thought into the resampling procedure and am wondering if it's problematic in cases where it's not actually needed because the trace is truly flat. The following is the same as cell 4 of your gist's notebook except it skips the transformation step:
Is the difference in the results a cause for concern? |
Hi @ojustino, thanks for your investigation and this comment. The "untransformed" image should indeed produce a distinct spectral extraction from the one I made in the example notebook which does transform |
fc525be
to
5efd84f
Compare
I've reverted the very last commit. The reverted commit pinned the setuptools version, due to an upstream astropy failure related to the convolution module. The astropy fix was merged in astropy/astropy#14035, so we no longer need the pin here. |
5efd84f
to
b4c5db9
Compare
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.
@bmorris3, that makes sense, thanks. Looks like I was fixating on the example instead of the actual code. The code looks good to me and the test makes sense, so I approve from that perspective. I would be interested in seeing feedback from others with more experience in extraction using non-flat traces, but I have no objections based on the ones I've tried.
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 agree - let's get this in and make any small tweaks once there is some user feedback!
Thanks both for the reviews. 🎉 |
Description
This PR implements Horne spectral extraction with non-flat traces. For a demo, see this example notebook.
specreduce Horne extractions currently support flat traces. In the flat trace case, the sum of the spectrum in the dispersion dimension produces a flux profile in the spatial dimension, which we fit with a (1D) Gaussian. The model profile is used to construct a kernel, which applies weights to each pixel in the extracted 1D spectrum.
For a non-flat trace, the profile in the will be "smeared" when summed in the dispersion dimension, which is not accurately approximated by a Gaussian. Less flat traces will produce poorer kernels, and less accurate spectral extractions.
The trick used here to support non-flat traces is to roll the pixels along the spatial dimension until the trace is flat, and then perform the extraction on the shifted image as usual. There are no actual changes to the Horne implementation, just a manipulation of the image in the case of a non-flat trace to "make it flat".
The trick within the trick is that we can use fancy indexing to flatten the trace without interpolation or resampling, and do it efficiently. In this PR, we only re-index the underlying image.
My strategy here is to (1) never make up data (no interp/sampling business), and (2) keep the diff small.
Possible Improvements
Closes #102
🐱