spacetx/starfish

blob throws error when run with no `reference_image` and `is_volume=False`

mattcai opened this issue · 2 comments

Description

When using BlobDetector to find spots in an ImageStack without using a reference_image and with is_volume=False error is thrown because BlobDetector is hard coded to parse the result of skimage.feature.blob_log run on 3D numpy array.

Using a reference_image doesn't throw this error because it ignores the is_volume argument and runs everything like is_volume=True.

Steps/Code to Reproduce

code to reproduce error

Expected Results

Expect to return an IntensityTable

Actual Results

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-57-d5060f4c30ec> in <module>
      7     measurement_type='mean',
      8 )
----> 9 bd_spots = bd.run(image_stack=wth_imgs)

~/starfish-CI/starfish/starfish/core/pipeline/algorithmbase.py in helper(*args, **kwargs)
     21         @functools.wraps(func)
     22         def helper(*args, **kwargs):
---> 23             result = func(*args, **kwargs)
     24             if result is not None:
     25                 method_class_str = str(args[0].__class__)

~/starfish-CI/starfish/starfish/core/spots/FindSpots/blob.py in run(self, image_stack, reference_image, n_processes, *args)
    193                 func=spot_finding_method,
    194                 group_by=determine_axes_to_group_by(self.is_volume),
--> 195                 n_processes=n_processes
    196             )
    197             results = SpotFindingResults(imagestack_coords=image_stack.xarray.coords,

~/starfish-CI/starfish/starfish/core/imagestack/imagestack.py in transform(self, func, group_by, verbose, n_processes, *args, **kwargs)
    947             # Note: results is [None, ...] if executing an in-place workflow
    948             # Note: this return must be inside the context manager or the Pool will deadlock
--> 949             return list(zip(results, selectors))
    950 
    951     @staticmethod

/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py in result_iterator()
    596                     # Careful not to keep a reference to the popped future
    597                     if timeout is None:
--> 598                         yield fs.pop().result()
    599                     else:
    600                         yield fs.pop().result(end_time - time.monotonic())

/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py in result(self, timeout)
    433                 raise CancelledError()
    434             elif self._state == FINISHED:
--> 435                 return self.__get_result()
    436             else:
    437                 raise TimeoutError()

/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py in run(self)
     55 
     56         try:
---> 57             result = self.fn(*self.args, **self.kwargs)
     58         except BaseException as exc:
     59             self.future.set_exception(exc)

~/starfish-CI/starfish/starfish/core/imagestack/imagestack.py in _processing_workflow(worker_callable, data_array, args, kwargs, selectors)
    962 
    963         # pass worker_callable a view into the backing array, which will be overwritten
--> 964         return worker_callable(sliced, *args, **kwargs)  # type: ignore
    965 
    966     @property

~/starfish-CI/starfish/starfish/core/spots/FindSpots/blob.py in image_to_spots(self, data_image)
    135         y_inds = fitted_blobs_array[:, 1].astype(int)
    136         x_inds = fitted_blobs_array[:, 2].astype(int)
--> 137         radius = np.round(fitted_blobs_array[:, 3] * np.sqrt(3))
    138         data_image = np.asarray(data_image)
    139         intensities = data_image[tuple([z_inds, y_inds, x_inds])]

IndexError: index 3 is out of bounds for axis 1 with size 3

starfish user trying to find spots in 3D images runs out of memory when using is_volume=True. Her workaround seems analogous to setting is_volume=False. Fixing this bug would allow her to use BlobDetector as intended.

This is fixed in #1985