Skip to content
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

POC for 1D images (e.g. line plots) #2764

Closed
wants to merge 1 commit into from

Conversation

sofroniewn
Copy link
Contributor

Description

Following up on some of the discussion around 1D images from last weeks dev meeting, I put together this very rough and ready PR that does the bare minimum to support 1D plots for the image layer.

The idea is that we'd now allow viewer.dims.ndisplay=1 and we'd then do 1D slicing on all our layers and 1D rendering. For now I just hacked it together so that the image layer works. It also ignores a lot of additional possible settings, but it is pretty cool.

We can discuss whether we like this direction or not, but I'm already planning to make use of this branch with some 1D wave equations simulations I've been playing with where I have a time axis and a 1D plot (so a 2D dataset) but I want to look at 1D plots of it. I also want to use napari-animation to make movies of the wave propagation, so having this include in napari instead of something like matplotlib is very helpful.

Here's a movie of 1D slicing through a 2D image of a cell:

viewer.open_sample(plugin='scikit-image', sample='cell')
viewer.dims.ndisplay = 1
Screen.Recording.2021-05-22.at.5.44.36.PM.mov

Curious what others think cc @tlambert03 @jni @andy-sweet

Type of change

  • Bug-fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

References

How has this been tested?

  • example: the test suite for my feature covers cases x, y, and z
  • example: all tests pass with my change

Final checklist:

  • My PR is the minimum possible work for the desired functionality
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • If I included new strings, I have used trans. to make them localizable.
    For more information see our translations guide.

@sofroniewn sofroniewn added the feature New feature or request label May 23, 2021
@sofroniewn sofroniewn added this to the 0.4 milestone May 23, 2021
@codecov
Copy link

codecov bot commented May 23, 2021

Codecov Report

Merging #2764 (e09f0a8) into master (4b19ed6) will decrease coverage by 0.00%.
The diff coverage is 77.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2764      +/-   ##
==========================================
- Coverage   82.04%   82.03%   -0.01%     
==========================================
  Files         486      486              
  Lines       40483    40495      +12     
==========================================
+ Hits        33213    33221       +8     
- Misses       7270     7274       +4     
Impacted Files Coverage Δ
napari/layers/image/image.py 93.05% <66.66%> (-0.61%) ⬇️
napari/_vispy/vispy_image_layer.py 95.68% <77.77%> (-1.56%) ⬇️
napari/_vispy/vispy_camera.py 94.94% <100.00%> (+0.05%) ⬆️
napari/components/dims.py 97.70% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b19ed6...e09f0a8. Read the comment docs.

@goanpeca
Copy link
Contributor

We can discuss whether we like this direction or not, but I'm already planning to make use of this branch with some 1D wave equations simulations I've been playing with where I have a time axis and a 1D plot (so a 2D dataset) but I want to look at 1D plots of it. I also want to use napari-animation to make movies of the wave propagation, so having this include in napari instead of something like matplotlib is very helpful.

This looks like a lot of fun. Can I select the axis of the slice? X vs Y ? (a custom axis eventually?)

@sofroniewn
Copy link
Contributor Author

This looks like a lot of fun. Can I select the axis of the slice? X vs Y ? (a custom axis eventually?)

Yup, hitting the transpose / roll axis buttons now will change what get's sliced, though the sliced plot is always shown horizontally.

@tlambert03
Copy link
Member

tlambert03 commented May 23, 2021

I definitely like the concept of ndisplay = 1 ... but not quite sure that the main canvas is the right spot for it. Seems very specific to image/labels, in which case a linescan kind of feels more appropriate and flexible.

(if the motivation for this POC is fundamentally different than a linescan, let me know!)

@sofroniewn
Copy link
Contributor Author

(if the motivation for this POC is fundamentally different than a linescan, let me know!)

I was actually imaging this as being more generally useful, for example this movie of watching a 1D wave propagate through a medium of variable speed was the reason I made the branch. Note the data here is 2D ('t', 'x') and even though playing the movie is a special case of a linescan for an application like this it is nice to have the plot be inside the main canvas.

I can understand if people feel like 1D wave simulation is a bit unique of an application, that isn't so directly tied to imaging, but I do like this functionality a lot for this purpose!! We can definitely let this sit for a while before deciding what to do next, I'm happy using my branch right now.

Screen.Recording.2021-05-23.at.4.54.32.PM.mov

@sofroniewn sofroniewn added the stale PR that is not currently being worked on label Jul 19, 2021
@sofroniewn
Copy link
Contributor Author

We should probably turn this into an issue, link to the PR and close PR

@sofroniewn
Copy link
Contributor Author

This was discussed with the group the other day and there was some support for the use case from @jni, but this PR still needs some work before it is ready to merge. In particular we need to think about other layer types. We might need to watch out for some corner cases too around passing 1D arrays. I have created #3562 to track this idea and will close this now. Please weigh in there if you are interested in this functionality

@sofroniewn sofroniewn closed this Oct 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request make-issue stale PR that is not currently being worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants