InsightSoftwareConsortium / napari-itk-io

File IO with itk for napari.
Apache License 2.0
7 stars 2 forks source link

Opening JPG file causes error in napari when napari-itk-io is installed. #4

Open haesleinhuepf opened 2 years ago

haesleinhuepf commented 2 years ago

Hi Matt @thewtex ,

I hope you're doing well. I just had an issue with drag&drop of JPG files on napari. Napari can't open these images if napari-itk-io is installed. I pasted the error message below. The error does not point directly at napari-itk-io, but the error doesn't happen if this plugin is not installed. Thus, there must be some connection.

I think it happens with all JPG files. If not, I'm happy to send one of the files I tried.

Let me know if I can help tracing the issue down!

Best, Robert

Error log:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\miniconda3\envs\test2\lib\site-packages\napari\_qt\qt_viewer.py in dropEvent(self=, event=)
    992                 filenames.append(url.toString())
    993 
--> 994         self.viewer.open(filenames, stack=bool(shift_down))
        self.viewer.open = ), dims=Dims(ndim=2, ndisplay=2, last_used=0, range=((0, 2, 1), (0, 2, 1)), current_step=(0, 0), order=(0, 1), axis_labels=('0', '1')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[], scale_bar=ScaleBar(visible=False, colored=False, ticks=True, position=, font_size=10.0, unit=None), text_overlay=TextOverlay(visible=False, color= (4,) float64, font_size=10.0, position=, text=''), help='', status='Ready', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Control-Shift-C': >})>
        filenames = ['C:/structure/data/cats/00001IMG_00001_BURST20180819090638.jpg']
        global stack = undefined
        global bool = undefined
        shift_down = 
    995 
    996     def closeEvent(self, event):

~\miniconda3\envs\test2\lib\site-packages\napari\components\viewer_model.py in open(self=Viewer(axes=Axes(visible=False, labels=True, col..._viewer.QtViewer object at 0x000001B0445EFB80>>}), path=['C:/structure/data/cats/00001IMG_00001_BURST20180819090638.jpg'], stack=False, plugin=None, layer_type=None, **kwargs={})
    883             for _path in pbr:
    884                 added.extend(
--> 885                     self._add_layers_with_plugins(
        self._add_layers_with_plugins = ), dims=Dims(ndim=2, ndisplay=2, last_used=0, range=((0, 2, 1), (0, 2, 1)), current_step=(0, 0), order=(0, 1), axis_labels=('0', '1')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[], scale_bar=ScaleBar(visible=False, colored=False, ticks=True, position=, font_size=10.0, unit=None), text_overlay=TextOverlay(visible=False, color= (4,) float64, font_size=10.0, position=, text=''), help='', status='Ready', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Control-Shift-C': >})>
        _path = 'C:/structure/data/cats/00001IMG_00001_BURST20180819090638.jpg'
        kwargs = {}
        plugin = None
        layer_type = None
    886                         _path, kwargs, plugin=plugin, layer_type=layer_type
    887                     )

~\miniconda3\envs\test2\lib\site-packages\napari\components\viewer_model.py in _add_layers_with_plugins(self=Viewer(axes=Axes(visible=False, labels=True, col..._viewer.QtViewer object at 0x000001B0445EFB80>>}), path_or_paths='C:/structure/data/cats/00001IMG_00001_BURST20180819090638.jpg', kwargs={}, plugin='napari-itk-io', layer_type=None)
    956             # actually add the layer
    957             with layer_source(path=filename, reader_plugin=plugin):
--> 958                 added.extend(self._add_layer_from_data(*_data))
        added.extend = 
        self._add_layer_from_data = ), dims=Dims(ndim=2, ndisplay=2, last_used=0, range=((0, 2, 1), (0, 2, 1)), current_step=(0, 0), order=(0, 1), axis_labels=('0', '1')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[], scale_bar=ScaleBar(visible=False, colored=False, ticks=True, position=, font_size=10.0, unit=None), text_overlay=TextOverlay(visible=False, color= (4,) float64, font_size=10.0, position=, text=''), help='', status='Ready', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Control-Shift-C': >})>
        _data = ( (3120, 4160, 3) uint8, {'channel_axis': 2, 'rgb': True, 'metadata': {'origin':  (2,) float64, 'spacing':  (2,) float64, 'direction':  (2, 2) float64}, 'scale':  (2,) float64, 'translate':  (2,) float64, 'name': '00001IMG_00001_BURST20180819090638'}, 'image')
    959         return added
    960 

~\miniconda3\envs\test2\lib\site-packages\napari\components\viewer_model.py in _add_layer_from_data(self=Viewer(axes=Axes(visible=False, labels=True, col..._viewer.QtViewer object at 0x000001B0445EFB80>>}), data= (3120, 4160, 3) uint8, meta={'channel_axis': 2, 'metadata': {'direction':  (2, 2) float64, 'origin':  (2,) float64, 'spacing':  (2,) float64}, 'name': '00001IMG_00001_BURST20180819090638', 'rgb': True, 'scale':  (2,) float64, 'translate':  (2,) float64}, layer_type='image')
   1030         try:
   1031             add_method = getattr(self, 'add_' + layer_type)
-> 1032             layer = add_method(data, **(meta or {}))
        layer = undefined
        add_method = ), dims=Dims(ndim=2, ndisplay=2, last_used=0, range=((0, 2, 1), (0, 2, 1)), current_step=(0, 0), order=(0, 1), axis_labels=('0', '1')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[], scale_bar=ScaleBar(visible=False, colored=False, ticks=True, position=, font_size=10.0, unit=None), text_overlay=TextOverlay(visible=False, color= (4,) float64, font_size=10.0, position=, text=''), help='', status='Ready', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Control-Shift-C': >})>
        data =  (3120, 4160, 3) uint8
        meta = {'channel_axis': 2, 'rgb': True, 'metadata': {'origin':  (2,) float64, 'spacing':  (2,) float64, 'direction':  (2, 2) float64}, 'scale':  (2,) float64, 'translate':  (2,) float64, 'name': '00001IMG_00001_BURST20180819090638'}
   1033         except TypeError as exc:
   1034             if 'unexpected keyword argument' not in str(exc):

~\miniconda3\envs\test2\lib\site-packages\napari\components\viewer_model.py in add_image(self=Viewer(axes=Axes(visible=False, labels=True, col..._viewer.QtViewer object at 0x000001B0445EFB80>>}), data= (3120, 4160, 3) uint8, channel_axis=2, rgb=True, colormap=None, contrast_limits=None, gamma=1, interpolation='nearest', rendering='mip', iso_threshold=0.5, attenuation=0.05, name='00001IMG_00001_BURST20180819090638', metadata={'direction':  (2, 2) float64, 'origin':  (2,) float64, 'spacing':  (2,) float64}, scale= (2,) float64, translate= (2,) float64, rotate=None, shear=None, affine=None, opacity=1, blending=None, visible=True, multiscale=None, cache=True, experimental_slicing_plane=None, experimental_clipping_planes=None)
    723             layer_list = list()
    724             for image, i_kwargs, _ in layerdata_list:
--> 725                 layer = Image(image, **i_kwargs)
        layer = undefined
        global Image = 
        image =  (3120, 4160) uint8
        i_kwargs = {'rgb': True, 'colormap': 'cyan', 'contrast_limits': None, 'gamma': 1, 'interpolation': 'nearest', 'rendering': 'mip', 'iso_threshold': 0.5, 'attenuation': 0.05, 'name': '00001IMG_00001_BURST20180819090638', 'metadata': {'origin':  (2,) float64, 'spacing':  (2,) float64, 'direction':  (2, 2) float64}, 'scale':  (2,) float64, 'translate':  (2,) float64, 'rotate': None, 'shear': None, 'affine': None, 'opacity': 1, 'blending': 'additive', 'visible': True, 'multiscale': False, 'cache': True, 'experimental_slicing_plane': None, 'experimental_clipping_planes': None}
    726                 self.layers.append(layer)
    727                 layer_list.append(layer)

~\miniconda3\envs\test2\lib\site-packages\napari\layers\image\image.py in __init__(self= instance, data= (3120, 4160) uint8, rgb=True, colormap='cyan', contrast_limits=None, gamma=1, interpolation='nearest', rendering='mip', iso_threshold=0.5, attenuation=0.05, name='00001IMG_00001_BURST20180819090638', metadata={'direction':  (2, 2) float64, 'origin':  (2,) float64, 'spacing':  (2,) float64}, scale= (2,) float64, translate= (2,) float64, rotate=None, shear=None, affine=None, opacity=1, blending='additive', visible=True, multiscale=False, cache=True, experimental_slicing_plane=None, experimental_clipping_planes=None)
    240             ndim = len(init_shape)
    241 
--> 242         super().__init__(
        global super.__init__ = undefined
        data =  (3120, 4160) uint8
        ndim = 1
        name = '00001IMG_00001_BURST20180819090638'
        metadata = {'origin':  (2,) float64, 'spacing':  (2,) float64, 'direction':  (2, 2) float64}
        scale =  (2,) float64
        translate =  (2,) float64
        rotate = None
        shear = None
        affine = None
        opacity = 1
        blending = 'additive'
        visible = True
        multiscale = False
        cache = True
        experimental_clipping_planes = None
    243             data,
    244             ndim,

~\miniconda3\envs\test2\lib\site-packages\napari\layers\intensity_mixin.py in __init__(self= instance, *args=( (3120, 4160) uint8, 1), **kwargs={'affine': None, 'blending': 'additive', 'cache': True, 'experimental_clipping_planes': None, 'metadata': {'direction':  (2, 2) float64, 'origin':  (2,) float64, 'spacing':  (2,) float64}, 'multiscale': False, 'name': '00001IMG_00001_BURST20180819090638', 'opacity': 1, 'rotate': None, 'scale':  (2,) float64, ...})
     25 
     26     def __init__(self, *args, **kwargs):
---> 27         super().__init__(*args, **kwargs)
        global super.__init__ = undefined
        args = ( (3120, 4160) uint8, 1)
        kwargs = {'name': '00001IMG_00001_BURST20180819090638', 'metadata': {'origin':  (2,) float64, 'spacing':  (2,) float64, 'direction':  (2, 2) float64}, 'scale':  (2,) float64, 'translate':  (2,) float64, 'rotate': None, 'shear': None, 'affine': None, 'opacity': 1, 'blending': 'additive', 'visible': True, 'multiscale': False, 'cache': True, 'experimental_clipping_planes': None}
     28 
     29         self.events.add(contrast_limits=Event, gamma=Event, colormap=Event)

~\miniconda3\envs\test2\lib\site-packages\napari\layers\base\base.py in __init__(self= instance, data= (3120, 4160) uint8, ndim=1, name='00001IMG_00001_BURST20180819090638', metadata={'direction':  (2, 2) float64, 'origin':  (2,) float64, 'spacing':  (2,) float64}, scale= (2,) float64, translate= (2,) float64, rotate=None, shear=None, affine=None, opacity=1, blending='additive', visible=True, multiscale=False, cache=True, experimental_clipping_planes=None)
    264             [
    265                 Affine(np.ones(ndim), np.zeros(ndim), name='tile2data'),
--> 266                 CompositeAffine(
        global CompositeAffine = 
        scale =  (2,) float64
        translate =  (2,) float64
        rotate = None
        shear = None
        ndim = 1
        name = '00001IMG_00001_BURST20180819090638'
    267                     scale,
    268                     translate,

~\miniconda3\envs\test2\lib\site-packages\napari\utils\transforms\transforms.py in __init__(self=, scale= (2,) float64, translate= (2,) float64, rotate=None, shear=None, ndim=1, name='data2physical')
    597                 scale=scale, translate=translate, rotate=rotate, shear=shear
    598             )
--> 599         self._translate = translate_to_vector(translate, ndim=ndim)
        self._translate =  (2,) float64
        global translate_to_vector = 
        translate =  (2,) float64
        ndim = 1
    600         self._scale = scale_to_vector(scale, ndim=ndim)
    601         self._rotate = rotate_to_matrix(rotate, ndim=ndim)

~\miniconda3\envs\test2\lib\site-packages\napari\utils\transforms\transform_utils.py in translate_to_vector(translate= (2,) float64, ndim=1)
    111     translate_arr = np.zeros(ndim)
    112     if translate is not None:
--> 113         translate_arr[-len(translate) :] = translate
        translate_arr =  (1,) float64
        global len = undefined
        translate =  (2,) float64
    114     return translate_arr
    115 

ValueError: could not broadcast input array from shape (2,) into shape (1,)

Furthermore, my napari info:

napari: 0.4.12
Platform: Windows-10-10.0.19042-SP0
Python: 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:20:16) [MSC v.1916 64 bit (AMD64)]
Qt: 5.15.2
PyQt5: 5.15.5
NumPy: 1.21.3
SciPy: 1.7.1
Dask: 2021.09.1
VisPy: 0.9.2

OpenGL:
- GL version: 4.6.14761 Compatibility Profile Context 21.30.02.01 30.0.13002.1001
- MAX_TEXTURE_SIZE: 16384

Screens:
- screen 1: resolution 1920x1200, scale 1.0

Plugins:
- console: 0.0.4
- napari-itk-io: 0.1.0
- ome-types: 0.2.9
- scikit-image: 0.4.12
- svg: 0.1.5
psobolewskiPhD commented 2 years ago

FYI I'm on macOS 12 (arm64) and jpg drag-n-drop works. Here's the env:

napari: 0.4.12
Platform: macOS-12.0.1-arm64-arm-64bit
System: MacOS 12.0.1
Python: 3.9.6 | packaged by conda-forge | (default, Jul 6 2021, 08:51:19) [Clang 11.1.0 ]
Qt: 5.15.2
PyQt5: 5.15.4
NumPy: 1.21.0
SciPy: 1.7.0
Dask: 2021.06.2
VisPy: 0.9.4

OpenGL:
- GL version: 2.1 Metal - 76.1
- MAX_TEXTURE_SIZE: 16384

Screens:
- screen 1: resolution 1680x1050, scale 2.0

Plugins:
- Measurements (skimage regionprops): 0.1.10
- StarDist: 2021.10.25
- Utilities (skimage regionprops): 0.1.10
- aicsimageio-in-memory: 0.4.1
- aicsimageio-out-of-memory: 0.4.1
- animation: 0.0.2
- clEsperanto: 0.10.7
- console: 0.0.4
- napari-itk-io: 0.1.0
- napari-tools-menu: 0.1.3
- ome-types: 0.2.6
- scikit-image: 0.4.12
- smo: 2.0.0
- svg: 0.1.5
Czaki commented 2 years ago

It will be nice if this plugin properly declares a list of supported extensions in reader in the napari manifest (instead of *). Common users have problems: https://forum.image.sc/t/devbio-napari-cant-open-images/65939

The minimum required improvement is to wrap these lines in try-except to do not throw not clear stactrace: https://github.com/InsightSoftwareConsortium/napari-itk-io/blob/b434d97aac9d1e2a9fedc12c564724ef7baa6e85/src/napari_itk_io/_reader.py#L31-L35