-
Notifications
You must be signed in to change notification settings - Fork 76
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
prohibit subsets that do not overlap data range within plugins #1935
prohibit subsets that do not overlap data range within plugins #1935
Conversation
daac88c
to
da79f65
Compare
Codecov ReportBase: 91.78% // Head: 91.81% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1935 +/- ##
==========================================
+ Coverage 91.78% 91.81% +0.03%
==========================================
Files 140 140
Lines 14989 15045 +56
==========================================
+ Hits 13758 13814 +56
Misses 1231 1231
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. |
Unsure whether this should be milestoned as 3.1.2 or 3.2 (especially given the other case covered by #1868), and whether it should be in the changelog as a "feature" or bugfix - opinions/thoughts welcomed! |
Given we already plan 3.2 for AAS, milestone to 3.2 is probably ok at this point. |
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.
What about partial overlap? What should happen then? Is that tested?
Also on the topic of partial overlap, if it is supported, also see what happens if the overlap is only one element in wavelength space.
@@ -664,6 +664,9 @@ def calculate_fit(self, add_data=True): | |||
fitted spectrum/cube | |||
residuals (if ``residuals_calculate`` is set to ``True``) | |||
""" | |||
if not self.spectral_subset_valid: | |||
raise ValueError("spectral subset is outside data range") |
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 be easier for future debugging if you also report both ranges so people can see why they are not overlapping.
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 only ever happens if ignoring the UI warnings and calling from the API directly... although that also means the user likely isn't staring at the viewer where it's visually obvious. I'm not convinced ranges will help though and am guessing the more likely action would be to change one selection or the other... so do you think it would help to be "spectral subset '{self.spectral_subset.selected}' is outside data range of '{self.dataset.selected}'"
?
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.
If I am debugging this when user says it should not have errored, I would find it helpful to have the numbers already in the traceback to see why it crashes in the first place and whether that is expected.
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.
ok, I added both. Let me know what you think!
spec = self.dataset.selected_obj | ||
spec_min, spec_max = np.nanmin(spec.spectral_axis), np.nanmax(spec.spectral_axis) | ||
subset_min, subset_max = self.spectral_subset.selected_min_max(spec) | ||
self.spectral_subset_valid = bool(subset_min < spec_max and subset_max > spec_min) |
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.
Why is the range check not inclusive?
self.spectral_subset_valid = bool(subset_min < spec_max and subset_max > spec_min) | |
self.spectral_subset_valid = bool(subset_min =< spec_max and subset_max >= spec_min) |
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.
We need to ensure the subset will contain data. From testing it seemed that isn't the case for exact edge values, but that could just be due to rounding error or might be related to #1892. Can you point to where in the code the subset logic is guaranteed to be inclusive? I don't mind changing this if it should act inclusively, but also want to avoid a rabbit hole here and might just need to revisit this during/after the possible upcoming subset refactoring work.
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 don't know on top of my head if it should be inclusive or not. I just want to make sure this was considered. Thanks for the clarification!
Partial overlap is the same as a single data set with a small subset on the edge (it does work, 1 element might give you unexpected results when fitting 🤷 , but it won't crash - unless model fitting ever complains about less data points than degrees of freedom, but that is a different case entirely). |
bfdfebd
to
715b52e
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.
Codewise LGTM and the tests seem to demonstrate that the bug is fixed. Thanks!
727a550
to
35c2514
Compare
* implemented for model fitting and line analysis
35c2514
to
f26ac6f
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.
Looks good!
Only comment is a minor one. We've mentioned before that we could avoid hard-coding the default text for selected subsets in the future, and I contend that the future is now. I've provided a few suggestions that you can accept/reject below.
|
||
@observe("dataset_selected", "spectral_subset_selected") | ||
def _check_dataset_spectral_subset_valid(self, event={}, return_ranges=False): | ||
if self.spectral_subset_selected == "Entire Spectrum": |
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.
if self.spectral_subset_selected == "Entire Spectrum": | |
if self.spectral_subset_selected == self.spectral_subset.default_text: |
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.
after offline discussion, we'll reconsider this app-wide as a follow-up effort and then try to be consistent after.
plugin = specviz_helper.plugins['Line Analysis'] | ||
plugin.dataset = 'right_spectrum' | ||
assert plugin.dataset == 'right_spectrum' | ||
assert plugin.spectral_subset == 'Entire Spectrum' |
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.
assert plugin.spectral_subset == 'Entire Spectrum' | |
assert plugin.spectral_subset == plugin.spectral_subset.default_text |
|
||
plugin.dataset = 'right_spectrum' | ||
assert plugin.dataset == 'right_spectrum' | ||
assert plugin.spectral_subset == 'Entire Spectrum' |
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.
assert plugin.spectral_subset == 'Entire Spectrum' | |
assert plugin.spectral_subset == plugin.spectral_subset.default_text |
Description
This pull request prohibits the user selecting a spectral subset that does not overlap at all with the selected dataset. This is done through a new plugin mixin which is then used in both model fitting and line analysis, showing red text in the plugin UIs, disabling the "fit" button in model fitting, and raising a traceback if calling the
fit
orget_results
API methods, respectively.IMPORTANT NOTE: adding the subset to the right (reference) data will result in a traceback because of #1868. Once that bug is fixed, this logic should then handle that case as well. Notes are added in the test cases if we want to update the test for either line analysis or model fitting to handle the opposite scenario as a regression test for #1868.
Screen.Recording.2022-12-19.at.3.11.07.PM.mov
Fixes #1911
Change log entry
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, maintainershould 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.
trivial
label.