spacetx / starfish

starfish: unified pipelines for image-based transcriptomics
https://spacetx-starfish.readthedocs.io/en/latest/
MIT License
226 stars 68 forks source link

register_translation is deprecated #1887

Closed lambdamoses closed 4 years ago

lambdamoses commented 4 years ago

Description

When running your Quick Start notebook, I got an error at the image registration step that says register_translation in skimages is deprecated.

Steps/Code to Reproduce

from starfish import data

# Download experiment
e = data.MOUSE_V_HUMAN()
# Load ImageStacks from experiment
imgs = e.fov().get_image('primary')  # primary images consisting of 4 rounds and 4 channels
dots = e.fov().get_image('dots')  # auxiliary image with all rolonies stained
nuclei = e.fov().get_image('nuclei')  # auxiliary image with dapi stain

from starfish.image import ApplyTransform, LearnTransform
from starfish.types import Axes

def register(imgs, dots, method = 'translation'):
    mip_imgs = imgs.reduce(dims = [Axes.CH, Axes.ZPLANE], func="max")
    mip_dots = dots.reduce(dims = [Axes.CH, Axes.ZPLANE], func="max")
    learn_translation = LearnTransform.Translation(reference_stack=mip_dots, axes=Axes.ROUND, upsampling=1000)
    transforms_list = learn_translation.run(mip_imgs)
    warp = ApplyTransform.Warp()
    registered_imgs = warp.run(imgs, transforms_list=transforms_list, in_place=False, verbose=True)
    return registered_imgs

# filter
imgs_wth, dots_wth = filter_white_tophat(imgs, dots, 15)

# register
registered_imgs = register(imgs_wth, dots_wth)

Expected Results

As shown in the Quick Start notebook

Actual Results

/home/lambda/anaconda3/lib/python3.7/site-packages/skimage/feature/__init__.py:43: skimage_deprecation: Function ``register_translation`` is deprecated and will be removed in version 0.19. Use ``skimage.registration.phase_cross_correlation`` instead.
  removed_version='0.19')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-fb152b26fe05> in <module>
      3 
      4 # register
----> 5 registered_imgs = register(imgs_wth, dots_wth)
      6 
      7 # find spots

<ipython-input-5-db5545f8a08b> in register(imgs, dots, method)
      7     mip_dots = dots.reduce(dims = [Axes.CH, Axes.ZPLANE], func="max")
      8     learn_translation = LearnTransform.Translation(reference_stack=mip_dots, axes=Axes.ROUND, upsampling=1000)
----> 9     transforms_list = learn_translation.run(mip_imgs)
     10     warp = ApplyTransform.Warp()
     11     registered_imgs = warp.run(imgs, transforms_list=transforms_list, in_place=False, verbose=True)

~/anaconda3/lib/python3.7/site-packages/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__)

~/anaconda3/lib/python3.7/site-packages/starfish/core/image/_registration/LearnTransform/translation.py in run(self, stack, verbose, *args)
     67             shift, error, phasediff = register_translation(src_image=target_image,
     68                                                            target_image=reference_image,
---> 69                                                            upsample_factor=self.upsampling)
     70             if verbose:
     71                 print(f"For {self.axes}: {a}, Shift: {shift}, Error: {error}")

~/anaconda3/lib/python3.7/site-packages/skimage/_shared/utils.py in wrapped(*args, **kwargs)
    161             elif self.behavior == 'raise':
    162                 raise skimage_deprecation(msg)
--> 163             return func(*args, **kwargs)
    164 
    165         # modify doc string to display deprecation warning

~/anaconda3/lib/python3.7/site-packages/skimage/feature/__init__.py in register_translation(src_image, target_image, upsample_factor, space, return_error)
     47     return phase_cross_correlation(src_image, target_image,
     48                                    upsample_factor=upsample_factor,
---> 49                                    space=space, return_error=return_error)
     50 
     51 

~/anaconda3/lib/python3.7/site-packages/skimage/registration/_phase_cross_correlation.py in phase_cross_correlation(reference_image, moving_image, upsample_factor, space, return_error, reference_mask, moving_mask, overlap_ratio)
    202     # real data needs to be fft'd.
    203     elif space.lower() == 'real':
--> 204         src_freq = fft.fftn(reference_image)
    205         target_freq = fft.fftn(moving_image)
    206     else:

~/anaconda3/lib/python3.7/site-packages/scipy/fft/_backend.py in __ua_function__(method, args, kwargs)
     21         if fn is None:
     22             return NotImplemented
---> 23         return fn(*args, **kwargs)
     24 
     25 

~/anaconda3/lib/python3.7/site-packages/scipy/fft/_pocketfft/basic.py in c2cn(forward, x, s, axes, norm, overwrite_x, workers)
    144     Return multidimensional discrete Fourier transform.
    145     """
--> 146     tmp = _asfarray(x)
    147 
    148     shape, axes = _init_nd_shape_and_axes(tmp, s, axes)

~/anaconda3/lib/python3.7/site-packages/scipy/fft/_pocketfft/helper.py in _asfarray(x)
     93 
     94     # Always align input
---> 95     return np.array(x, copy=not x.flags['ALIGNED'])
     96 
     97 def _datacopied(arr, original):

~/anaconda3/lib/python3.7/site-packages/xarray/core/common.py in __getattr__(self, name)
    231                     return source[name]
    232         raise AttributeError(
--> 233             "{!r} object has no attribute {!r}".format(type(self).__name__, name)
    234         )
    235 

AttributeError: 'DataArray' object has no attribute 'flags'

Versions

I just ran conda update --all.

Linux-3.10.0-1127.8.2.el7.x86_64-x86_64-with-centos-7.8.2003-Core
Python 3.7.6 | packaged by conda-forge | (default, Jun  1 2020, 18:57:50) 
[GCC 7.5.0]
NumPy 1.18.1
SciPy 1.4.1
scikit-image 0.17.2
pandas 1.0.4
sklearn 0.22.1
xarray 0.15.1
sympy 1.6
starfish 0.2.0
mattcai commented 4 years ago

Thank you for trying out the Quick Start tutorial. We are aware of this issue (#1885) and it'll be fixed as part of PR #1886. In the meantime, you can use the compatible scikit-image by doing pip install scikit-image==0.15.0.

mattcai commented 4 years ago

closed by #1886