-
Notifications
You must be signed in to change notification settings - Fork 206
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
Update residual line when model line is changed. #3355
base: RELEASE_next_patch
Are you sure you want to change the base?
Update residual line when model line is changed. #3355
Conversation
Update residual line when model line is changed. hyperspy#3352
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## RELEASE_next_patch #3355 +/- ##
======================================================
+ Coverage 80.49% 80.63% +0.14%
======================================================
Files 147 146 -1
Lines 21866 21947 +81
Branches 5149 5176 +27
======================================================
+ Hits 17602 17698 +96
+ Misses 3045 3030 -15
Partials 1219 1219 ☔ View full report in Codecov by Sentry. |
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 have suggested some simplication to avoid boilerplate code with the idea that if self._residual_line
is not None, then it should be connected.
The same would need to be done for disconnecting the line, when closing the figure and most likely self._residual_line
will need to be reset to None
- I don't think this is the case at the moment.
I didn't test that my suggestion are corrects (only by reading the code), so I may be missing something!
It would need a test to check that event are connected and disconnected properly, for example something along the lines of:
hyperspy/hyperspy/tests/drawing/test_plot_signal_tools.py
Lines 91 to 100 in 3b350ff
def test_plot_BackgroundRemoval_close_figure(): | |
s = signals.Signal1D(np.arange(1000).reshape(10, 100)) | |
br = BackgroundRemoval(s, background_type="Gaussian") | |
signal_plot = s._plot.signal_plot | |
assert len(signal_plot.events.closed.connected) == 5 | |
assert len(s.axes_manager.events.indices_changed.connected) == 4 | |
s._plot.close() | |
assert br._fit not in s.axes_manager.events.indices_changed.connected | |
assert br.disconnect not in signal_plot.events.closed.connected |
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.
nice I will test the changes soon
Co-authored-by: Eric Prestat <eric.prestat@gmail.com>
Co-authored-by: Eric Prestat <eric.prestat@gmail.com>
I tried running test_plot_BackgroundRemoval_close_figure() and didn't get any error so I think the connection is being closed?
|
@ericpre. Took me a while to understand the testing part. But after updating the disconnection, here is a test I made.
Here is the result. I am not sure what "<bound method BaseModel._on_navigating of >" is and how to disconnect that. |
@HanHsuanWu, I will look at this in a couple of days. |
This is a function that fetch the current value of the model when the indices are changed and this should stay connected. It is connected during initialisation of the class: and call: Lines 997 to 1001 in b742845
If you check that the number of connected functions is the same before plotting and after closing the plot, that should be good enough. |
As suggested in #3352, I rebase to RELEASE_next_patch, as well as cleaning up the commits history.
Currently, the plotted residual is not being updated whenever the model line changes.
So I added update for model._residual_line whenever mode._model_line is being updated.