Skip to content
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

Tweak edges using a gradient method #1796

Merged
merged 36 commits into from
Jul 17, 2024
Merged

Conversation

rcooke-ast
Copy link
Collaborator

This PR adds additional functionality to the tweak-edges algorithm. The current implementation is prone to error when there's vignetting (see below image for an example).

The top panel is the slit profile (black), and some vertical lines that show the initial, tweaked (threshold - already implemented in PypeIt), and tweaked (gradient - new method in this PR) determinations of the slit edges. The tweaked (gradient) is a new method that I’ve implementing that is based on the strongest gradients of the slit profile (see bottom panel)… the smoothed profile is in purple, which is what the tweaked locations is based on. The key problem with the old approach is vignetting.

image

I will soon be submitting another PR that refactors the spatial flexure to be (optionally) slit-dependent. This is the start of that effort, and I won't develop further on this until PR #1755 clears.

@codecov-commenter
Copy link

codecov-commenter commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 27.33333% with 109 lines in your changes missing coverage. Please review.

Project coverage is 38.19%. Comparing base (14d810f) to head (510d2b1).

Files Patch % Lines
pypeit/core/flat.py 9.09% 40 Missing ⚠️
pypeit/flatfield.py 29.62% 19 Missing ⚠️
pypeit/coadd3d.py 0.00% 10 Missing ⚠️
pypeit/core/procimg.py 0.00% 9 Missing ⚠️
pypeit/core/datacube.py 0.00% 8 Missing ⚠️
pypeit/spectrographs/gtc_osiris.py 0.00% 6 Missing ⚠️
pypeit/images/rawimage.py 0.00% 4 Missing ⚠️
pypeit/spectrographs/gemini_gnirs.py 0.00% 4 Missing ⚠️
pypeit/find_objects.py 0.00% 3 Missing ⚠️
pypeit/alignframe.py 0.00% 2 Missing ⚠️
... and 3 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           kcwi_cube_updates    #1796      +/-   ##
=====================================================
- Coverage              38.22%   38.19%   -0.03%     
=====================================================
  Files                    208      208              
  Lines                  48256    48311      +55     
=====================================================
+ Hits                   18444    18451       +7     
- Misses                 29812    29860      +48     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@kbwestfall kbwestfall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, so I'm approving now. As far as I can tell, you mostly remove the initial=True flags for the code relevant to the SlicerIFU only. Is that true? There was at least one case where I wanted to make sure that we understand changes to the default behavior.

pypeit/core/flat.py Outdated Show resolved Hide resolved
pypeit/core/flat.py Show resolved Hide resolved
pypeit/core/flat.py Outdated Show resolved Hide resolved
pypeit/find_objects.py Outdated Show resolved Hide resolved
pypeit/flatfield.py Show resolved Hide resolved
pypeit/slittrace.py Show resolved Hide resolved
pypeit/utils.py Show resolved Hide resolved
Copy link
Collaborator Author

@rcooke-ast rcooke-ast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, @kbwestfall - all addressed!

pypeit/core/flat.py Outdated Show resolved Hide resolved
pypeit/find_objects.py Outdated Show resolved Hide resolved
pypeit/slittrace.py Show resolved Hide resolved
pypeit/core/flat.py Show resolved Hide resolved
pypeit/core/flat.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@debora-pe debora-pe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good for me in general. I'm approving.
But I have a question. The fact that you removed initial=True to all the code relevant to the SlicerIFU, does it mean that the parameter tweak_slits cannot be False for SlicerIFU? If it's correct, is that clear to the users?
Similarly, spatial_fit_finecorr() also have initial=False. Does it mean that it is always run only when tweak_slits=True? Is that clear to the users?

@rcooke-ast
Copy link
Collaborator Author

Thanks for the feedback, @debora-pe!

The fact that you removed initial=True to all the code relevant to the SlicerIFU, does it mean that the parameter tweak_slits cannot be False for SlicerIFU?

Just to confirm, tweak_slits can be False for SlicerIFU. These latest changes basically just make the code identical for MultiSlit and SlicerIFU when it comes to using either the initial or tweaked edges. The main difference is that MultiSlit and SlicerIFU can now use an alternative method to define the tweaked edges. Because the way slits.select_edges() works, the default will be that the tweaked edges are used, and if those are not available (or if the initial edges are specifically requested) then the initial edges are used.

Similarly, spatial_fit_finecorr() also have initial=False. Does it mean that it is always run only when tweak_slits=True?

Like the above response, the spatial_fit_finecorr() function uses onslit_tweak, but this variable is defined by using the tweaked edges by default, and if those are not available, then the initial ones are used.

So, the full functionality is still available to all users - thanks for checking 👍

@debora-pe
Copy link
Collaborator

Thank you @rcooke-ast for the explanation!

@rcooke-ast rcooke-ast merged commit 3117c08 into kcwi_cube_updates Jul 17, 2024
23 checks passed
@rcooke-ast rcooke-ast deleted the cube_tweakedge branch July 17, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants