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

ij.op().create() ambiguity with PTService.create() #106

Closed
elevans opened this issue Mar 29, 2021 · 1 comment
Closed

ij.op().create() ambiguity with PTService.create() #106

elevans opened this issue Mar 29, 2021 · 1 comment
Assignees
Milestone

Comments

@elevans
Copy link
Member

elevans commented Mar 29, 2021

When attempting to use/interact with ij.op().create() an overloading error is thrown. There is an ambiguity issue (bug?) where JPype gets confused between PTService.create() and what we want ij.op().create().

>>> import imagej
>>> ij = imagej.init()
>>> ij.op().threshold() # something that works
<java object 'net.imagej.ops.threshold.ThresholdNamespace'>
>>> ij.op().create()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: No matching overloads found for org.scijava.plugin.PTService.create(), options are:
	public default org.scijava.plugin.SciJavaPlugin org.scijava.plugin.PTService.create(java.lang.Class)

For now the workaround is to be explicit and import the create namespace manually.

>>> import imagej
>>> import scyjava as sj
>>> ij = imagej.init()
>>> CreateNamespace = sj.jimport('net.imagej.ops.create.CreateNamespace')
>>> CreateNamespace
<java class 'net.imagej.ops.create.CreateNamespace'>
>>> dir(CreateNamespace)
['__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'context', 'equals', 'getClass', 'getContext', 'getName', 'hashCode', 'img', 'imgFactory', 'imgLabeling', 'imgPlus', 'integerType', 'kernel', 'kernel2ndDerivBiGauss', 'kernelBiGauss', 'kernelDiffraction', 'kernelGabor', 'kernelGaborComplexDouble', 'kernelGaborComplexFloat', 'kernelGaborDouble', 'kernelGaborFloat', 'kernelGauss', 'kernelLog', 'kernelSobel', 'labelingMapping', 'nativeType', 'notify', 'notifyAll', 'object', 'ops', 'setContext', 'setEnvironment', 'setName', 'toString', 'wait']

Here's an example of how code should run (but doesn't because of this ambiguity issue) working with this workaround.

Should work:

psf = ij.op().create().kernelDiffraction(psfSize, numericalAperture, wavelength, riSample, riImmersion, xySpacing, zSpacing, depth, FloatType())

Workaround:

import scyjava as sj

# import the CreateNamespace
CreateNamespace = sj.jimport('net.imagej.ops.create.CreateNamespace')

psf = ij.op().namespace(CreateNamespace).kernelDiffraction(psfSize, numericalAperture, wavelength, riSample, riImmersion, xySpacing, zSpacing, depth, FloatType())

Note instead of using ij.op().create(), use ij.op().namespace() and pass it the CreateNamespace.

@imagejan
Copy link
Member

This looks like jpype-project/jpype#844 again, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants