Jython - output files not being saved

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Jython - output files not being saved

jswalker
Hi all,

I'm using FIJI (ImageJ 1.51a, Java 1.6.0_24 (64 bit)).

I've noticed this on two separate Jython macros I'm developing and would love to know where I'm going wrong. They are .py scripts with GUIs intended to be run directly from FIJI's Plugins>Run>Macro command - in an attempt to make them usable by our student researchers, some of whom may have little to no programming experience.

Normally I run scripts from a network drive (and have them output to network directories) but I've tried running this from (and on files in) my local drive and it has no effect. I've also tried running FIJI in administrator mode--no change either.

In the first one, I'm simply opening ND2 files using bioformats and saving them as JPGs. I get all the log messages I'm supposed to, and there is a transient .tmp file created in the ND2's directory as it is processed, but no JPG is produced at the end of it.

from ij import IJ
from fiji.util.gui import GenericDialogPlus
from loci.plugins import BF
from ij.io import FileSaver
import os

...GenericDialogPlus stuff goes here...

def process(srcDir, dstDir, nameContains, currentDir, fileName, keepDirectories, headlessMode):
    print "Opening", fileName
    saveDir = currentDir.replace(srcDir, dstDir) if keepDirectories else dstDir
    imps = BF.openImagePlus(os.path.join(currentDir, fileName))
    print "Opened", fileName
    for imp in imps:
        if not headlessMode:
            print "Now showing image..."
            imp.show()
    fs = FileSaver(imp)
    if not os.path.exists(saveDir):
        os.makedirs(saveDir)
    print "Saving to", saveDir
    fs.saveAsJpeg(os.path.join(saveDir, fileName))
    IJ.selectWindow("Log")
    IJ.run("Close")
    imp.close()

(I would also love to know if there's a way to select the log window and close it without calling IJ, but that's negligible!)

The second one is more complicated, as I'm trying to save several results files. This one might deserve a post of its own, but I'll put it here as I suspect the problem may be the same. No files are produced as a result of these commands, despite the fact that I'm using simple IJ.saveAs calls for some of them.

   saveDir = currentDir.replace(srcDir, dstDir) if keepDirectories else dstDir
   if not os.path.exists(saveDir):
     os.makedirs(saveDir)
   print "Saving to", saveDir
   ImageConverter(imp4).convertToGray8()
   IJ.saveAs(imp4, "Jpeg", os.path.join(saveDir, fileName))
   rm = RoiManager.getInstance()
   rm.runCommand("Save", fileName + ".zip")
   ht = rm.getList()
   ht.removeAll()
   IJ.saveAs("Results", fileName+".csv")
   IJ.run("Close")
   IJ.selectWindow("Log")
   IJ.saveAs("Text", fileName+".txt")
   IJ.run("Close")
   IJ.run("Clear Results")
   imp3.close()
   imp2.close()
   imp.close()

The IJ macro versions of these scripts worked just fine, and I'm not sure what else to try. Any ideas?
Many thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Jython - output files not being saved

jswalker
Update: Problem resolved - by changing  fs.saveAsJpeg(os.path.join(saveDir, fileName)) to  fs.saveAsJpeg(os.path.join(saveDir, fileName + ".jpg")) in the first case, and changing (for example)  IJ.saveAs("Text", fileName+".txt") to  IJ.saveAs("Text", saveDir + fileName+".txt") in the other cases. I ended up calling os.path.splitext as well, which gets rid of the double file extension.