Open rjlopez2 opened 1 year ago
If you are working from another (presumably python) program, I would recommend using this code as a python module rather than a writer plugin as demonstrated in the tests/test_import.ipynb notebook. I did some preliminary testing of the writer hook functionality but didn't test it exhaustively. Note that the only reason to use this plugin is to export rois to ImageJ for downstream work. If your aim is to provide a storage mechanism for rois, text (e.g. csv) file export is more reliable and easier to troubleshoot.
thanks for the reply I see... yea that was also my idea to implement it as a second alternative to export ROIs in imageJ format. I will then use it as a imported module as you have suggested. thanks for the support. Cheers.
Hey thanks a lot for your nice plugin.
I may have missed in the documentation, but what is the way to normally use your plugin for saving a given shape layer as rois in .roi/.zip format? I am trying to use
napari_jroitools
as part of another plugin to read and write ROIs. Reading ROIs doesn't seems to be a problem. However, I found a problem when using the writer hook implementation or may be I am just missing or doing something wrong?The way I trigger the error was trying to save a shape layer conatining ROIs as followed:
viewer.layers.save(filename, plugin='napari_jroiwriter')
Here is the full error message:
StopIteration Traceback (most recent call last) File ~/miniconda3/envs/omass_env_test_user_implementation/lib/python3.9/site-packages/napari_plugin_engine/hooks.py:201, in HookCaller.get_plugin_implementation(self=, plugin_name='napari_jroiwriter')
200 try:
--> 201 return next(
self =
plugin_name = 'napari_jroiwriter'
202 imp
203 for imp in self.get_hookimpls()
204 if imp.plugin_name == plugin_name
205 )
206 except StopIteration:
StopIteration:
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last) File ~/p_experimental/image_analysis/napari_play/napari-omaas/src/napari_omaas/_widget.py:68, in ExampleQWidget._on_click_save_ROIs_btn(self=, event=False, filename='/Users/rubencito/Desktop/hbljhblhk.zip')
66 def _on_click_save_ROIsbtn(self, event=None, filename=None):
67 if filename is None: filename, = QFileDialog.getSaveFileName(self, "Save as .zip or .roi", ".", "ImageJ ROIS(.roi .zip)")
---> 68 self.viewer.layers.save(filename, plugin='napari_jroiwriter')
filename = '/Users/rubencito/Desktop/hbljhblhk.zip'
self = <napari_omaas._widget.ExampleQWidget object at 0x1c2853f70>
self.viewer = Viewer(axes=Axes(visible=False, labels=True, colored=True, dashed=False, arrows=True), camera=Camera(center=(0.0, 159.5, 899.5), zoom=0.47447222222222224, angles=(0.0, 0.0, 90.0), perspective=0.0, interactive=False), cursor=Cursor(position=(150.0, 277.52586421430385, 1813.1467318600012), scaled=True, size=1, style=<CursorStyle.CROSS: 'cross'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 300.0, 1.0), (0.0, 320.0, 1.0), (0.0, 1800.0, 1.0)), current_step=(150, 160, 900), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer '10h-16m-16s' at 0x1c2867af0>, <Shapes layer 'Shapes' at 0x1c2867730>], scale_bar=ScaleBar(visible=False, colored=False, ticks=True, position=<Position.BOTTOM_RIGHT: 'bottom_right'>, font_size=10, unit=None), text_overlay=TextOverlay(visible=False, color=(0.5, 0.5, 0.5, 1.0), font_size=10, position=<TextOverlayPosition.TOP_LEFT: 'top_left'>, text=''), overlays=Overlays(interaction_box=InteractionBox(points=None, show=False, show_handle=False, show_vertices=False, selection_box_drag=None, selection_box_final=None, transform_start=<napari.utils.transforms.transforms.Affine object at 0x1a680f5e0>, transform_drag=<napari.utils.transforms.transforms.Affine object at 0x1a680f640>, transform_final=<napari.utils.transforms.transforms.Affine object at 0x1a680f6a0>, transform=<napari.utils.transforms.transforms.Affine object at 0x1c990f190>, allow_new_selection=True, selected_vertex=None)), help='hold to pan/zoom', status='Shapes [ 150 278 1813]: [, ]', tooltip=Tooltip(visible=True, text=''), theme='system', title='napari', mouse_move_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events..mouse_move at 0x1bdf27a60>], mouse_drag_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events..mouse_drag at 0x1bdf27790>], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x1a1fbb1f0>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Shift': <function InteractionBoxMouseBindings.initialize_key_events..hold_to_lock_aspect_ratio at 0x1bdf275e0>, 'Control-Shift-R': <function InteractionBoxMouseBindings._reset_active_layer_affine at 0x1bde9d670>, 'Control-Shift-A': <function InteractionBoxMouseBindings._transform_active_layer at 0x1bde9db80>})
File ~/miniconda3/envs/omass_env_test_user_implementation/lib/python3.9/site-packages/napari/components/layerlist.py:448, in LayerList.save(self=[<Image layer '10h-16m-16s' at 0x1c2867af0>, <Shapes layer 'Shapes' at 0x1c2867730>], path='/Users/rubencito/Desktop/hbljhblhk.zip', selected=False, plugin='napari_jroiwriter', _writer=None) 445 warnings.warn(msg) 446 return [] --> 448 return save_layers(path, layers, plugin=plugin, _writer=_writer) layers = [<Image layer '10h-16m-16s' at 0x1c2867af0>, <Shapes layer 'Shapes' at 0x1c2867730>] path = '/Users/rubencito/Desktop/hbljhblhk.zip' plugin = 'napari_jroiwriter' _writer = None
File ~/miniconda3/envs/omass_env_test_user_implementation/lib/python3.9/site-packages/napari/plugins/io.py:204, in save_layers(path='/Users/rubencito/Desktop/hbljhblhk.zip', layers=[<Image layer '10h-16m-16s'>, <Shapes layer 'Shapes'>], plugin='napari_jroiwriter', _writer=None) 156 """Write list of layers or individual layer to a path using writer plugins. 157 158 If
plugin
is not provided and only one layer is passed, then we (...) 201 File paths of any files that were written. 202 """ 203 if len(layers) > 1: --> 204 written = _write_multiple_layers_with_plugins( layers = [<Image layer '10h-16m-16s' at 0x1c2867af0>, <Shapes layer 'Shapes' at 0x1c2867730>] path = '/Users/rubencito/Desktop/hbljhblhk.zip' plugin = 'napari_jroiwriter' _writer = None 205 path, layers, plugin_name=plugin, _writer=_writer 206 ) 207 elif len(layers) == 1: 208 _written = _write_single_layer_with_plugins( 209 path, layers[0], plugin_name=plugin, _writer=_writer 210 )File ~/miniconda3/envs/omass_env_test_user_implementation/lib/python3.9/site-packages/napari/plugins/io.py:324, in _write_multiple_layers_with_plugins(path='/Users/rubencito/Desktop/hbljhblhk.zip', layers=[<Image layer '10h-16m-16s'>, <Shapes layer 'Shapes'>], plugin_name='napari_jroiwriter', _writer=None) 315 names = {i.plugin_name for i in hook_caller.gethookimpls()} 316 raise ValueError( 317 trans.( 318 "There is no registered plugin named '{plugin_name}'.\nNames of plugins offering writers are: {names}", (...) 322 ) 323 ) --> 324 implementation = hook_caller.get_plugin_implementation(plugin_name) hook_caller =
plugin_name = 'napari_jroiwriter'
325 writer_function = hook_caller(
326 _plugin=plugin_name, path=path, layer_types=layer_types
327 )
328 else:
File ~/miniconda3/envs/omass_env_test_user_implementation/lib/python3.9/site-packages/napari_plugin_engine/hooks.py:207, in HookCaller.get_plugin_implementation(self=, plugin_name='napari_jroiwriter')
201 return next(
202 imp
203 for imp in self.get_hookimpls()
204 if imp.plugin_name == plugin_name
205 )
206 except StopIteration:
--> 207 raise KeyError(
self.name = 'napari_get_writer'
self =
plugin_name = 'napari_jroiwriter'
208 f"No implementation of {self.name!r} found "
209 f"for plugin {plugin_name!r}."
210 )
KeyError: "No implementation of 'napari_get_writer' found for plugin 'napari_jroiwriter'."
could you please provide some support here?
thanks in advance.
Ruben