haesleinhuepf / napari-assistant

BSD 3-Clause "New" or "Revised" License
20 stars 5 forks source link

Exported jupyter notebook from 3D timelapse data throws errors #41

Open zoccoler opened 1 year ago

zoccoler commented 1 year ago

Hi everyone,

When a 3D timelapse data is loaded into napari, and some operations are applied with the Assistant, and the 'Generate Code -> Export Jupyter Notebook with Napari' is used, the newly generated notebook throws errors because it tries to apply the functions to a 4D image.

Minimal Working Example

import napari
import numpy as np
from skimage import io
image = np.random.randint(low=0, high=10, size=(10, 30, 30, 30))
image[:, 10:20, 10:20, 10:14] = 15
image[:, 10:20, 10:20, 16:20] = 20
io.imsave('test_image.tif', image)
viewer = napari.Viewer()
viewer.window.add_plugin_dock_widget('napari-assistant', 'Assistant')
test_image = io.imread('test_image.tif')
viewer.open('test_image.tif', layer_type='image')

Then, apply voronoi-otsu-labeling and click on 'Generate Code -> Export Jupyter Notebook with Napari'. The new notebook will throw an error for cle.voronoi_otsu_labeling.

Versions

python 3.9
napari 0.4.17
napari-assistant 0.4.4

Possible solution

An option could be to store the current_timepoint when generating code and feeding the functions with image[current_timepoint]. Also, commenting that a for loop should be used to have the results for all timepoints would be a good hint.

haesleinhuepf commented 1 year ago

Note to self @haesleinhuepf