Discussion:
Running Jython scripts from command line
Tristan Chaplin
2012-04-19 04:49:58 UTC
Permalink
Hi,

Apologies if this is more of a ImageJ question.

I'd like to able to run a jython script from the command line. I tried:

./ImageJ-macosx -batch script.py

but I get

Macro Error: Undefined variable in line 1.

<import> os , sys

I found this command at
http://rsbweb.nih.gov/ij/developer/api/ij/ImageJ.html

After a quick check, it seems that it's assuming the script is java or
javascript and not python (if I comment out the that first line with a //
it goes (and fails) to the next line, but if I use a # it still fails on
the first line).

Is calling jython scripts from the command line not supported? Or am I just
doing it wrong?

Thanks,
Tristan
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Tom Kazimiers
2012-04-19 07:56:41 UTC
Permalink
Hi Tristan,
Post by Tristan Chaplin
./ImageJ-macosx -batch script.py
but I get
Macro Error: Undefined variable in line 1.
<import> os , sys
have you tried without the -batch option? I frequently run Jython
scripts in Fiji from the CLI. However, I don't use the -batch option. If
I add it, I get macro errors, too. If leaving out this option doesn't
help, you might give Fiji a try. But I guess it should work with ImageJ
the same.

Looking at the Fiji wiki, it seems to me that -batch is only used in
combination with ImageJ macros. The example in the Wiki shows *not* how
a Ruby script is run, but how to make Macro calls to refresh the Ruby
scripts and to run a certain plugin.
Post by Tristan Chaplin
Is calling jython scripts from the command line not supported? Or am I
just doing it wrong?
Like said above, for me it works without problems.

Cheers,
Tom

[1] http://fiji.sc/wiki/index.php/Scripting_Help
Tristan Chaplin
2012-04-20 00:03:24 UTC
Permalink
Ah thanks Tom. I also realised I've somehome messed up my fiji install, the
reason I used ImageJ-macosx was that fiji-macosx threw errors when I ran
it, so I assumed you couldn't call it directly. I downloaded a fresh copy
of fiji and noticed I had some extra junk in this MacOS/Contents directory,
so I switched to the fresh version and fiji-macosx works now, and I can
call the script with headless.

fiji-macosx --headless script

Thanks!

works. I thought it needed to be
Post by Tom Kazimiers
Hi Tristan,
Post by Tristan Chaplin
./ImageJ-macosx -batch script.py
but I get
Macro Error: Undefined variable in line 1.
<import> os , sys
have you tried without the -batch option? I frequently run Jython
scripts in Fiji from the CLI. However, I don't use the -batch option. If
I add it, I get macro errors, too. If leaving out this option doesn't
help, you might give Fiji a try. But I guess it should work with ImageJ
the same.
Looking at the Fiji wiki, it seems to me that -batch is only used in
combination with ImageJ macros. The example in the Wiki shows *not* how
a Ruby script is run, but how to make Macro calls to refresh the Ruby
scripts and to run a certain plugin.
Post by Tristan Chaplin
Is calling jython scripts from the command line not supported? Or am I
just doing it wrong?
Like said above, for me it works without problems.
Cheers,
Tom
[1] http://fiji.sc/wiki/index.php/Scripting_Help
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Johannes Schindelin
2012-04-20 06:09:40 UTC
Permalink
Hi Tristan,
Post by Tristan Chaplin
Ah thanks Tom. I also realised I've somehome messed up my fiji install, the
reason I used ImageJ-macosx was that fiji-macosx threw errors when I ran
it, so I assumed you couldn't call it directly. I downloaded a fresh copy
of fiji and noticed I had some extra junk in this MacOS/Contents directory,
so I switched to the fresh version and fiji-macosx works now, and I can
call the script with headless.
If your ImageJ-macosx is not identical to fiji-macosx, something is wrong
with your installation.

That might be due to a problem that was reported to me but which I did not
have time yet to address. That problem seems to manifest itself as a
version of ImageJ-macosx Fiji does not recognise as being an official
version (read: something known to the Fiji Updater).

Ciao,
Johannes
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Jan Eglinger
2012-04-20 09:04:09 UTC
Permalink
Hi Tristan and Johannes,
Post by Johannes Schindelin
If your ImageJ-macosx is not identical to fiji-macosx, something is wrong
with your installation.
That might be due to a problem that was reported to me but which I did not
have time yet to address. That problem seems to manifest itself as a
version of ImageJ-macosx Fiji does not recognise as being an official
version (read: something known to the Fiji Updater).
I've observed on a number of systems (running Mac OS Leopard and Snow
Leopard) that after a recent update, some of the launcher executables
(like fiji-macosx and fiji-tiger) are marked as locally modified. Did
you try to update the files via 'Advanced mode', 'View locally modified
plugins only' to make them "known to the Updater" again?

Jan
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Johannes Schindelin
2012-04-20 17:15:54 UTC
Permalink
Hi Jan,
Post by Jan Eglinger
Post by Johannes Schindelin
If your ImageJ-macosx is not identical to fiji-macosx, something is wrong
with your installation.
That might be due to a problem that was reported to me but which I did not
have time yet to address. That problem seems to manifest itself as a
version of ImageJ-macosx Fiji does not recognise as being an official
version (read: something known to the Fiji Updater).
I've observed on a number of systems (running Mac OS Leopard and Snow
Leopard) that after a recent update, some of the launcher executables
(like fiji-macosx and fiji-tiger) are marked as locally modified. Did
you try to update the files via 'Advanced mode', 'View locally modified
plugins only' to make them "known to the Updater" again?
It would be awesome if you could run this little Beanshell script in such
a case and report back the checksums:

import fiji.updater.logic.Checksummer;
import fiji.updater.logic.PluginCollection;
import fiji.updater.logic.PluginObject;

import fiji.updater.util.StderrProgress;

import java.util.Arrays;

dbPath = System.getProperty("ij.dir") + "/db.xml.gz";

plugins = new PluginCollection();
progress = new StderrProgress();
checksummer = new Checksummer(plugins, progress);

checksummer.updateFromLocal(Arrays.asList(new String[] {
"Contents/MacOS/fiji-tiger",
"Contents/MacOS/fiji-macosx"
}));
plugins.sort();
for (PluginObject plugin : plugins)
print(plugin + " " + plugin.current.checksum);

(Just call File>New>Script, select Language>Beanshell, paste the script
and call Run>Run; the output is in the bottom part of the Script Editor.)

Thank you!
Johannes
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Jan Eglinger
2012-04-25 15:12:46 UTC
Permalink
Hi Johannes,
Post by Johannes Schindelin
Hi Jan,
Post by Jan Eglinger
Post by Johannes Schindelin
If your ImageJ-macosx is not identical to fiji-macosx, something is wrong
with your installation.
That might be due to a problem that was reported to me but which I did not
have time yet to address. That problem seems to manifest itself as a
version of ImageJ-macosx Fiji does not recognise as being an official
version (read: something known to the Fiji Updater).
I've observed on a number of systems (running Mac OS Leopard and Snow
Leopard) that after a recent update, some of the launcher executables
(like fiji-macosx and fiji-tiger) are marked as locally modified. Did
you try to update the files via 'Advanced mode', 'View locally modified
plugins only' to make them "known to the Updater" again?
It would be awesome if you could run this little Beanshell script in such
import fiji.updater.logic.Checksummer;
import fiji.updater.logic.PluginCollection;
import fiji.updater.logic.PluginObject;
import fiji.updater.util.StderrProgress;
import java.util.Arrays;
dbPath = System.getProperty("ij.dir") + "/db.xml.gz";
plugins = new PluginCollection();
progress = new StderrProgress();
checksummer = new Checksummer(plugins, progress);
checksummer.updateFromLocal(Arrays.asList(new String[] {
"Contents/MacOS/fiji-tiger",
"Contents/MacOS/fiji-macosx"
}));
plugins.sort();
for (PluginObject plugin : plugins)
print(plugin + " " + plugin.current.checksum);
(Just call File>New>Script, select Language>Beanshell, paste the script
and call Run>Run; the output is in the bottom part of the Script Editor.)
on Mac OS 10.5 (Leopard), I get the following "locally modified" files
and checksums after downloading a new copy of Fiji and running the
updater (everything else updates fine of course):

Contents/MacOS/fiji-macosx de36f7b25af2a38e639336509fefbe5786588dc5
Contents/MacOS/fiji-tiger 38ef1c8dedd2b898820fa05acf11755811ee4952


Best,
Jan
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Johannes Schindelin
2012-04-25 17:10:06 UTC
Permalink
Hi Jan,
Post by Jan Eglinger
on Mac OS 10.5 (Leopard), I get the following "locally modified" files
and checksums after downloading a new copy of Fiji and running the
Contents/MacOS/fiji-macosx de36f7b25af2a38e639336509fefbe5786588dc5
Contents/MacOS/fiji-tiger 38ef1c8dedd2b898820fa05acf11755811ee4952
Thanks. I hard-coded those versions as known previous versions.

Thank you!
Dscho
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Tristan Chaplin
2012-05-02 02:07:15 UTC
Permalink
I'm running into a few more problems here. If I run a script with

fiji-macosx --headless script

and the script tries to resze a stack with the command

IJ.run(imp, "Size...", "width=400 height=400 depth=145 constrain average
interpolation=Bilinear")

I get this error:

java.lang.ClassCastException: java.lang.String cannot be cast to
java.awt.TextField
at ij.plugin.Resizer.run(Resizer.java:91)
at ij.IJ.runPlugInUnchecked(IJ.java:175)
at ij.IJ.runPlugIn(IJ.java:157)
at ij.Executer.runCommand(Executer.java:147)
at ij.Executer.run(Executer.java:78)
at ij.IJ.run(IJ.java:269)
at ij.IJ.run(IJ.java:314)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
at org.python.core.PyObject.__call__(PyObject.java:432)
at org.python.core.PyObject.__call__(PyObject.java:436)
at
org.python.pycode._pyx0.f$0(/Users/tchaplin/Dropbox/Neuro/Programs/python/imagej/multistackreg.py:101)
at
org.python.pycode._pyx0.call_function(/Users/tchaplin/Dropbox/Neuro/Programs/python/imagej/multistackreg.py)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1204)
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:200)
at org.python.util.jython.run(jython.java:246)
at org.python.util.jython.main(jython.java:129)

It seems the resize failed. If I run it in the script editor in Fiji it
works just fine. If I run IJ.run(imp, "Smooth", "stack") or IJ.run(imp,
"Enhance Contrast", "saturated=0.4 normalize equalize normalize_all use")
from headless it works.

Does anyone know what's going on here? Am I just doing it wrong?

Any help would be appreciated.

Thanks,
Tristan

On Thu, Apr 26, 2012 at 3:10 AM, Johannes Schindelin <
Post by Johannes Schindelin
Hi Jan,
Post by Jan Eglinger
on Mac OS 10.5 (Leopard), I get the following "locally modified" files
and checksums after downloading a new copy of Fiji and running the
Contents/MacOS/fiji-macosx de36f7b25af2a38e639336509fefbe5786588dc5
Contents/MacOS/fiji-tiger 38ef1c8dedd2b898820fa05acf11755811ee4952
Thanks. I hard-coded those versions as known previous versions.
Thank you!
Dscho
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Tristan Chaplin
2012-05-09 02:10:40 UTC
Permalink
I also get this same problem when I run

IJ.run(imp, "Reslice [/]...", "output=0.200 start=Bottom avoid")

or

IJ.run(imp, "Properties...", etc

I can't figure out why this doesn't work. If anyone has any suggestions
please let me know.

Thanks,
Tristan



On Wed, May 2, 2012 at 12:07 PM, Tristan Chaplin
Post by Tristan Chaplin
I'm running into a few more problems here. If I run a script with
fiji-macosx --headless script
and the script tries to resze a stack with the command
IJ.run(imp, "Size...", "width=400 height=400 depth=145 constrain average
interpolation=Bilinear")
java.lang.ClassCastException: java.lang.String cannot be cast to
java.awt.TextField
at ij.plugin.Resizer.run(Resizer.java:91)
at ij.IJ.runPlugInUnchecked(IJ.java:175)
at ij.IJ.runPlugIn(IJ.java:157)
at ij.Executer.runCommand(Executer.java:147)
at ij.Executer.run(Executer.java:78)
at ij.IJ.run(IJ.java:269)
at ij.IJ.run(IJ.java:314)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
at org.python.core.PyObject.__call__(PyObject.java:432)
at org.python.core.PyObject.__call__(PyObject.java:436)
at
org.python.pycode._pyx0.f$0(/Users/tchaplin/Dropbox/Neuro/Programs/python/imagej/multistackreg.py:101)
at
org.python.pycode._pyx0.call_function(/Users/tchaplin/Dropbox/Neuro/Programs/python/imagej/multistackreg.py)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1204)
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:200)
at org.python.util.jython.run(jython.java:246)
at org.python.util.jython.main(jython.java:129)
It seems the resize failed. If I run it in the script editor in Fiji it
works just fine. If I run IJ.run(imp, "Smooth", "stack") or IJ.run(imp,
"Enhance Contrast", "saturated=0.4 normalize equalize normalize_all use")
from headless it works.
Does anyone know what's going on here? Am I just doing it wrong?
Any help would be appreciated.
Thanks,
Tristan
On Thu, Apr 26, 2012 at 3:10 AM, Johannes Schindelin <
Post by Johannes Schindelin
Hi Jan,
Post by Jan Eglinger
on Mac OS 10.5 (Leopard), I get the following "locally modified" files
and checksums after downloading a new copy of Fiji and running the
Contents/MacOS/fiji-macosx de36f7b25af2a38e639336509fefbe5786588dc5
Contents/MacOS/fiji-tiger 38ef1c8dedd2b898820fa05acf11755811ee4952
Thanks. I hard-coded those versions as known previous versions.
Thank you!
Dscho
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Loading...