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

spectral extraction: improved logic for initial position of "Manual" background trace #1738

Merged
merged 2 commits into from
Oct 19, 2022

Conversation

kecnry
Copy link
Member

@kecnry kecnry commented Oct 14, 2022

Description

This pull request improves the logic for the initial guess for the position of the "Manual" background trace. Previously it started at the same guess as the extraction trace (based on the brightest flux medianed over the dispersion direction). Now it uses the same location that would be adopted for a OneSided background, with the "direction" determined on whether the extraction trace is in the top or bottom half of the image, and the separation at 10% of the cross-dispersion "height".

Motivated by @ojustino's comment: #1682 (review)

Change log entry

  • Is a change log needed? If yes, is it added to CHANGES.rst? If you want to avoid merge conflicts,
    list the proposed change log here for review and add to CHANGES.rst before merge. If no, maintainer
    should add a no-changelog-entry-needed label.

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a milestone set?
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@kecnry kecnry force-pushed the bg_trace_pixel_guess branch from 2bb8b80 to 18adcee Compare October 14, 2022 13:38
@kecnry kecnry added this to the 3.1 milestone Oct 14, 2022
@kecnry kecnry marked this pull request as ready for review October 14, 2022 13:57
@kecnry kecnry force-pushed the bg_trace_pixel_guess branch from 18adcee to d0bc2e4 Compare October 14, 2022 15:01
@codecov
Copy link

codecov bot commented Oct 14, 2022

Codecov Report

Base: 87.27% // Head: 87.65% // Increases project coverage by +0.37% 🎉

Coverage data is based on head (76b4e4b) compared to base (22559cf).
Patch coverage: 66.66% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1738      +/-   ##
==========================================
+ Coverage   87.27%   87.65%   +0.37%     
==========================================
  Files          95       95              
  Lines       10082    10131      +49     
==========================================
+ Hits         8799     8880      +81     
+ Misses       1283     1251      -32     
Impacted Files Coverage Δ
...plugins/spectral_extraction/spectral_extraction.py 90.62% <66.66%> (+0.04%) ⬆️
jdaviz/configs/imviz/plugins/catalogs/catalogs.py 91.22% <0.00%> (-4.43%) ⬇️
jdaviz/app.py 93.76% <0.00%> (-0.27%) ⬇️
...z/configs/default/plugins/data_tools/data_tools.py 64.51% <0.00%> (+3.91%) ⬆️
jdaviz/configs/imviz/plugins/viewers.py 87.42% <0.00%> (+4.57%) ⬆️
jdaviz/configs/imviz/wcs_utils.py 88.34% <0.00%> (+20.38%) ⬆️
jdaviz/configs/imviz/plugins/compass/compass.py 93.33% <0.00%> (+23.56%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@ojustino ojustino left a comment

Choose a reason for hiding this comment

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

It looks like sign is different for the "Manual" and "OneSided" cases when brightest_pixel is in the top half of the image, but the same for both cases when brightest_pixel is in the bottom half. Since the example Specviz2D notebook's brightest pixel is in its image's top half, the initial guesses for the "OneSided" and "Manual" options end up on opposite sides of the brightest pixel.

I think the two guesses for "Manual" and "OneSided" should either always be in the same spot (like now, when brightest_pixel < width / 2) or always be opposite from another (like now, when brightest_pixel >= width / 2).

@kecnry
Copy link
Member Author

kecnry commented Oct 14, 2022

Good point, I didn't explain the logic very well. The sign for the "OneSided" case is only applied if the separation would push the "TwoSided" case off the edge of the image, since the bg_separation traitlet is shared between "OneSided" and "TwoSided". In other words, the same logic that is used when "OneSided" becomes the default is used for the "Manual" position now, but bg_separation might still default to positive.

We could separate the bg_separation between the One and Two-Sided cases, but I personally don't think that is worth the overhead. The other option would be to have the "Manual" always match the position of the "OneSided" cases, if you think that would be more intuitive? (So always above the brightest pixel unless that would force it to go above the image, in which case it would be placed below instead).

@ojustino
Copy link
Contributor

I agree that a simpler approach is better here and think having the "Manual" position match the "OneSided" position makes sense.

@kecnry kecnry force-pushed the bg_trace_pixel_guess branch from c9b74da to 76b4e4b Compare October 14, 2022 19:04
Comment on lines +323 to +325
if default_bg_width * 2 >= distance_from_edge:
sign = 1 if (brightest_pixel < width / 2) else -1
default_bg_separation = sign * default_bg_width * 2
Copy link
Member Author

Choose a reason for hiding this comment

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

these lines will be covered by #1739 (coverage was lost when skipping the remote test in #1736)

Copy link
Contributor

@ojustino ojustino left a comment

Choose a reason for hiding this comment

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

The new commit sufficiently addresses my previous comment, and understood about the failing test. Should a merge here wait until the test has been rewritten? I imagine this branch would pass, but the change is also not an extremely urgent one.

@kecnry
Copy link
Member Author

kecnry commented Oct 14, 2022

I think since we know this case works, it's ok to get in with the slightly lower coverage? This is the exact same case that was covered before, so these lines will be covered once that test is rewritten. But I'm also ok letting this PR sit as long as that test doesn't fall off the radar too long - I agree this PR isn't urgent and don't expect merge conflicts.

Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Code looks like code and we have a follow-up issue, so merging. Thanks!

@pllim pllim merged commit 0b5a6be into spacetelescope:main Oct 19, 2022
@kecnry kecnry deleted the bg_trace_pixel_guess branch October 19, 2022 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants