guiwitz / napari-sediment

https://guiwitz.github.io/napari-sediment/napari_sediment.html
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Problem reading sediment generated zarr files #56

Open aloboa opened 5 months ago

aloboa commented 5 months ago

I have tried to display (drag and drop) zarr files:

from a saved project but always get: KeyError: 'metadata' Traceback:

---------------------------------------------------------------------------
MultipleReaderError                       Traceback (most recent call last)
~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/_qt/qt_viewer.py in _qt_open(self=<napari._qt.qt_viewer.QtViewer object>, filenames=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], stack=False, choose_plugin=False, plugin=None, layer_type=None, **kwargs={})
    965         try:
--> 966             self.viewer.open(
        self.viewer.open = <bound method ViewerModel.open of Viewer(camera=Camera(center=(0.0, 255.5, 255.5), zoom=1.595703125, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(101.0, 543.14749082007336, 501.78641370869042), scaled=True, size=1, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 204.0, 1.0), (0.0, 512.0, 1.0), (0.0, 512.0, 1.0)), current_step=(101, 255, 255), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'corrected' at 0x7caf2852aaf0>], help='use <2> for transform', status={'layer_base': 'corrected.zarr', 'source_type': 'plugin', 'plugin': 'napari Sediment', 'coordinates': ' [101 543 502]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[<bound method SedimentWidget._shift_move_callback of <napari_sediment.sediment_widget.SedimentWidget object at 0x7caf38374a60>>], mouse_drag_callbacks=[], mouse_double_click_callbacks=[<bound method SedimentWidget._add_analysis_roi of <napari_sediment.sediment_widget.SedimentWidget object at 0x7caf38374a60>>], mouse_wheel_callbacks=[<function dims_scroll at 0x7caf6e9a9430>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'A': <bound method ConvPaintWidget.hide_annotation of <napari_sediment.classifier.ConvPaintSpectralWidget object at 0x7caf38230b80>>, 'R': <bound method ConvPaintWidget.hide_prediction of <napari_sediment.classifier.ConvPaintSpectralWidget object at 0x7caf38230b80>>})>
        filenames = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        stack = False
        plugin = None
        layer_type = None
        kwargs = {}
    967                 filenames,

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/components/viewer_model.py in open(self=Viewer(camera=Camera(center=(0.0, 255.5, 255.5),...vPaintSpectralWidget object at 0x7caf38230b80>>}), path=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], stack=False, plugin=None, layer_type=None, **kwargs={})
   1104                 else:
-> 1105                     layers = self._open_or_raise_error(
        layers = undefined
        self._open_or_raise_error = <bound method ViewerModel._open_or_raise_error of Viewer(camera=Camera(center=(0.0, 255.5, 255.5), zoom=1.595703125, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(101.0, 543.14749082007336, 501.78641370869042), scaled=True, size=1, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 204.0, 1.0), (0.0, 512.0, 1.0), (0.0, 512.0, 1.0)), current_step=(101, 255, 255), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'corrected' at 0x7caf2852aaf0>], help='use <2> for transform', status={'layer_base': 'corrected.zarr', 'source_type': 'plugin', 'plugin': 'napari Sediment', 'coordinates': ' [101 543 502]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[<bound method SedimentWidget._shift_move_callback of <napari_sediment.sediment_widget.SedimentWidget object at 0x7caf38374a60>>], mouse_drag_callbacks=[], mouse_double_click_callbacks=[<bound method SedimentWidget._add_analysis_roi of <napari_sediment.sediment_widget.SedimentWidget object at 0x7caf38374a60>>], mouse_wheel_callbacks=[<function dims_scroll at 0x7caf6e9a9430>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'A': <bound method ConvPaintWidget.hide_annotation of <napari_sediment.classifier.ConvPaintSpectralWidget object at 0x7caf38230b80>>, 'R': <bound method ConvPaintWidget.hide_prediction of <napari_sediment.classifier.ConvPaintSpectralWidget object at 0x7caf38230b80>>})>
        _path = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        kwargs = {}
        layer_type = None
        _stack = False
   1106                         _path, kwargs, layer_type, _stack

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/components/viewer_model.py in _open_or_raise_error(self=Viewer(camera=Camera(center=(0.0, 255.5, 255.5),...vPaintSpectralWidget object at 0x7caf38230b80>>}), paths=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], kwargs={}, layer_type=None, stack=False)
   1224         else:
-> 1225             raise MultipleReaderError(
        global MultipleReaderError = <class 'napari.errors.reader_errors.MultipleReaderError'>
        global trans._ = <bound method TranslationBundle._ of <napari.utils.translations.TranslationBundle object at 0x7cafce6a5100>>
        path_message = '/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'
        global plugins = undefined
        readers = {'napari-sediment': 'napari Sediment', 'napari': 'napari builtins'}
        global deferred = undefined
        global list = undefined
        readers.keys = <built-in method keys of dict object at 0x7caf64de8300>
        paths = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
   1226                 trans._(

MultipleReaderError: Multiple plugins found capable of reading /media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr. Select plugin from {'napari-sediment': 'napari Sediment', 'napari': 'napari builtins'} and pass to reading function e.g. `viewer.open(..., plugin=...)`.

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/_qt/qt_viewer.py in dropEvent(self=<napari._qt.qt_viewer.QtViewer object>, event=<PyQt5.QtGui.QDropEvent object>)
   1329                 filenames.append(url.toString())
   1330 
-> 1331         self._qt_open(
        self._qt_open = <bound method QtViewer._qt_open of <napari._qt.qt_viewer.QtViewer object at 0x7caf675a5c10>>
        filenames = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        global stack = undefined
        global bool = undefined
        shift_down = <PyQt5.QtCore.Qt.KeyboardModifiers object at 0x7caf285220b0>
        global choose_plugin = undefined
        alt_down = <PyQt5.QtCore.Qt.KeyboardModifiers object at 0x7caf28522660>
   1332             filenames,
   1333             stack=bool(shift_down),

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/_qt/qt_viewer.py in _qt_open(self=<napari._qt.qt_viewer.QtViewer object>, filenames=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], stack=False, choose_plugin=False, plugin=None, layer_type=None, **kwargs={})
    982             )
    983         except MultipleReaderError:
--> 984             handle_gui_reading(filenames, self, stack, **kwargs)
        global handle_gui_reading = <function handle_gui_reading at 0x7caf6d8afd30>
        filenames = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        self = <napari._qt.qt_viewer.QtViewer object at 0x7caf675a5c10>
        stack = False
        kwargs = {}
    985 
    986     def _toggle_chunk_outlines(self):

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/_qt/dialogs/qt_reader_dialog.py in handle_gui_reading(paths=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], qt_viewer=<napari._qt.qt_viewer.QtViewer object>, stack=False, plugin_name=None, error=None, plugin_override=False, **kwargs={})
    199     display_name, persist = readerDialog.get_user_choices()
    200     if display_name:
--> 201         open_with_dialog_choices(
        global open_with_dialog_choices = <function open_with_dialog_choices at 0x7caf6d8e0310>
        display_name = 'napari Sediment'
        persist = False
        readerDialog._extension = '/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'
        readers = {'napari-sediment': 'napari Sediment', 'napari': 'napari builtins'}
        paths = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        stack = False
        qt_viewer = <napari._qt.qt_viewer.QtViewer object at 0x7caf675a5c10>
        kwargs = {}
    202             display_name,
    203             persist,

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/_qt/dialogs/qt_reader_dialog.py in open_with_dialog_choices(display_name='napari Sediment', persist=False, extension='/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr', readers={'napari': 'napari builtins', 'napari-sediment': 'napari Sediment'}, paths=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], stack=False, qt_viewer=<napari._qt.qt_viewer.QtViewer object>, **kwargs={})
    292     ][0]
    293     # may throw error, but we let it this time
--> 294     qt_viewer.viewer.open(paths, stack=stack, plugin=plugin_name, **kwargs)
        qt_viewer.viewer.open = <bound method ViewerModel.open of Viewer(camera=Camera(center=(0.0, 255.5, 255.5), zoom=1.595703125, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(101.0, 543.14749082007336, 501.78641370869042), scaled=True, size=1, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 204.0, 1.0), (0.0, 512.0, 1.0), (0.0, 512.0, 1.0)), current_step=(101, 255, 255), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'corrected' at 0x7caf2852aaf0>], help='use <2> for transform', status={'layer_base': 'corrected.zarr', 'source_type': 'plugin', 'plugin': 'napari Sediment', 'coordinates': ' [101 543 502]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[<bound method SedimentWidget._shift_move_callback of <napari_sediment.sediment_widget.SedimentWidget object at 0x7caf38374a60>>], mouse_drag_callbacks=[], mouse_double_click_callbacks=[<bound method SedimentWidget._add_analysis_roi of <napari_sediment.sediment_widget.SedimentWidget object at 0x7caf38374a60>>], mouse_wheel_callbacks=[<function dims_scroll at 0x7caf6e9a9430>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'A': <bound method ConvPaintWidget.hide_annotation of <napari_sediment.classifier.ConvPaintSpectralWidget object at 0x7caf38230b80>>, 'R': <bound method ConvPaintWidget.hide_prediction of <napari_sediment.classifier.ConvPaintSpectralWidget object at 0x7caf38230b80>>})>
        paths = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        stack = False
        global plugin = undefined
        plugin_name = 'napari-sediment'
        kwargs = {}
    295 
    296     if persist:

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/components/viewer_model.py in open(self=Viewer(camera=Camera(center=(0.0, 255.5, 255.5),...vPaintSpectralWidget object at 0x7caf38230b80>>}), path=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], stack=False, plugin='napari-sediment', layer_type=None, **kwargs={})
   1093                 if plugin:
   1094                     added.extend(
-> 1095                         self._add_layers_with_plugins(
        self._add_layers_with_plugins = <bound method ViewerModel._add_layers_with_plugins of Viewer(camera=Camera(center=(0.0, 255.5, 255.5), zoom=1.595703125, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(101.0, 543.14749082007336, 501.78641370869042), scaled=True, size=1, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 204.0, 1.0), (0.0, 512.0, 1.0), (0.0, 512.0, 1.0)), current_step=(101, 255, 255), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'corrected' at 0x7caf2852aaf0>], help='use <2> for transform', status={'layer_base': 'corrected.zarr', 'source_type': 'plugin', 'plugin': 'napari Sediment', 'coordinates': ' [101 543 502]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[<bound method SedimentWidget._shift_move_callback of <napari_sediment.sediment_widget.SedimentWidget object at 0x7caf38374a60>>], mouse_drag_callbacks=[], mouse_double_click_callbacks=[<bound method SedimentWidget._add_analysis_roi of <napari_sediment.sediment_widget.SedimentWidget object at 0x7caf38374a60>>], mouse_wheel_callbacks=[<function dims_scroll at 0x7caf6e9a9430>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'A': <bound method ConvPaintWidget.hide_annotation of <napari_sediment.classifier.ConvPaintSpectralWidget object at 0x7caf38230b80>>, 'R': <bound method ConvPaintWidget.hide_prediction of <napari_sediment.classifier.ConvPaintSpectralWidget object at 0x7caf38230b80>>})>
        _path = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        kwargs = {}
        plugin = 'napari-sediment'
        layer_type = None
        stack = False
        _stack = False
   1096                             _path,
   1097                             kwargs=kwargs,

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/components/viewer_model.py in _add_layers_with_plugins(self=Viewer(camera=Camera(center=(0.0, 255.5, 255.5),...vPaintSpectralWidget object at 0x7caf38230b80>>}), paths=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], stack=False, kwargs={}, plugin='napari-sediment', layer_type=None)
   1293         else:
   1294             assert len(paths) == 1
-> 1295             layer_data, hookimpl = read_data_with_plugins(
        layer_data = undefined
        hookimpl = undefined
        read_data_with_plugins = <function read_data_with_plugins at 0x7caf449ad4c0>
        paths = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        plugin = 'napari-sediment'
        stack = False
   1296                 paths, plugin=plugin, stack=stack
   1297             )

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/plugins/io.py in read_data_with_plugins(paths=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], plugin='napari-sediment', stack=False)
     75     hookimpl: Optional[HookImplementation]
     76 
---> 77     res = _npe2.read(paths, plugin, stack=stack)
        res = undefined
        global _npe2.read = <function read at 0x7caf6e9709d0>
        paths = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        plugin = 'napari-sediment'
        stack = False
     78     if res is not None:
     79         _ld, hookimpl = res

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari/plugins/_npe2.py in read(paths=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], plugin='napari-sediment', stack=False)
     61         npe1_path = paths[0]
     62     try:
---> 63         layer_data, reader = io_utils.read_get_reader(
        layer_data = undefined
        reader = undefined
        global io_utils.read_get_reader = <function read_get_reader at 0x7caf75ef58b0>
        npe1_path = '/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'
        plugin_name = 'napari-sediment'
        plugin = 'napari-sediment'
     64             npe1_path, plugin_name=plugin
     65         )

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/npe2/io_utils.py in read_get_reader(path='/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr', plugin_name='napari-sediment', stack=None)
     64         # Napari 0.4.15 and older, hopefully we can drop this and make stack mandatory
     65         new_path, new_stack = v1_to_v2(path)
---> 66         return _read(
        global _read = <function _read at 0x7caf75ef5a60>
        new_path = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        plugin_name = 'napari-sediment'
        global return_reader = undefined
        stack = None
        new_stack = False
     67             new_path, plugin_name=plugin_name, return_reader=True, stack=new_stack
     68         )

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/npe2/io_utils.py in _read(paths=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], stack=False, plugin_name='napari-sediment', return_reader=True, _pm=<npe2._plugin_manager.PluginManager object>)
    170         if read_func is not None:
    171             # if the reader function raises an exception here, we don't try to catch it
--> 172             if layer_data := read_func(paths, stack=stack):
        layer_data = undefined
        read_func = <function reader_function at 0x7caf64e97f70>
        paths = ['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr']
        stack = False
    173                 return (layer_data, rdr) if return_reader else layer_data
    174 

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/npe2/manifest/contributions/_readers.py in npe1_compat(paths=['/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'], stack=False)
     57         def npe1_compat(paths, *, stack):
     58             path = v2_to_v1(paths, stack)
---> 59             return callable_(path)
        global callable_ = undefined
        path = '/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'
     60 
     61         return npe1_compat

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari_sediment/_reader.py in reader_function(path='/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr')
     65     #paths = [path] if isinstance(path, str) else path
     66     # load all files into array
---> 67     array, metadata = read_spectral(path)# for _path in paths]
        array = undefined
        metadata = undefined
        global read_spectral = <function read_spectral at 0x7caf449ade50>
        path = '/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'
     68     # stack arrays into single array
     69     #data = np.squeeze(np.stack(arrays))

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari_sediment/_reader.py in read_spectral(path=PosixPath('/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari/roi_0/pure.zarr'), bands=None, row_bounds=None, col_bounds=None)
    120     elif path.suffix == '.zarr':
    121         zarr_image = read_hyper_zarr(path)
--> 122         metadata = zarr_image.attrs['metadata']
        metadata = undefined
        zarr_image.attrs = <zarr.attrs.Attributes object at 0x7caf650065b0>
    123         if bands is None:
    124             bands = np.arange(zarr_image.shape[0])

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/zarr/attrs.py in __getitem__(self=<zarr.attrs.Attributes object>, item='metadata')
     72 
     73     def __getitem__(self, item):
---> 74         return self.asdict()[item]
        self.asdict = <bound method Attributes.asdict of <zarr.attrs.Attributes object at 0x7caf650065b0>>
        item = 'metadata'
     75 
     76     def _write_op(self, f, *args, **kwargs):

KeyError: 'metadata'