"Results tables not found " in Headless Mode

Dear All,
I have a macro that I would like to run in Headless mode (see this recent post for a solved problem with being unable to use roiManager in headless mode.)

This macro employs Analyze Particles, which populates the Results table with particle data. The Results table is refreshed with updateResults;

I need a second Results table to hold the final multi-row output of the macro.

To do this, I call IJ.remameResults("Results,"Particles");
This call changes the table named “Results” to “Particles”, so that a subsequent call to UpdateResults: creates a new table named “Results”. With this new Results table, I call a series of
setResult(("Column", row, value):
commands, so that the new Results table holds my final table.
At the end of the analysis loop, I rename the new Results table “Stats” using the `IJ.remameResults’ call, so that these final data are preserved the next time through the loop when AnalyzeParticles is called. Then, it’s just a matter of renaming the two tables back and forth as multiple images are analyzed. In regular Fiji, this approach works fine.

The problem is that calling IJ.renameResults("Results,"Particles"); throws an exception:

“Results” not found

Why is this? updateResults; runs fine, so the data must be held in some structure.
Does the Results Table contain a visual element that doesn’t exist in headless mode? If so, how do I access Results tables in headless mode so these datasets can be maintained as the analysis proceeds through multiple images, and can be ultimately saved to disc?

Many thanks for any help.

This may be a simple typo for clarify sake but are you missing a " mark?

you wrote
IJ.renameResults("Results,“Particles”)
should there be a " after Results and before the , IJ.renameResults(“Results”,“Particles”)

Why do you need to run in headless mode? In headless mode, opening a Results window will generate an exception. Why not just run the macro in batch mode? If headless mode is required, switch to a scripting language, or Java, and use non-displayed ResultsTable objects.

you are correct. this is just a typo.
Thanks for picking it up.

Dear Wayne
I would like to run this macro in headless mode because it analyzes 16 images per each well of a 96 well plate. As written, it loops through many calls to the Results table.
Because these calls pull Windows focus to the Results table (even in batch mode), the Results table grabs any keystrokes typed into any another application, and often triggers an exception. This means that I can’t do any other work while the analysis is running. (Please see this post where I described the problem.

Your question prompted me to think further about the Results table problem. I have concluded that I don’t need to use any results tables.
I can still use “Analyze Particles” to obtain an object list, and then store the regions as overlays as you suggested. In regular mode, Analyze Particles displays a Results table, but not in headless mode.

Then, instead of using setResult("Column", row, value); to create a Results table for my final data as I am currently doing, I can assign each of the four results I calculate per well to ordinary variables.
Next, I can convert the double precision values into strings, concatenate them into a single comma-delimited string, and store it as one element of a 96-element array.

I can then save the results to disk as a .csv file by iterating through the array to write each string.

dataArray= newArray(96) ;   // array to hold well results

outFileName = dir + "results.csv" ;   // fully qualified path to results file
outFile = File.open(outFileName) ; // create results file
for (j=0; j<96; j++)                        // loop through well results
{
dataRow = dataArray(j) ;             // assign current well results
print(outFile, dataRow) ;              // write current well results 
}
File.close(outFile) ;                    // close file

I think this should avoid any calls to make, rename, or close Results tables, so that headless mode doesn’t crash.

Do you think this should work?

With many thanks
Jeremy

Thanks for this discussion. I am in a similar place where for different reasons, running in headless mode is desired for my project. The overlay discussion was useful for moving my ROIS take on one set of Images and measured on another but now I have to save them…

This should work.

I am not able to reproduce the problem with the Results window grabbing focus. I am able to enter text into another application as the following test macro is running.

  setBatchMode(true);
  run("Blobs (25K)");
  setAutoThreshold("Default");
  for (i=0; i<100; i++) {
     run("Analyze Particles...", "display clear");
     if (i>0 && i%10==0)
        IJ.renameResults("Results-"+i);
     wait(500);
  }

Thank you, Wayne.
It’s interesting that you don’t find the same problem. I think it might be this snippet of my macro, which runs after each well of the 96 well plate has been analyzed.

updateResults;			// shows stats of individual nuclei regions
IJ.renameResults("Results","Nuclei");
if (f==0) {
	       updateResults;				// creates a new Results table
	    } else {
		      IJ.renameResults("Stats", "Results") ;
		}
PercentAlive = LivingCells / Totalcells;

setResult("Well Row", nResults, WellRow[f]);
setResult("Well Column", nResults-1, WellColumn[f]);
setResult("Living Cells", nResults-1, LivingCells );
setResult("Total Cells", nResults-1 , Totalcells);
setResult("Percent", nResults-1 , PercentAlive);

PerCent = PercentAlive *100;
updateResults;
IJ.renameResults("Results","Stats");
IJ.renameResults("Nuclei","Results");

I made the test macro more like your code snippet and I am still able to use another application while it is running. Are you able to use another application while it is running?

  setBatchMode(true);
  run("Blobs (25K)");
  setAutoThreshold("Default");
  for (i=0; i<50; i++) {
     run("Analyze Particles...", "display clear");
     updateResults;
     IJ.renameResults("Results","Nuclei");
     if (i==0)
        updateResults;
     else
        IJ.renameResults("Stats", "Results") ;
     setResult("Well Row", nResults, 11);
     setResult("Well Column", nResults-1, 22);
     setResult("Living Cells", nResults-1, 33);
     updateResults;
     IJ.renameResults("Results","Stats");
     IJ.renameResults("Nuclei","Results");
     wait(500);
  }