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
NewFeature: Added jump click to plotting #3175
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## RELEASE_next_major #3175 +/- ##
======================================================
+ Coverage 81.27% 81.36% +0.08%
======================================================
Files 176 176
Lines 24401 24485 +84
Branches 5683 5691 +8
======================================================
+ Hits 19833 19923 +90
+ Misses 3261 3248 -13
- Partials 1307 1314 +7
☔ View full report in Codecov by Sentry. |
This is very nice! I tested this a little bit, some comments:
hyperspy/hyperspy/drawing/_widgets/rectangles.py", line 66, in _onjumpclick
self.position = (event.xdata, event.ydata)
^^^^^^^^^^^^^
hyperspy/hyperspy/drawing/widget.py", line 429, in <lambda>
lambda s, v: s._set_position(v))
^^^^^^^^^^^^^^^^^^
hyperspy/hyperspy/drawing/widget.py", line 423, in _set_position
position = self._validate_pos(position)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
hyperspy/hyperspy/drawing/widget.py", line 405, in _validate_pos
pos = np.maximum(pos, [ax.low_value for ax in self.axes])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'NoneType' and 'float' |
This has some performance implications, especially for large lazy datasets, since it means that (potentially) two chunks are loaded into memory for each "jump". I think this is due to this part of the code: if np.ndim(value) == 0 and len(self.axes) == 1:
self.position = [self.axes[0].index2value(value)]
elif len(self.axes) != len(value):
raise ValueError()
else:
p = []
for i in range(len(self.axes)):
p.append(self.axes[i].index2value(value[i]))
self.position = p
indices = property(lambda s: s._get_indices(),
lambda s, v: s._set_indices(v)) This part of the code: hyperspy/hyperspy/drawing/widget.py Line 363 in d0a266a
|
Thanks for testing this! Always good to see where things might go wrong on a different computer
I think yes? Unless we want to make the click and drag marker behavior only work with the "left-click". It wouldn't be too hard to do that.
This is weird... I'm having a hard time replicating this as well. My best guess here is that your computer is sending a click first to the edge of the canvas and then to the point you actually selected. I've tested this and at least for my computer I don't think it is happening but I'm not sure.
This is another thing that I'm not getting an error with but regardless it should be fixed by adding the |
Yea I think that this is a potential issue but I can't seem to replicate it. My best guess is that it is a bug related to an older
Possibly... I can try it on a different computer/ operating system and see. I wrote some tests so we should be able to test this. |
Thank you for quickly writing up this PR on discontinuous navigation after our offline discussion, @CSSFrancis! Plotting geometrical simulations on top of EBSD patterns using markers is helpful when evaluating indexing results. We use this approach extensively in kikuchipy (see this tutorial). My issue with continuous navigation is that all markers are created and added to a signal before navigating. This operation is memory-intensive in kikuchipy. I hope discontinuous navigation can enable lazy markers and computation of one marker at a time. I tried this PR out locally, and it works nicely! However, I'm seeing the same behavior as @manunor:
|
This is with def _onjumpclick(self, event):
# Callback for MPL pick event
if event.key=="shift" and event.inaxes:
print(event.xdata, event.ydata)
self.position = (event.xdata, event.ydata) Running this, it only outputs one event per click. |
My guess is that this is only really visible when loading a large dataset from the hard drive, maybe via a HDF5 ( |
By 'this', do you mean the extra navigation positing showing? I see this behavior when running @CSSFrancis's example in the top comment, using a Dask array. With Matplotlib v3.7.1. |
Yes. I'm running Ubuntu. Could it be a Ubuntu specific issue? |
I'm also running Ubuntu. |
I'm running on Ubuntu 20.04.6 as well with Matplotlib v3.7.1 as well and haven't been able to replicate it. I tried on my M1 macbook as well and couldn't replicate it there either. |
This is the part that I am stuck on... the position is changed which should call the You could try seeing if this function is getting called twice. It might also be that the |
That is exactly what is happening! You can kind of see it on the video where one of the indexes switches first and the second one switches a little bit after. |
Okay now try it out... It should be fixed now. Only some of the events where suppressed causing the It was happening on my computer but apparently it was flashing too fast :) @ericpre do you have any idea if changing from |
@hakonanes Lazy markers is something that I think would be a great thing to add! Most of the groundwork in #3148 is there (I just need to allow a There are some potential drawbacks of lazy plotting markers (mostly that you can't operate in parallel to calculate them so it could be slow to plot them/ move from one chunk to the next). There are potential ways around that so maybe we start by adding the feature and go from there. |
Okay maybe I have found the bug but introduced some new ones :) I'm going to have to look into the suppress code and figure out exactly which function to suppress rather than blanket suppressing all of them. It might just be the new |
Hello, I am also quite fond of this idea, so I can help out with some testing! |
This fix makes it work as intended on my set-up! |
That fixed the issue with the position not changing (#3175 (comment)), but the "double jump" is still there (the one in the animation in this comment: #3175 (comment)) |
Hmmm let me write some more tests and we can go from there. |
…imes that the update is called
I added two tests to make sure that only one I think that tests the two bugs that we were seeing here. |
That did indeed fixed the issue! Now it works nicely, and there is one "jump" per click. |
Thanks for all of your testing and finding some of the bugs I missed :). Probably should have just written the event tests first. There also should probably be more mock event tests in general so this is probably a good start. @ericpre when you have a chance, can you look at how I handled the event suppression before this is merged? |
Yeah, I find that for some features or changes that is a nice workflow: adding the tests first, then implementing the change. |
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 is useful., however, this is working only the rectangle widget. It shouldn't too difficult to make it work for all widgets.
with self.axes_manager.events.indices_changed.suppress(): | ||
for i in range(len(self.axes)): | ||
self.axes[i].value = self._pos[i] | ||
self.axes_manager.events.indices_changed.trigger(obj=self.axes_manager) |
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.
Instead to making a SquareWidget._pos_changed
the code should be changed in DraggableWidgetBase._pos_changed
?
Yea I think that it would be good. I can add it for the |
Indeed, the several widgets situation needs to be handle correctly, currently, when adding several square widgets, the issue will occur. The widgets have a |
@ericpre I added in the ability to use the jump-click method with the Horizontal and Vertical plots and refactored things based on your suggestions. I also added some tests for testing the dragging a Line Marker |
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.
That's brilliant! Just need some clean-up.
It seems that the very first event with |
I think this is just because the figure needs to be active/ selected? The same thing applies to using the arrow keys where you need to have clicked on the figure first. It's kind of frustrating but I'm not really sure how you would fix that? I'd have to dig into the |
Yes, I thought so too but if this was the case, it would do it too for the click and drag of the pointer, which works fine at first attempt. For some reason, |
Co-authored-by: Eric Prestat <eric.prestat@gmail.com>
Description of the change
This is just a quick change to the plotting to allow for jumping. I think we might want to make it possible to change which key is used with the jump.
I can make this a little more robust and we could potentially add it to all of the widgets but the main problem is if you have multiple widgets I don't know how it should work. Same with handing two singles overlaid in 1D.
Progress of the PR
upcoming_changes
folder (seeupcoming_changes/README.rst
),readthedocs
doc build of this PR (link in github checks)Minimal example of the bug fix or the new feature
Screencast.from.06-19-2023.06_10_13.PM.online-video-cutter.com.mp4