Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

added a Feature Histogram Widget#148

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dstansby merged 26 commits intomatplotlib:mainfromjo-mueller:add-feature-histogram
Aug 25, 2023

Conversation

jo-mueller
Copy link
Contributor

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 whetherscatter.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:

importnumpyasnpimportnaparifromnapari_matplotlibimportHistogramWidget,FeaturesHistogramWidgetn_points=1000random_points=np.random.random((n_points,3))*10feature1=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},face_color='feature1',size=1)widget=FeaturesHistogramWidget(viewer)viewer.window.add_dock_widget(widget)widget._set_axis_keys('feature1')widget._key_selection_widget()widget._set_axis_keys('feature2')widget._key_selection_widget()

This code is essentially also what I added to the tests (tests are passing locally).

Looking forward to hear your thoughts on this! :)

@jo-mueller
Copy link
ContributorAuthor

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.

jo-muellerand others added2 commitsJune 2, 2023 10:36
Co-Authored-By: Marcelo Zoccoler <26173597+zoccoler@users.noreply.github.com>
Copy link
Member

@dstansbydstansby left a 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!

@jo-mueller
Copy link
ContributorAuthor

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.

@jo-muellerjo-muellerforce-pushed theadd-feature-histogram branch 2 times, most recently from524fdbd to83747f9CompareJune 26, 2023 11:14
@jo-mueller
Copy link
ContributorAuthor

jo-mueller commentedJun 26, 2023
edited
Loading

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.

@dstansby
Copy link
Member

dstansby commentedJun 26, 2023
edited
Loading

pre-commit.ci autofix

pre-commit-ci[bot] reacted with rocket emoji

Copy link
Member

@dstansbydstansby left a 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.

@jo-mueller
Copy link
ContributorAuthor

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=1000random_points=np.random.random((n_points,3))*10feature1=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 plotwidget._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 plotviewer.layers.selection.clear()viewer.layers.selection.add(viewer.layers[1])assert_figures_equal(widget.figure,fig1)

removed `reset_choices()` statementRevert "removed `reset_choices()` statement"This reverts commited8fc0a.removed `reset_choices()` from feature histogram
@dstansby
Copy link
Member

For a figure test, see e.g.,

@pytest.mark.mpl_image_compare
deftest_histogram_2D(make_napari_viewer,astronaut_data):
viewer=make_napari_viewer()
viewer.theme="light"
viewer.add_image(astronaut_data[0],**astronaut_data[1])
fig=HistogramWidget(viewer).figure
# Need to return a copy, as original figure is too eagerley garbage
# collected by the widget
returndeepcopy(fig)

This using thepytest-mpl plugin to compare the generated image with an image stored in the repository in this directory:https://github.com/matplotlib/napari-matplotlib/tree/main/src/napari_matplotlib/tests/baseline

@jo-mueller
Copy link
ContributorAuthor

For the figure test: So@pytest.mark.mpl_image_compare will compare the returned image toany image in thebaseline directory?

@dstansby
Copy link
Member

No, you'll need to generate the new test image - seehttps://github.com/matplotlib/pytest-mpl#usage for instructions.

@jo-mueller
Copy link
ContributorAuthor

@dstansby

No, you'll need to generate the new test image - seematplotlib/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 forpytest --mpl seemed quite complicated to me. It requires a few additional installation steps (pip install pyqt6 tinycss2) that did not seem evident to me from the.

@dstansby
Copy link
Member

No worries! If you don't mind, I'd be happy to pick this up and get the test working?

@jo-mueller
Copy link
ContributorAuthor

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 👍

dstansby reacted with thumbs up emoji

@dstansbydstansby mentioned this pull requestAug 25, 2023
@dstansby
Copy link
Member

dstansby commentedAug 25, 2023
edited
Loading

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...

jo-mueller reacted with heart emoji

@dstansby
Copy link
Member

Looks like it's just code coverage failing

@dstansbydstansby marked this pull request as ready for reviewAugust 25, 2023 16:07
@dstansbydstansby merged commitdc1f3bb intomatplotlib:mainAug 25, 2023
@jo-muellerjo-mueller deleted the add-feature-histogram branchAugust 26, 2023 23:50
@jo-muellerjo-mueller mentioned this pull requestOct 4, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dstansbydstansbydstansby approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@jo-mueller@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp