-
Notifications
You must be signed in to change notification settings - Fork 21
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
added a Feature Histogram Widget #148
Conversation
PS: @dstansby I didn't see that there was ongoing work on a different PR because it wasn't linked to the issue. Feel free to treat this as stale for while. |
fb47952
to
91f6d16
Compare
Co-Authored-By: Marcelo Zoccoler <[email protected]>
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.
Looking good - a few major changes to make though. I have time to revise this myself, or I can leave you to do it- let me know either way!
Hi @dstansby , thanks a lot for taking the time to review this! I think I can definitely get those changes done myself. I'll be on vacation in the coming week so PR should come sometime in the second-to-next week. |
Co-authored-by: David Stansby <[email protected]>
Co-authored-by: David Stansby <[email protected]>
Co-authored-by: David Stansby <[email protected]>
…/napari-matplotlib into add-feature-histogram
524fdbd
to
83747f9
Compare
…/napari-matplotlib into add-feature-histogram
added parent to init
Hi @dstansby , I added your suggestions from above and replaced the magicgui widgets with pyqt code as has been done in the scatter widget in the meantime. Also sorry for the messy commit history - let me know if I should put the changes on a clean branch and re-start the PR. |
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
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've left one requst for a change. In addition, could you add a figure test? Hopefully the other test files help with that, but let me know if you need any pointers.
Otherwise I'm 👍 to merge.
Hi @dstansby , I'm not sure what you mean by figure test? I did add the following to the tests. This adds two points layers to the viewer with two sets of features assigned to each. I check whether the figure in the widget changes upon changing the key for the histogram and whether the plot changes as it should when the selected layer is changed. n_points = 1000
random_points = np.random.random((n_points, 3)) * 10
feature1 = np.random.random(n_points)
feature2 = np.random.normal(size=n_points)
viewer = make_napari_viewer()
viewer.add_points(
random_points,
properties={"feature1": feature1, "feature2": feature2},
name="points1",
)
viewer.add_points(
random_points,
properties={"feature1": feature1, "feature2": feature2},
name="points2",
)
widget = FeaturesHistogramWidget(viewer)
viewer.window.add_dock_widget(widget)
# Check whether changing the selected key changes the plot
widget._set_axis_keys("feature1")
fig1 = deepcopy(widget.figure)
widget._set_axis_keys("feature2")
assert_figures_not_equal(widget.figure, fig1)
# check whether selecting a different layer produces the same plot
viewer.layers.selection.clear()
viewer.layers.selection.add(viewer.layers[1])
assert_figures_equal(widget.figure, fig1) |
ed8fc0a
to
9d6988e
Compare
removed `reset_choices()` statement Revert "removed `reset_choices()` statement" This reverts commit ed8fc0a. removed `reset_choices()` from feature histogram
For a figure test, see e.g., napari-matplotlib/src/napari_matplotlib/tests/test_histogram.py Lines 8 to 16 in 87d34f5
This using the |
For the figure test: So |
No, you'll need to generate the new test image - see https://github.com/matplotlib/pytest-mpl#usage for instructions. |
Ok, I added the baseline image, but for some reason, the generated baseline is not detected by the test...Sorry for the back and forth, I'm not so familiar with these testing schemes 🙈 Just as a sidenote: Setting everything up for |
No worries! If you don't mind, I'd be happy to pick this up and get the test working? |
Not at all! Would be cool though if it were documented somewhere for future contributions 👍 |
Looks like the test image was just in the wrong directory :) I also did a few other minor fixes, will merge this and do a new release of napari-matplotlib if the tests pass. Thanks a lot for the contribution, and sorry for how long it took me to merge it... |
Looks like it's just code coverage failing |
Linked to issue #58
New features:
This PR introduces a new widget to create Histograms from feature data in Labels/Points/Shapes/Tracks/Vectors layers. It's strongly based off of the ScatterWidget. I wasn't sure whether
scatter.py
was the right place to put it, but it felt like a better fit thanhistogram.py
, which essentially just works with image intensity data rather than tabular data.Example code snippet
This code snipped demonstrates what it does:
This code is essentially also what I added to the tests (tests are passing locally).
Looking forward to hear your thoughts on this! :)