Parameter value persistance causes error with napari layers as parameter types
See original GitHub issueDescribe the bug
Using @magicgui(persist=True) works fine in a plugin, except the case when I have something like image: napari.layers.Image as an input parameter, e.g. here.
If I change the parameters, then re-start napari, the plugin doesn’t start and I get an error.
To Reproduce Steps to reproduce the behavior:
napari
Load plugin, change a parameter & close napari
NAPARI_CATCH_ERRORS=0 napari
Try to load plugin
(napari-cellfinder) adam@garfield:~/projects/cellfinder-napari$ NAPARI_CATCH_ERRORS=0 napari
09:58:45 WARNING Could not import pyopencl. Falling back to scipy for CPU affine transforms
09:58:47 ERROR Unhandled exception:
Traceback (most recent call last):
File "/home/adam/miniconda3/envs/napari-cellfinder/lib/python3.8/site-packages/napari/_qt/qt_main_window.py", line 450, in _add_widget
self._add_plugin_dock_widget(key)
File "/home/adam/miniconda3/envs/napari-cellfinder/lib/python3.8/site-packages/napari/_qt/qt_main_window.py", line 568, in _add_plugin_dock_widget
wdg = Widget(**kwargs)
File "/home/adam/miniconda3/envs/napari-cellfinder/lib/python3.8/site-packages/magicgui/_magicgui.py", line 200, in __call__
widget = self.func(param_options=prm_options, **{**self.keywords, **kwargs})
File "/home/adam/miniconda3/envs/napari-cellfinder/lib/python3.8/site-packages/magicgui/widgets/_function_gui.py", line 199, in __init__
self._load(quiet=True)
File "/home/adam/miniconda3/envs/napari-cellfinder/lib/python3.8/site-packages/magicgui/widgets/_function_gui.py", line 379, in _load
super()._load(path or self._dump_path, quiet=quiet)
File "/home/adam/miniconda3/envs/napari-cellfinder/lib/python3.8/site-packages/magicgui/widgets/_bases/container_widget.py", line 300, in _load
getattr(self, key).value = val
File "/home/adam/miniconda3/envs/napari-cellfinder/lib/python3.8/site-packages/magicgui/widgets/_bases/categorical_widget.py", line 38, in value
raise ValueError(
ValueError: None is not a valid choice. must be in ()
This error doesn’t occur if I:
- delete the cache file before re-starting napari
- Don’t have a napari layer as parameter type in my decorated function
Expected behavior All the parameters to be reloaded whether or not one of the inputs is a napari layer
Environment (please complete the following information):
- OS: Ubuntu 18.04
- backend: PySide2
- magicgui version: 0.2.7
P.S. the parameter persistence is really helpful for my plugin, thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
the "order" layer-creation parameter is not parsed as expected
Bug napari.view_image does not parse the order parameter how I expecte. order=(2,1,0) will return a viewer where viewer.dims.order is (0,2 ...
Read more >Source code for napari.components.viewer_model
Parameters ---------- event : :class:`napari.layers.Layer` Layer to add. """ layer = event.value # Connect individual layer events to viewer events # TODO: ...
Read more >Using layer properties to pass variables - Image.sc Forum
I'm trying to have power-user functionality in my napari feature classifier plugin by allowing users to pass parameters for the plugin ...
Read more >Aerosol and physical atmosphere model parameters are both ...
The common causes of uncertainty mean that constraining the modelled planetary brightness to tightly match satellite observations changes the lower 95 % ...
Read more >image layer tutorial - napari
Currently if you pass contrast limits as a keyword argument to a layer then full extent of the contrast limits range slider will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

There is a debounce applied to the save-to-disk function so it only runs no more than 4 times a second. So if changes are applied in rapid succession, it’s possible that the last changes will be missed. This was to prevent something like a slider causing a ton of disk events… I’ll try to add logic to make sure that the last event is always registered.
I ran into the same issue, but it ended with:
AttributeError: Can't pickle local object 'configure_dask.<locals>.dask_optimized_slicing'