AllenCell / napari-allencell-segmenter

A plugin that enables image segmentation provided by Allen Institute for Cell Science
BSD 3-Clause "New" or "Revised" License
16 stars 6 forks source link

Import error for watershed function when running cetn2 workflow #133

Closed memoryleine closed 2 years ago

memoryleine commented 2 years ago

This text document allows the plugin developers to gather the information they need to understand and prioritize your bug report. Please write your responses in the space below each section (replace [your answer here] with your answer), then click the "Submit new issue" button when you are finished. You can preview the formatting of this document using the Preview tab above.

Description

A clear description of the bug I freshly installed napari and this plugin into a new environment. When trying to run the watershed cutting step of the cetn2 workflow, the watershed function from skimage.morphology cannot be imported. I think this is probably because the watershed function in the morphology module is deprecated, and the function from skimage.segmentation.watershed should be used instead. (For reference, the version of scikit-image in the environment is 0.19.2.)

Error message

ImportError                               Traceback (most recent call last)
File ~/miniconda3/envs/napari-env/lib/python3.9/site-packages/superqt/utils/_qthreading.py:616, in create_worker.<locals>.reraise(e=ImportError("cannot import name 'watershed' from...9/site-packages/skimage/morphology/__init__.py)"))
    615 def reraise(e):
--> 616     raise e
        e = ImportError("cannot import name 'watershed' from 'skimage.morphology' (/home/maddy/miniconda3/envs/napari-env/lib/python3.9/site-packages/skimage/morphology/__init__.py)")

File ~/miniconda3/envs/napari-env/lib/python3.9/site-packages/superqt/utils/_qthreading.py:176, in WorkerBase.run(self=<napari._qt.qthreading.GeneratorWorker object>)
    174     warnings.filterwarnings("always")
    175     warnings.showwarning = lambda *w: self.warned.emit(w)
--> 176     result = self.work()
        self = <napari._qt.qthreading.GeneratorWorker object at 0x7f3c056ae9d0>
    177 if isinstance(result, Exception):
    178     if isinstance(result, RuntimeError):
    179         # The Worker object has likely been deleted.
    180         # A deleted wrapped C/C++ object may result in a runtime
    181         # error that will cause segfault if we try to do much other
    182         # than simply notify the user.

File ~/miniconda3/envs/napari-env/lib/python3.9/site-packages/superqt/utils/_qthreading.py:443, in GeneratorWorker.work(self=<napari._qt.qthreading.GeneratorWorker object>)
    441 try:
    442     input = self._next_value()
--> 443     output = self._gen.send(input)
        self = <napari._qt.qthreading.GeneratorWorker object at 0x7f3c056ae9d0>
        input = None
        output = (WorkflowStep(category=<WorkflowStepCategory.CORE: 'core'>, function=SegmenterFunction(name='find_local_maxima', display_name='Find Local Maxima', function='peak_local_max_wrapper', module='aicssegmentation.core.utils', parameters=None), step_number=6, parent=[2, 5], parameter_values=None), <class 'numpy.ndarray'> (122, 908, 908) bool)
        self._gen = <generator object WorkflowStepsController._run_all_async at 0x7f3bee21d740>
    444     self.yielded.emit(output)
    445 except StopIteration as exc:

File ~/miniconda3/envs/napari-env/lib/python3.9/site-packages/napari_allencell_segmenter/controller/workflow_steps_controller.py:91, in WorkflowStepsController._run_all_async(self=<napari_allencell_segmenter.controller.workflow_steps_controller.WorkflowStepsController object>, parameter_inputs=[{'scaling_param': [12.0, 160.0, 300, 2000]}, {'scaling_param': [5000]}, {'sigma': 1.0}, {'cutoff': 0.04, 'log_sigma': 1.0}, {'method': '3D', 'min_size': 3}, None, None, {'method': '3D', 'min_size': 3}])
     89 while not self.model.active_workflow.is_done():
     90     step = self.model.active_workflow.get_next_step()
---> 91     result = self.model.active_workflow.execute_next(parameter_inputs[i])
        i = 6
        result = <class 'numpy.ndarray'> (122, 908, 908) bool
        parameter_inputs[i] = None
        self = <napari_allencell_segmenter.controller.workflow_steps_controller.WorkflowStepsController object at 0x7f3bf72f4ee0>
        parameter_inputs = [{'scaling_param': [12.0, 160.0, 300, 2000]}, {'scaling_param': [5000]}, {'sigma': 1.0}, {'log_sigma': 1.0, 'cutoff': 0.04}, {'min_size': 3, 'method': '3D'}, None, None, {'min_size': 3, 'method': '3D'}]
     92     i = i + 1
     93     yield (step, result)

File ~/miniconda3/envs/napari-env/lib/python3.9/site-packages/aicssegmentation/workflow/workflow.py:90, in Workflow.execute_next(self=<aicssegmentation.workflow.workflow.Workflow object>, parameters=None)
     87         res = self.get_result(i - 1)  # parents are 1 indexed
     88         image.append(res)
---> 90 result: np.ndarray = self.get_next_step().execute(image, parameters or step.parameter_values)
        step = WorkflowStep(category=<WorkflowStepCategory.CORE: 'core'>, function=SegmenterFunction(name='watershed_for_cutting', display_name='Watershed for cutting', function='watershed_wrapper', module='aicssegmentation.core.utils', parameters=None), step_number=7, parent=[5, 6], parameter_values=None)
        image = [<class 'numpy.ndarray'> (122, 908, 908) bool, <class 'numpy.ndarray'> (122, 908, 908) bool]
        np = <module 'numpy' from '/home/maddy/miniconda3/envs/napari-env/lib/python3.9/site-packages/numpy/__init__.py'>
        parameters or step.parameter_values = None
        self = <aicssegmentation.workflow.workflow.Workflow object at 0x7f3bf4307610>
        parameters = None
        step.parameter_values = None
     91 self._results.append(result)
     93 # Only increment after running step

File ~/miniconda3/envs/napari-env/lib/python3.9/site-packages/aicssegmentation/workflow/workflow_step.py:76, in WorkflowStep.execute(self=WorkflowStep(category=<WorkflowStepCategory.CORE...p_number=7, parent=[5, 6], parameter_values=None), input_images=[<class 'numpy.ndarray'> (122, 908, 908) bool, <class 'numpy.ndarray'> (122, 908, 908) bool], parameters=None)
     73     if parameters is not None:
     74         return py_function(*input_images, **parameters)
---> 76     return py_function(*input_images)
        py_function = <function watershed_wrapper at 0x7f3b7ebd0550>
        input_images = [<class 'numpy.ndarray'> (122, 908, 908) bool, <class 'numpy.ndarray'> (122, 908, 908) bool]
     77 except TypeError:
     78     # Some functions want it as a list
     79     if parameters is not None:

File ~/miniconda3/envs/napari-env/lib/python3.9/site-packages/aicssegmentation/core/utils.py:449, in watershed_wrapper(bw=<class 'numpy.ndarray'> (122, 908, 908) bool, local_maxi=<class 'numpy.ndarray'> (122, 908, 908) bool)
    447 from scipy.ndimage import distance_transform_edt
    448 from skimage.measure import label
--> 449 from skimage.morphology import watershed, dilation, ball
    451 distance = distance_transform_edt(bw)
    452 im_watershed = watershed(
    453     -distance,
    454     label(dilation(local_maxi, selem=ball(1))),
    455     mask=bw,
    456     watershed_line=True,
    457 )

ImportError: cannot import name 'watershed' from 'skimage.morphology' (/home/maddy/miniconda3/envs/napari-env/lib/python3.9/site-packages/skimage/morphology/__init__.py)

* If you can't find the error message, go to Plugins > Plugin Errors > napari-allencell-segmenter
* Most of the time, the most helpful information is at the very bottom of the error output

Expected Behavior

What did you expect to happen instead? The watershed cutting runs successfully.

Reproduction

Please list the exact steps we can take to reproduce this bug.

  1. Install napari into a fresh environment
  2. Install the napari-allencell-segmenter plugin
  3. Open an image in napari
  4. Open the plugin, select an image channel, and select the cetn2 (dots) workflow
  5. Click "run all"

Environment

jxchen01 commented 2 years ago

thanks for bringing this error to our attention. I think this is exactly due to the API update on skimage. For some reason, our automatic build on aicssegmentation core package was disabled (otherwise, it is supposed to catch all such errors automatically in a weekly base). Anyway, we will get this fixed ASAP.

Thanks again for reporting this.