[ImageJ-devel] [fiji-devel] Re: jython scripting, No compatible service: io.scif.SCIFIOService

Mark Hiner hinerm at gmail.com
Wed Feb 26 09:53:59 CST 2014


Hi Harri,

thanks a lot, setting CLASSPATH did the trick, after I removed the
> unnecessary lines. I didn't understand them anyway, I was just parroting
> http://fiji.sc/ImgLib2_Examples.
>

The SCIFIOConfig<https://github.com/scifio/scifio/blob/master/scifio/src/main/java/io/scif/config/SCIFIOConfig.java>class
allows control over various aspects of the I/O behavior. In the
example you were copying, it was encouraging images to be opened using the
SCIFIOCell class, which allows for dynamic caching of planes, which is
useful if your dataset won't fit in memory. It's basically a writeable
virtual image. SCIFIO uses a heuristic to check image size vs. available
memory though, and will automatically select CELL mode if the image won't
reasonably be expected to fit.

Anyway, I did a little more experimentation and realized two things:
1) apparently you need to import the fully qualified nested enum path
2) jython seems to not support Java varargs, and always converts them to
array arguments

This is the script that is working for me right now:

import sys

from io.scif.config import SCIFIOConfig
import io.scif.config.SCIFIOConfig.ImgMode
from io.scif.img import ImgIOException,ImgOpener

from java.io import File

from net.imglib2.img import Img
from net.imglib2.img.display.imagej import ImageJFunctions
from net.imglib2.type import NativeType
from net.imglib2.type.numeric import RealType

filename = sys.argv[1]

mode = [io.scif.config.SCIFIOConfig.ImgMode.CELL]
opener = ImgOpener()
config = SCIFIOConfig()
config.imgOpenerSetImgModes( mode )
img = opener.openImg( filename, config )

ImageJFunctions.show( img )

But if you don't want to use the config, like I said, it is not required
unless you find the default behavior to be insufficient. Just wanted to
share my discoveries :)

Now it sort of works, but I still don't see the image. I get an icon with
> the Java guy on the launcher bar, with the image name and "(V) (3.1%)". If
> I click that, all other windows disappear and there a small stick-like
> artefact on the top of the screen, but nothing more.
>

A good litmus test here would be to open your Fiji installation that you're
harvesting your dependencies from, run Help > Switch to Modern Mode, and
try using File > Open on your dataset. That should go through the same/very
similar SCIFIO API you're testing in your jython script.

I mentioned that proprietary formats aren't currently supported by SCIFIO
because of outdated jars in Fiji, but additionally the OME-TIFF support is
probably similarly outdated (since it's not core SCIFIO). The TIFF reader
should still be capable of rendering an ome.tiff correctly, but it's
entirely possible you're running into a bug here.

If the dataset looks OK in Fiji's modern mode, then we at least know
there's something else going on at the jython level. If it looks the same
as when running your script, we know it's just an outdated dependency issue.

Also, feel free to upload your dataset <http://fiji.sc/Upload_Sample_Image>.
I can then take a closer look at what's going on, and see if I can
reproduce the display error you saw.

- Mark


On Wed, Feb 26, 2014 at 9:19 AM, Harri Jäälinoja <
harri.jaalinoja at helsinki.fi> wrote:

>  Hi Mark,
>
> thanks a lot, setting CLASSPATH did the trick, after I removed the
> unnecessary lines. I didn't understand them anyway, I was just parroting
> http://fiji.sc/ImgLib2_Examples.
>
> Now it sort of works, but I still don't see the image. I get an icon with
> the Java guy on the launcher bar, with the image name and "(V) (3.1%)". If
> I click that, all other windows disappear and there a small stick-like
> artefact on the top of the screen, but nothing more.
>
> Good progress anyway, more tomorrow.
>
> Harri
>
>
> On 26/02/14 16:41, Mark Hiner wrote:
>
>  Hi Harri,
>
> java.lang.
>> IllegalArgumentException: java.lang.IllegalArgumentException: No
>> compatible service: io.scif.SCIFIOService
>>  hajaalin at biotek973:~/Software/
>> mvn-IJ2$ jar tvf target/dependency/scifio-0.9.2.jar |grep SCIFIOService
>>    150 Fri Feb 14 16:24:24 EET 2014 io/scif/SCIFIOService.class
>>
>
>  So this exception may be slightly misleading. SCIFIOService is a marker
> interface for all the services that are part of SCIFIO. When an
> org.scijava.Context is initialized as it is here, it's typically given a
> set of base service interfaces and then loads all implementations of that
> service. So it seems like the Context knows about the SCIFIOService
> interface, but didn't discover any implementations (things like
> DefaultFormatService, DefaultImgUtilityService).
>
>  So this brings me to my next point: I think there is either a) a bug in
> jython where annotations are not preserved or b) a bug with the class
> loading logic used by Fiji/IJ2. I am leaning towards a) right now.
>
>   I am using an Ubuntu 12.04 64-bit VM. I installed Jython 2.5.3, but I
> suspect you can get this working with 2.5.1.
>
>   Anyway, I went back to OSX and tested jython with the -Dpython.path
> option, and got the same missing service exception. But! If I set
> $CLASSPATH (java automatically picks up the $CLASSPATH environment
> variable) and run the equivalent of:
>
>  jython macros/imglib0.py /home/hajaalin/Data/Misha/composite1.ome.tif
>
>  it works! Thus I believe that python.path has a bug and although jython
> supports discovery of classes on python.path, it does not preserve their
> annotations (or some similar metadata is being lost).
>
>  So instead of setting CP and passing it via -Dpython.path, just use:
>
>  export CLASSPATH=`find
> /home/hajaalin/Software/fiji-20140219/Fiji.app/jars -name '*.jar' |sed
> ':a;N;$!ba;s/\n/:/g'`
>
>  A simple rule of thumb is, try running a random SCIFIO class like "java
> io.scif.SCIFIOService" from the command line. If you get a NoClassDef
> error, your CLASSPATH is not configured correctly. If you get a
> "NoSuchMethodError: main", your CLASSPATH is correct and your jython will
> pick up all the desired classes.
>
>  Moving on...
>
> jython macros/imglib0.py /home/hajaalin/Data/Misha/composite1.ome.tif
>
>  ^ That then works a bit better with my CLASSPATH set, except I get a
> different runtime error about how ImgMode.CELL can't be coerced to ImgMode.
> (same error I get when running using Fiji).
>
>  I notice that you aren't actually using the SCIFIOConfig you construct,
> so if you delete those lines and I'm finally able to open an image. The
> SCIFIOConfig isn't strictly necessary either - SCIFIO will open it as a
> CellImg automatically if it needs to. I will try to investigate further as
> to how to get the types working for a nested enum in jython..
>
>  You may see yet another error message about io.scif.bf.BioFormatsFormat
> failing. This is because some jars in Fiji are out of date, but that
> shouldn't cause catastrophic failure (it just means that some proprietary
> formats won't be supported right now). These jars should be updated this
> week.
>
>  I hope this helps. Let me know if you can't get this working on your end.
>
>  - Mark
>
>
>
> --
> __________________________________________________
> Harri Jäälinoja
> Light Microscopy Unit
> Institute of Biotechnology, University of Helsinkihttp://www.biocenter.helsinki.fi/bi/lmu/+358 9 191 59370 fax +358 9 191 59366
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://imagej.net/pipermail/imagej-devel/attachments/20140226/16b5372b/attachment-0001.html>


More information about the ImageJ-devel mailing list