Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

spectral-extraction: improved initial parameter estimation #1560

Merged
merged 4 commits into from
Aug 16, 2022

Conversation

kecnry
Copy link
Member

@kecnry kecnry commented Aug 11, 2022

Description

This pull request improves the automatic initial input parameter determination for input to spectral extraction, particularly for cases where the previous defaults would result in a window outside the range of the image which would throw an error from specreduce. This also prevents other cases like this from throwing a traceback by instead raising an error snackbar message on load and pointing to the plugin for manual extraction.

Re failing coverage checks: I did add test coverage for the near-edge example to ensure it forces a one-sided background, but since the parser only accepts files, its difficult to add coverage for the "brightest pixel on edge" logic and the complete try/except snackbar.

TODO:

  • iterate on expected behavior
  • add test coverage

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 change log needed? If yes, is it added to CHANGES.rst?
  • Is a milestone set?
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@kecnry kecnry added plugin Label for plugins common to multiple configurations specviz2d labels Aug 11, 2022
@kecnry kecnry added this to the 2.9 milestone Aug 11, 2022
@kecnry kecnry force-pushed the spec-extract-tweaks branch from 3664e4e to bc3eb9a Compare August 11, 2022 15:17
@codecov
Copy link

codecov bot commented Aug 11, 2022

Codecov Report

Merging #1560 (ff60cd5) into main (6060929) will decrease coverage by 0.02%.
The diff coverage is 78.94%.

@@            Coverage Diff             @@
##             main    #1560      +/-   ##
==========================================
- Coverage   85.64%   85.61%   -0.03%     
==========================================
  Files          94       94              
  Lines        9216     9228      +12     
==========================================
+ Hits         7893     7901       +8     
- Misses       1323     1327       +4     
Impacted Files Coverage Δ
jdaviz/configs/specviz2d/helper.py 80.00% <60.00%> (-1.93%) ⬇️
...plugins/spectral_extraction/spectral_extraction.py 88.60% <85.71%> (-0.33%) ⬇️

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

@kecnry kecnry force-pushed the spec-extract-tweaks branch 2 times, most recently from c25e98d to 7b0d6f9 Compare August 11, 2022 18:50
@kecnry kecnry marked this pull request as ready for review August 11, 2022 19:09
@kecnry kecnry requested a review from camipacifici August 11, 2022 19:09
Copy link
Contributor

@camipacifici camipacifici 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!

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.

Is there a follow-up issue to make Specviz2D parser more flexible and then add the edge case you couldn't add before in this PR?

jdaviz/configs/specviz2d/helper.py Outdated Show resolved Hide resolved
jdaviz/configs/specviz2d/helper.py Outdated Show resolved Hide resolved
jdaviz/configs/specviz2d/helper.py Outdated Show resolved Hide resolved
@@ -237,7 +252,7 @@ def marks(self):

viewer2d = self.app.get_viewer('spectrum-2d-viewer')
viewer1d = self.app.get_viewer('spectrum-viewer')
if not viewer2d.state.reference_data or not viewer1d.state.reference_data:
if not viewer2d.state.reference_data:
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the removal of the second condition do?

Copy link
Member Author

Choose a reason for hiding this comment

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

previously this avoided tracebacks before the original 1d spectrum was extracted. Now this will force that error to occur, which is now caught by the try/except and exposed in the snackbar.


pext = specviz2d_helper.app.get_tray_item_from_name('spectral-extraction')
assert pext.bg_type_selected == 'OneSided'
assert pext.bg_separation < 0
Copy link
Contributor

Choose a reason for hiding this comment

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

What is < 0 testing? You sure you don't want to be more explicit with numpy.testing.assert_allclose()?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's really just testing that the logic detected that the extraction window was so close to the top of the image, that the background region needed to be below the extraction region. I was intentionally non-specific in the test, because we'll very likely improve the separation/width default logic in the future which would change the exact value, but as long as the window-detection logic doesn't change significantly to avoid the edge entirely, that should still always return a negative separation.

@kecnry
Copy link
Member Author

kecnry commented Aug 16, 2022

Is there a follow-up issue to make Specviz2D parser more flexible

Yes there is, I'll add a note in there to also extend the test cases 🐱

@kecnry kecnry force-pushed the spec-extract-tweaks branch 2 times, most recently from a26a8d6 to 1aabcf2 Compare August 16, 2022 13:48
kecnry and others added 4 commits August 16, 2022 11:37
* spectral extraction plugin has not been in a release
* to handle cases where extraction or background regions otherwise would default to outside of the image
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
@kecnry kecnry force-pushed the spec-extract-tweaks branch from 1aabcf2 to ff60cd5 Compare August 16, 2022 15:37
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.

LGTM. Thanks!

@pllim pllim merged commit 3a76598 into spacetelescope:main Aug 16, 2022
@kecnry kecnry deleted the spec-extract-tweaks branch August 16, 2022 16:13
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
plugin Label for plugins common to multiple configurations Ready for final review specviz specviz2d
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants