haesleinhuepf / napari-time-slicer

A meta plugin for processing timelapse data timepoint by timepoint in napari
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

Aggregate data #11

Open jo-mueller opened 1 year ago

jo-mueller commented 1 year ago

Fixes #4

Hi @haesleinhuepf ,

this PR attempts to start on expanding the functionality of the time-slicer to more Layer types and hopefully allow other functions that use the time-slicer to be a bit more agnostic to whether something is 4D or 3D or 2D +t or whatever.

Summary

In short, I brought the TimelapseConverter class from napari-stress (originally here) to the time-slicer and re-factored it a bit to be cleaner and better readable.

The class has two major methods: convert_4d_data_to_list and convert_list_to_4d_data which convert 4D to a list of 3D data or vice versa. The methods only require the to-be-converted data and the type of the input layer. The correct conversion function is then looked up from a dictionary that holds the respective conversion function for each kind of layer.

In the time-slicer, I created a new function aggregate, which basically drags the slider and aggregates all the data in memory. The aggregation only requires the convert_list_to_4d_data from the TimelapseConverter, but maybe the other step may also be helpful somewhere in the future if the first step in a workflow is a 4D surface or whatever.

Tests

I wrote unit tests and tested the aggregation from the napari viewer, which worked well. The only use case I didn't get to work was to get some measurements with regionprops aggregate those for all timeframes, which is probably because regionprops is currently not decorated (compatible?) with the time slicer.

This is probably not complete but maybe a step in the right direction :)

Future talk

haesleinhuepf commented 1 year ago

Hi Johannes @jo-mueller ,

awesome, thanks for working on this!

I presume the function you're proposing here does the tecnically same as this one: https://github.com/haesleinhuepf/napari-time-slicer/blob/90797a79fedfb0353c3fe5e8daf38455f3e6a5b8/src/napari_time_slicer/_function.py#L31-L74

Do you think it would be possible to merge both functions?

  • I would love to somehow submit the execution of a workflow step to a dask client rather than having to wait for each frame's computation.

I've started working on this here:

Feel free to try it out and see if this in compatible wit points and surfaces. Feedback is very welcome.

Best, Robery

jo-mueller commented 1 year ago

@haesleinhuepf thanks for looking into it.

Do you think it would be possible to merge both functions?

I could simply merge my code into that function, jup. They are pretty identical, that's true ^^ I'll update the PR.

jo-mueller commented 1 year ago

@haesleinhuepf I merged the two functions with identical scope into a single function (the one that already existed).

jo-mueller commented 1 year ago

Hi @haesleinhuepf , thanks for taking the time to look at this. Just a side note on how I did the interactive testing: I created some 2D+t sample data like this:

from skimage import data
sample_data = np.stack([data.binary_blobs()] for i in range(5))

and added it to a napari viewer. I then created a small workflow (connected components, label erosion) and used the convert_to_stack4d function from the tools menu. I would also like to add this test routine as an actual test to the PR, but I'm not sure how I can recreate the interactively assembled workflow from code...

Otherwise, I think it's also functional as it is.