Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when attempting to view a buffered subimage with itkwidgets==1.0a35 #678

Open
tbirdso opened this issue Aug 16, 2023 · 2 comments

Comments

@tbirdso
Copy link

tbirdso commented Aug 16, 2023

Overview

Observed an error when attempting to view an itk.Image with itkwidgets==1.0a35.

I am not 100% certain that the error lies in itkwidgets. The stack trace includes ngff_zarr, dask_image, and scipy.

Full Exception Message

> itkwidgets.view(subimage)
Traceback (most recent call last):
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\IPython\core\interactiveshell.py", line 3508, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "C:\Users\tom.birdsong\AppData\Local\Temp\ipykernel_9092\2030550360.py", line 2, in <module>
    itkwidgets.view(subimage)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\itkwidgets\viewer.py", line 465, in view
    viewer = Viewer(data=data, **kwargs)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\itkwidgets\viewer.py", line 136, in __init__
    data = build_init_data(input_data)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\itkwidgets\_initialization_params.py", line 88, in build_init_data
    result = _get_viewer_image(data, label=False)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\itkwidgets\integrations\__init__.py", line 78, in _get_viewer_image
    multiscales = to_multiscales(ngff_image, method=method)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\ngff_zarr\to_multiscales.py", line 317, in to_multiscales
    images = _downsample_dask_image(
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\ngff_zarr\methods\_dask_image.py", line 396, in _downsample_dask_image
    downscaled_array = dask_image.ndinterp.affine_transform(
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\dask_image\ndinterp\__init__.py", line 93, in affine_transform
    ndimage_affine_transform(np.zeros([0] * image.ndim),
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\scipy\ndimage\_interpolation.py", line 599, in affine_transform
    offset = _ni_support._normalize_sequence(offset, input.ndim)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\scipy\ndimage\_ni_support.py", line 63, in _normalize_sequence
    if not is_str and isinstance(input, Iterable):
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\abc.py", line 98, in __instancecheck__
    return _abc_instancecheck(cls, instance)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\abc.py", line 102, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\abc.py", line 102, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\typing_extensions.py", line 583, in __subclasscheck__
    return super().__subclasscheck__(other)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\abc.py", line 102, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\typing_extensions.py", line 639, in _proto_hook
    raise TypeError("Instance and class checks can only be used with"
TypeError: Instance and class checks can only be used with @runtime_checkable protocols

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\IPython\core\interactiveshell.py", line 2105, in showtraceback
    stb = self.InteractiveTB.structured_traceback(
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\IPython\core\ultratb.py", line 1396, in structured_traceback
    return FormattedTB.structured_traceback(
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\IPython\core\ultratb.py", line 1287, in structured_traceback
    return VerboseTB.structured_traceback(
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\IPython\core\ultratb.py", line 1140, in structured_traceback
    formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\IPython\core\ultratb.py", line 1055, in format_exception_as_a_whole
    frames.append(self.format_record(record))
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\IPython\core\ultratb.py", line 955, in format_record
    frame_info.lines, Colors, self.has_colors, lvals
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\IPython\core\ultratb.py", line 778, in lines
    return self._sd.lines
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\stack_data\utils.py", line 144, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\stack_data\core.py", line 734, in lines
    pieces = self.included_pieces
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\stack_data\utils.py", line 144, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\stack_data\core.py", line 681, in included_pieces
    pos = scope_pieces.index(self.executing_piece)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\stack_data\utils.py", line 144, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\stack_data\core.py", line 660, in executing_piece
    return only(
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\executing\executing.py", line 182, in only
    if isinstance(it, Sized):
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\typing.py", line 769, in __instancecheck__
    return self.__subclasscheck__(type(obj))
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\typing.py", line 774, in __subclasscheck__
    return issubclass(cls, self.__origin__)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\abc.py", line 102, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\abc.py", line 102, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\typing_extensions.py", line 583, in __subclasscheck__
    return super().__subclasscheck__(other)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\abc.py", line 102, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
  File "C:\Users\tom.birdsong\Anaconda3\envs\venv-itk\lib\site-packages\typing_extensions.py", line 639, in _proto_hook
    raise TypeError("Instance and class checks can only be used with"
TypeError: Instance and class checks can only be used with @runtime_checkable protocols

Platform Information

Windows 10
Python 3.8.5
itk == 5.4rc1
itkwidgets == 1.0a35
dask == 2023.5.0 2022.8.0
dask-image == 2023.3.0 2021.12.0
ngff-zarr == 0.4.6
scipy == 1.10.1

Additional Details

The subimage was extracted from a requested/buffered region in a larger image using itk.extract_image_filter.

> print(subimage)
Image (00000247B1238600)
  RTTI typeinfo:   class itk::Image<float,3>
  Reference Count: 1
  Modified Time: 4416
  Debug: Off
  Object Name: 
  Observers: 
    none
  Source: (none)
  Source output name: (none)
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 4404
  UpdateMTime: 4415
  RealTimeStamp: 0 seconds 
  LargestPossibleRegion: 
    Dimension: 3
    Index: [6321, 9160, 2699]
    Size: [556, 556, 501]
  BufferedRegion: 
    Dimension: 3
    Index: [6321, 9160, 2699]
    Size: [556, 556, 501]
  RequestedRegion: 
    Dimension: 3
    Index: [6321, 9160, 2699]
    Size: [556, 556, 501]
  Spacing: [0.0018, 0.0018, 0.002]
  Origin: [13.3776, 18.4878, 7.398]
  Direction: 
-1 0 0
0 -1 0
0 0 -1

  IndexToPointMatrix: 
-0.0018 0 0
0 -0.0018 0
0 0 -0.002

  PointToIndexMatrix: 
-555.556 0 0
0 -555.556 0
0 0 -500

  Inverse Direction: 
-1 0 0
0 -1 0
0 0 -1

  PixelContainer: 
    ImportImageContainer (00000247B5450870)
      RTTI typeinfo:   class itk::ImportImageContainer<unsigned __int64,float>
      Reference Count: 1
      Modified Time: 4413
      Debug: Off
      Object Name: 
      Observers: 
        none
      Pointer: 0000024805EDE040
      Container manages memory: true
      Size: 154877136
      Capacity: 154877136

EDIT: Updated platform information.

@thewtex
Copy link
Member

thewtex commented Aug 16, 2023

@tbirdso thanks for the report!

Looks likely to be a dask-image / scipy issue. For reference, could you please add:

  • Python version
  • dask-image version
  • scipy version

?

@tbirdso
Copy link
Author

tbirdso commented Aug 16, 2023

Looks likely to be a dask-image / scipy issue. For reference, could you please add:

Sure thing, I've added this information to the issue summary. My dask-image version looks old, will attempt to reproduce with the most recent version.

EDIT: I am able to reproduce with the latest version of dask-image. I have updated the issue summary accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants