-
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
Model fitting residuals #1864
Model fitting residuals #1864
Conversation
c4061e2
to
a64d70c
Compare
Codecov ReportBase: 88.45% // Head: 88.48% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1864 +/- ##
==========================================
+ Coverage 88.45% 88.48% +0.02%
==========================================
Files 95 95
Lines 10533 10540 +7
==========================================
+ Hits 9317 9326 +9
+ Misses 1216 1214 -2
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. |
a64d70c
to
38c164a
Compare
|
||
def _register_spectrum(self, event): | ||
""" | ||
Add a spectrum to the data collection based on the currently displayed | ||
parameters (these could be user input or fit values). | ||
""" | ||
if self._warn_if_no_equation(): | ||
return | ||
# Make sure the initialized models are updated with any user-specified | ||
# parameters | ||
self._update_initialized_parameters() | ||
|
||
# Need to run the model fitter with run_fitter=False to get spectrum | ||
if "spectrum" in event: | ||
spectrum = event["spectrum"] | ||
else: | ||
model, spectrum = fit_model_to_spectrum(self._spectrum1d, | ||
self._initialized_models.values(), | ||
self.model_equation, | ||
window=self._window) | ||
|
||
self.add_results.add_results_from_plugin(spectrum) | ||
self._set_default_results_label() |
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.
It seems that during past refactors this kind of got left as an unnecessary artifact that only gets called once internally (and so never even entered the else statement in 797). This PR moves the remaining applicable logic to where it was called before.
2885325
to
f58c186
Compare
Works as expected in Specviz and Cubeviz, I'll give the code quick look-over in the morning before I approve. |
Looks lovely! But I hit a traceback if I have two spectra loaded, I highlight a subset, and then I select it in the model fitting plugin. ValueError Traceback (most recent call last) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/site-packages/ipywidgets/widgets/widget.py:620, in Widget.set_state(self, sync_data) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/contextlib.py:142, in _GeneratorContextManager.exit(self, typ, value, traceback) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/site-packages/traitlets/traitlets.py:1371, in HasTraits.hold_trait_notifications(self) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/site-packages/ipywidgets/widgets/widget.py:686, in Widget.notify_change(self, change) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/site-packages/traitlets/traitlets.py:1386, in HasTraits.notify_change(self, change) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/site-packages/traitlets/traitlets.py:1431, in HasTraits._notify_observers(self, event) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/site-packages/jdaviz/core/template_mixin.py:874, in SubsetSelect._selected_changed(self, event) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/site-packages/jdaviz/core/template_mixin.py:925, in SubsetSelect._update_has_subregions(self) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/functools.py:981, in cached_property.get(self, instance, owner) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/site-packages/jdaviz/core/template_mixin.py:936, in SubsetSelect.selected_obj(self) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/site-packages/jdaviz/app.py:815, in Application.get_subsets_from_viewer(self, viewer_reference, data_label, subset_type) File ~/opt/miniconda3/envs/pr1864/lib/python3.10/site-packages/jdaviz/app.py:742, in Application.get_subsets_from_viewer.._get_all_subregions(mask, spec_axis_data) ValueError: Mask has length 0, ApplyROI may have been used incorrectly |
@camipacifici - I wouldn't expect that bug was introduced here, but can you either provide more details to reproduce or test on main and confirm if it happens there as well or not? As for mosviz, that's a good catch, that'll definitely need to be fixed before merging this, so I'll mark this back as draft until I get a chance to fix assigning the mosviz row/plugin information. |
3e868e8
to
6f5eb59
Compare
6f5eb59
to
18ec056
Compare
I think mosviz is now working correctly (although note that because of the small size of the viewers and the data menu now being attached in #1712, some resizing might be necessary in order to access the additional entries). One slightly annoying behavior is that the residuals entry is not added to the viewer by default (as consistent with other viztools in this PR), but will be loaded by default on a row change. Should residuals be plotted by default for all viztools instead? |
Looks great (disco mode included!) |
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.
LGTM, thanks.
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! I did notice the mosviz behavior with row switching but if you're ok with that being follow-up work thats fine.
I'd be happy to make the changes here if we knew the behavior we want... but I suspect we might need to use it a little while first to get a feel for the expected behavior (in which case deferring probably makes sense). I'll leave this open for a little while in case anyone has thoughts on that and will merge if I don't here anything by Monday will merge as-is and we can revise down the road if necessary. |
Description
This pull request implements the option to expose the residuals from a model fit as an additional entry in the data collection.
Open questions:
Screen.Recording.2022-11-22.at.2.09.27.PM.mov
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.