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

filter.tubeness(img, img, number, double[]) cannot be called #166

Closed
gselzer opened this issue Jan 26, 2023 · 6 comments
Closed

filter.tubeness(img, img, number, double[]) cannot be called #166

gselzer opened this issue Jan 26, 2023 · 6 comments
Assignees
Labels
blocked Waiting for an upstream change bug Something isn't working
Milestone

Comments

@gselzer
Copy link
Collaborator

gselzer commented Jan 26, 2023

The stack trace is as follows, obtained when running the Widget button for that op:

 ([<java object 'net.imagej.DefaultDataset'>, <java object 'net.imagej.DefaultDataset'>, <java object 'java.util.ArrayList'>, <java object 'java.util.ArrayList'>, 1]) -- module:net.imagej.ops.Ops$Filter$Tubeness
[ERROR] Cannot create module: sc.fiji.snt.filter.Tubeness
org.scijava.module.ModuleException: org.scijava.InstantiableException: java.lang.InstantiationException: sc.fiji.snt.filter.Tubeness
	at org.scijava.command.CommandModule.instantiateCommand(CommandModule.java:251)
	at org.scijava.command.CommandModule.<init>(CommandModule.java:98)
	at org.scijava.command.CommandInfo.createModule(CommandInfo.java:326)
	at org.scijava.module.DefaultModuleService.createModule(DefaultModuleService.java:167)
	at net.imagej.ops.DefaultOpMatchingService.createModule(DefaultOpMatchingService.java:562)
	at net.imagej.ops.DefaultOpMatchingService.moduleConforms(DefaultOpMatchingService.java:483)
	at net.imagej.ops.DefaultOpMatchingService.filterMatches(DefaultOpMatchingService.java:293)
	at net.imagej.ops.DefaultOpMatchingService.filterMatches(DefaultOpMatchingService.java:138)
	at net.imagej.ops.DefaultOpMatchingService.findMatch(DefaultOpMatchingService.java:95)
	at net.imagej.ops.DefaultOpMatchingService.findMatch(DefaultOpMatchingService.java:83)
	at net.imagej.ops.OpEnvironment.module(OpEnvironment.java:253)
	at net.imagej.ops.OpEnvironment.run(OpEnvironment.java:136)
	at net.imagej.ops.OpListingModule.run(OpListingModule.java:68)
Caused by: org.scijava.InstantiableException: java.lang.InstantiationException: sc.fiji.snt.filter.Tubeness
	at org.scijava.plugin.PluginInfo.createInstance(PluginInfo.java:309)
	at org.scijava.command.CommandInfo.createInstance(CommandInfo.java:248)
	at org.scijava.command.CommandModule.instantiateCommand(CommandModule.java:248)
	... 12 more
Caused by: java.lang.InstantiationException: sc.fiji.snt.filter.Tubeness
	at java.lang.Class.newInstance(Class.java:427)
	at org.scijava.plugin.PluginInfo.createInstance(PluginInfo.java:304)
	... 14 more
Caused by: java.lang.NoSuchMethodException: sc.fiji.snt.filter.Tubeness.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.newInstance(Class.java:412)
	... 15 more
[java.lang.Enum.toString] [ERROR] Cannot create module: sc.fiji.snt.filter.Tubeness
org.scijava.module.ModuleException: org.scijava.InstantiableException: java.lang.InstantiationException: sc.fiji.snt.filter.Tubeness
	at org.scijava.command.CommandModule.instantiateCommand(CommandModule.java:251)
	at org.scijava.command.CommandModule.<init>(CommandModule.java:98)
	at org.scijava.command.CommandInfo.createModule(CommandInfo.java:326)
	at org.scijava.module.DefaultModuleService.createModule(DefaultModuleService.java:167)
	at net.imagej.ops.DefaultOpMatchingService.createModule(DefaultOpMatchingService.java:562)
	at net.imagej.ops.DefaultOpMatchingService.moduleConforms(DefaultOpMatchingService.java:483)
	at net.imagej.ops.DefaultOpMatchingService.filterMatches(DefaultOpMatchingService.java:293)
	at net.imagej.ops.DefaultOpMatchingService.filterMatches(DefaultOpMatchingService.java:138)
	at net.imagej.ops.DefaultOpMatchingService.findMatch(DefaultOpMatchingService.java:95)
	at net.imagej.ops.DefaultOpMatchingService.findMatch(DefaultOpMatchingService.java:83)
	at net.imagej.ops.OpEnvironment.module(OpEnvironment.java:253)
	at net.imagej.ops.OpEnvironment.run(OpEnvironment.java:136)
	at net.imagej.ops.OpListingModule.run(OpListingModule.java:68)
Caused by: org.scijava.InstantiableException: java.lang.InstantiationException: sc.fiji.snt.filter.Tubeness
	at org.scijava.plugin.PluginInfo.createInstance(PluginInfo.java:309)
	at org.scijava.command.CommandInfo.createInstance(CommandInfo.java:248)
	at org.scijava.command.CommandModule.instantiateCommand(CommandModule.java:248)
	... 12 more
Caused by: java.lang.InstantiationException: sc.fiji.snt.filter.Tubeness
	at java.lang.Class.newInstance(Class.java:427)
	at org.scijava.plugin.PluginInfo.createInstance(PluginInfo.java:304)
	... 14 more
Caused by: java.lang.NoSuchMethodException: sc.fiji.snt.filter.Tubeness.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.newInstance(Class.java:412)
	... 15 more
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
File src/psygnal/_signal.py:927, in psygnal._signal.SignalInstance._run_emit_loop()

File ~/miniconda3/envs/napari-imagej-dev/lib/python3.10/site-packages/magicgui/widgets/_function_gui.py:212, in FunctionGui.__init__.<locals>._disable_button_and_call()
    211 try:
--> 212     self.__call__()
        self = <FunctionGui filter.tubeness(out: napari.layers.image.image.Image = <Image layer 'brick [1]' at 0x7fb541b240d0>, in: napari.layers.image.image.Image = <Image layer 'brick' at 0x7fb541b50eb0>, spacing: List[float] = [2.0, 2.0], scales: List[float] = [2.0, 2.0], numThreads: int = 1) -> List[napari.layers.base.base.Layer]>
    213 finally:

File ~/miniconda3/envs/napari-imagej-dev/lib/python3.10/site-packages/magicgui/widgets/_function_gui.py:324, in FunctionGui.__call__(self=<FunctionGui filter.tubeness(out: napari.layers.... int = 1) -> List[napari.layers.base.base.Layer]>, update_widget=False, *args=(), **kwargs={})
    323 with _function_name_pointing_to_widget(self):
--> 324     value = self._function(*bound.args, **bound.kwargs)
        self = <FunctionGui filter.tubeness(out: napari.layers.image.image.Image = <Image layer 'brick [1]' at 0x7fb541b240d0>, in: napari.layers.image.image.Image = <Image layer 'brick' at 0x7fb541b50eb0>, spacing: List[float] = [2.0, 2.0], scales: List[float] = [2.0, 2.0], numThreads: int = 1) -> List[napari.layers.base.base.Layer]>
        bound = <BoundArguments (out=<Image layer 'brick [1]' at 0x7fb541b240d0>, in=<Image layer 'brick' at 0x7fb541b50eb0>, spacing=[2.0, 2.0], scales=[2.0, 2.0], numThreads=1)>
        self._function = <function filter.tubeness at 0x7fb5419dc160>
    326 self._call_count += 1

File ~/code/imagej/napari-imagej/src/napari_imagej/utilities/_module_utils.py:529, in functionify_module_execution.<locals>.module_execute(*user_resolved_inputs=(<Image layer 'brick [1]'>, <Image layer 'brick'>, [2.0, 2.0], [2.0, 2.0], 1))
    527 except JException as exc:
    528     # chain exc to a Python exception
--> 529     raise Exception(
    530         f"Caught Java Exception\n\n {jstacktrace(exc)}"
    531     ) from None

Exception: Caught Java Exception

 java.lang.NullPointerException
	at net.imagej.ops.DefaultOpMatchingService.createModule(DefaultOpMatchingService.java:568)
	at net.imagej.ops.DefaultOpMatchingService.moduleConforms(DefaultOpMatchingService.java:483)
	at net.imagej.ops.DefaultOpMatchingService.filterMatches(DefaultOpMatchingService.java:293)
	at net.imagej.ops.DefaultOpMatchingService.filterMatches(DefaultOpMatchingService.java:138)
	at net.imagej.ops.DefaultOpMatchingService.findMatch(DefaultOpMatchingService.java:95)
	at net.imagej.ops.DefaultOpMatchingService.findMatch(DefaultOpMatchingService.java:83)
	at net.imagej.ops.OpEnvironment.module(OpEnvironment.java:253)
	at net.imagej.ops.OpEnvironment.run(OpEnvironment.java:136)
	at net.imagej.ops.OpListingModule.run(OpListingModule.java:68)

I'm not quite sure why this is happening, but it may not be able to put in the sigma parameter, because that Number type is getting matched to an integer widget, when the parameter should be a double.

We may want to wait on Fiji 2.10/#159 being merged

@gselzer gselzer added bug Something isn't working blocked Waiting for an upstream change labels Jan 26, 2023
@gselzer gselzer added this to the 0.2.0 milestone Jan 26, 2023
@gselzer gselzer self-assigned this Jan 26, 2023
@ctrueden
Copy link
Member

@gselzer There's something super weird going on there. I do not think you are calling the code you think you are calling. 😬 sc.fiji.snt.filter.Tubeness is not the right package. That's part of SNT. Is this coming in from the deprecated Simple_Neurite_Tracer?

@ctrueden
Copy link
Member

ctrueden commented Jan 27, 2023

It's coming from org.morphonets:SNT. Code here. But that code isn't shipped with Fiji. Are you enabling the Neuroanatomy update site?

@ctrueden
Copy link
Member

Isn't this filter.tubeness the one we should be using?

@gselzer
Copy link
Collaborator Author

gselzer commented Feb 2, 2023

Oh, yeah, I think you're right. I did have neuroanatomy enabled.

But it would still be cool if the SNT Op worked.

Unfortunately, our filter.tubeness Op doesn't work either. There are issues with the double[] parameter that are fixed with #159, but if I hop on that branch I get the following error:

09:50:57 DEBUG napari-imagej: Creating module...
09:50:57 DEBUG napari-imagej: Preprocessing...
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/code/imagej/napari-imagej/src/napari_imagej/widgets/result_runner.py:155, in ResultRunner._run_actions_for.<locals>.<lambda>()
    150         self.viewer.window.add_dock_widget(widget)
    151         widget[0].native.setFocus()
    153 buttons = [
    154     ActionButton(name="Run", func=lambda: execute_result(modal=True)),
--> 155     ActionButton(name="Widget", func=lambda: execute_result(modal=False)),
        ActionButton = <class 'napari_imagej.widgets.result_runner.ActionButton'>
    156 ]
    158 return buttons

File ~/code/imagej/napari-imagej/src/napari_imagej/widgets/result_runner.py:138, in ResultRunner._run_actions_for.<locals>.execute_result(modal=False)
    135 module = ij().module().createModule(moduleInfo)
    137 # preprocess using napari GUI
--> 138 func, param_options = functionify_module_execution(
        moduleInfo = <java object 'net.imagej.ops.OpListingInfo'>
        module = <java object 'net.imagej.ops.OpListingModule'>
        self.viewer = Viewer(axes=Axes(visible=False, labels=True, colored=True, dashed=False, arrows=True), camera=Camera(center=(0.0, 0.0, 0.0), zoom=1.0, angles=(0.0, 0.0, 90.0), perspective=0.0, interactive=True), cursor=Cursor(position=(1.0, 1.0), scaled=True, size=1, style=<CursorStyle.STANDARD: 'standard'>), 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, color=<class 'numpy.ndarray'> (4,) float32, ticks=True, position=<Position.BOTTOM_RIGHT: 'bottom_right'>, font_size=10.0, box=False, box_color=<class 'numpy.ndarray'> (4,) float32, unit=None), text_overlay=TextOverlay(visible=False, color=<class 'numpy.ndarray'> (4,) float32, font_size=10.0, 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 0x7f647568fed0>, transform_drag=<napari.utils.transforms.transforms.Affine object at 0x7f647568ff10>, transform_final=<napari.utils.transforms.transforms.Affine object at 0x7f647568ff90>, transform=<napari.utils.transforms.transforms.Affine object at 0x7f6475698050>, allow_new_selection=True, selected_vertex=None)), help='', status='', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=False, mouse_move_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_move at 0x7f646c0437e0>], mouse_drag_callbacks=[<function InteractionBoxMouseBindings.initialize_mouse_events.<locals>.mouse_drag at 0x7f646c043920>], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x7f64787e2d40>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={'Shift': <function InteractionBoxMouseBindings.initialize_key_events.<locals>.hold_to_lock_aspect_ratio at 0x7f646c042980>, 'Control-Shift-R': <function InteractionBoxMouseBindings._reset_active_layer_affine at 0x7f646c1d2ca0>, 'Control-Shift-A': <function InteractionBoxMouseBindings._transform_active_layer at 0x7f646c1d2c00>, 'Control-L': <function NapariImageJWidget.__init__.<locals>.<lambda> at 0x7f64275ec180>})
        self = <napari_imagej.widgets.result_runner.ResultRunner object at 0x7f6427ac6f80>
    139     self.viewer, module, moduleInfo
    140 )
    141 if modal:
    142     execute_function_modally(
    143         viewer=self.viewer,
    144         name=name,
    145         func=func,
    146         param_options=param_options,
    147     )

File ~/code/imagej/napari-imagej/src/napari_imagej/utilities/_module_utils.py:534, in functionify_module_execution(viewer=Viewer(axes=Axes(visible=False, labels=True, col...t.__init__.<locals>.<lambda> at 0x7f64275ec180>}), module=<java object 'net.imagej.ops.OpListingModule'>, info=<java object 'net.imagej.ops.OpListingInfo'>)
    529         raise Exception(
    530             f"Caught Java Exception\n\n {jstacktrace(exc)}"
    531         ) from None
    533 # Add metadata for widget creation
--> 534 _add_napari_metadata(module_execute, info, unresolved_inputs)
        unresolved_inputs = [<java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>]
        module_execute = <function filter.tubeness at 0x7f63d161f600>
        info = <java object 'net.imagej.ops.OpListingInfo'>
    535 magic_kwargs = _add_scijava_metadata(
    536     unresolved_inputs, module_execute.__annotation__
    537 )
    539 return (module_execute, magic_kwargs)

File ~/code/imagej/napari-imagej/src/napari_imagej/utilities/_module_utils.py:381, in _add_napari_metadata(execute_module=<function filter.tubeness>, info=<java object 'net.imagej.ops.OpListingInfo'>, unresolved_inputs=[<java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>])
    378 execute_module.__qualname__ = module_name
    380 # Rewrite the function signature to match the module inputs.
--> 381 _modify_function_signature(execute_module, unresolved_inputs, info)
        info = <java object 'net.imagej.ops.OpListingInfo'>
        execute_module = <function filter.tubeness at 0x7f63d161f600>
        unresolved_inputs = [<java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>]
    383 # Add the type hints as annotations metadata as well.
    384 # Without this, magicgui doesn't pick up on the types.
    385 type_hints = {str(i.getName()): type_hint_for(i) for i in unresolved_inputs}

File ~/code/imagej/napari-imagej/src/napari_imagej/utilities/_module_utils.py:275, in _modify_function_signature(function=<function filter.tubeness>, inputs=[<java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>], module_info=<java object 'net.imagej.ops.OpListingInfo'>)
    273 # Grab all options after the module inputs
    274 inputs = _sink_optional_inputs(inputs)
--> 275 module_params = [_module_param(i) for i in inputs]
        inputs = [<java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>, <java object 'org.scijava.module.DefaultMutableModuleItem'>]
    276 other_params = [
    277     Parameter(
    278         i[0],
   (...)
    283     for i in _napari_module_param_additions(module_info).items()
    284 ]
    285 all_params = module_params + other_params

File ~/code/imagej/napari-imagej/src/napari_imagej/utilities/_module_utils.py:275, in <listcomp>(.0=<list_iterator object>)
    273 # Grab all options after the module inputs
    274 inputs = _sink_optional_inputs(inputs)
--> 275 module_params = [_module_param(i) for i in inputs]
        i = <java object 'org.scijava.module.DefaultMutableModuleItem'>
    276 other_params = [
    277     Parameter(
    278         i[0],
   (...)
    283     for i in _napari_module_param_additions(module_info).items()
    284 ]
    285 all_params = module_params + other_params

File ~/code/imagej/napari-imagej/src/napari_imagej/utilities/_module_utils.py:262, in _module_param(input=<java object 'org.scijava.module.DefaultMutableModuleItem'>)
    259 default = _param_default_or_none(input)
    260 type_hint = _type_hint_for_module_item(input)
--> 262 return Parameter(name=name, kind=kind, default=default, annotation=type_hint)
        name = 'in'
        kind = <_ParameterKind.POSITIONAL_OR_KEYWORD: 1>
        default = <class 'inspect._empty'>
        type_hint = 'napari.layers.Image'

File ~/mambaforge/envs/napari-imagej-dev/lib/python3.11/inspect.py:2715, in Parameter.__init__(self=<class 'inspect.Parameter'> instance, name='in', kind=<_ParameterKind.POSITIONAL_OR_KEYWORD: 1>, default=<class 'inspect._empty'>, annotation='napari.layers.Image')
   2713 is_keyword = iskeyword(name) and self._kind is not _POSITIONAL_ONLY
   2714 if is_keyword or not name.isidentifier():
-> 2715     raise ValueError('{!r} is not a valid parameter name'.format(name))
        name = 'in'
   2717 self._name = name

ValueError: 'in' is not a valid parameter name

I'm not sure why the parameter name is named in, so maybe this is a new issue? I'll have to dig in.

@gselzer
Copy link
Collaborator Author

gselzer commented Mar 27, 2023

Okay, I just tried running the ImageJ Ops tubeness filter again, and that one works great. Do you think it is worth trying to get SNT's tubeness Op working too, @ctrueden, or should we just close this issue?

@gselzer
Copy link
Collaborator Author

gselzer commented May 31, 2023

The same thing happens in Fiji, so I filed morphonets/SNT#173 - let's fix it at the source!

@gselzer gselzer closed this as completed May 31, 2023
napari-imagej plugin automation moved this from 0.2.0 to Done May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Waiting for an upstream change bug Something isn't working
Development

No branches or pull requests

2 participants