Programatically save the J2 table that is auto-generated from OUTPUT script parameters

fiji
batch-processing
save

#1

when using OUTPUT script parameters, these get conveniently summarized in a IJ2-result table.
I would like to grab this table and save it to disk as e.g. *.csv, but I am not certain how to do so.

I tested different combinations from a related post, but unfortunately did not figure out the proper combination. Here is the last thing I tried, which fails for me with an error “‘NoneType’ object has no attribute ‘get’”.

#@ OUTPUT Integer result1
#@ OUTPUT String result2
#@ IOService io
#@ File (style="save") outFile
#@ DisplayService ds

from net.imagej.table import TableDisplay

result1 = 3
result2 = "circle"
active_display = ds.getActiveDisplay(TableDisplay)
active_table = active_display.get(0).class
io.save(active_table, outFile.getPath())

is this possible and if so, how? Thanks for the help!


#2

You’ll need the scijava-plugins-io-table component, which is currently not included in Fiji but can be downloaded from here:

http://maven.imagej.net/service/local/repositories/releases/content/org/scijava/scijava-plugins-io-table/0.1.0/scijava-plugins-io-table-0.1.0.jar

With this file in your Fiji.app/jars folder, the following should work:

#@ DisplayService ds
#@ IOService io
#@ File (style="save") outFile

activeDisplay = ds.getActiveDisplay()
io.save(activeDisplay, outfile.getPath())

Note however that:

  • you won’t be able to save the table generated from the outputs in the same script where they’re defined, as the creation of the Table is part of the script post-processing.

  • you’re using an outdated TableDisplay class: the package name recently changed from net.imagej.table to org.scijava.table, so you should be looking for org.scijava.table.TableDisplay (I noticed this is also still missing from the SciJava javadoc page).

  • you should save the TableDisplay object directly (I’m not sure what you tried to achieve with the active_display.get(0).class, as this one returns the class instead of the object…).


#3

thanks for the download and code @imagejan.
Together with local support from @ehrenfeu we managed to get it working:

#@ DisplayService ds
#@ IOService io
#@ File (style="save") outFile

active_display = ds.getActiveDisplay()
active_table = active_display.get(0)
io.save(active_table, outFile.getPath())

this works fine for me and writes the table into a .csv as specified when choosing the save location.

It does finish with an error, but writes the file nevertheless! :slight_smile: Thanks again!

[Tue Jan 08 13:54:23 CET 2019] [ERROR] [] null
io.scif.FormatException: No compatible output format found for extension: V:\SolviasAG-Gradientplate\foo2.csv
	at io.scif.services.DefaultFormatService.getWriterByExtension(DefaultFormatService.java:270)
	at io.scif.services.DefaultDatasetIOService.canSave(DefaultDatasetIOService.java:94)
	at io.scif.io.DatasetIOPlugin.supportsSave(DatasetIOPlugin.java:69)
	at org.scijava.io.IOPlugin.supportsSave(IOPlugin.java:76)
	at org.scijava.io.IOService.getSaver(IOService.java:66)
	at org.scijava.io.DefaultIOService.save(DefaultIOService.java:80)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
	at org.python.core.PyObject.__call__(PyObject.java:515)
	at org.python.core.PyObject.__call__(PyObject.java:519)
	at org.python.core.PyMethod.__call__(PyMethod.java:156)
	at org.python.pycode._pyx10.f$0(V:\SolviasAG-Gradientplate\save-ij2-table.py:12)
	at org.python.pycode._pyx10.call_function(V:\SolviasAG-Gradientplate\save-ij2-table.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1614)
	at org.python.core.__builtin__.eval(__builtin__.java:497)
	at org.python.core.__builtin__.eval(__builtin__.java:501)
	at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
	at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)