IJ.renameResults(summaryTitle,"Results") seems to have a timing issue

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

IJ.renameResults(summaryTitle,"Results") seems to have a timing issue

Aryeh Weiss
When I use:
IJ.renameResults(summaryTitle,"Results")

It does not reliably work in a script unless I put a delay into the code.

So:
IJ.renameResults(summaryTitle,"Results")
time.sleep(1)

makes the code work. Without the delay, the rename does not always work.

This is a difficult problem to describe and reproduce,, but maybe
someone has some ideas.
Maybe the static IJ methods require time to complete their "side
effects" before continuing?

--aryeh

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: IJ.renameResults(summaryTitle,"Results") seems to have a timing issue

Wayne Rasband-2
> On Jul 21, 2019, at 12:59 PM, Aryeh Weiss <[hidden email]> wrote:
>
> When I use:
> IJ.renameResults(summaryTitle,"Results")
>
> It does not reliably work in a script unless I put a delay into the code.

It would help if you could provide a minimal script that reproduces the problem.

The best way to create scripts that run quickly and reliably is to avoid displaying images and tables and to work with ImagePlus and ResultsTable objects. The particle analyzer will direct its output to a ResultsTable if you call ParticleAnalyzer.setResultsTable(). Call ParticleAnalyzer.setSummaryTable() to have summary data directed to a ResultsTable (requires ImageJ 1.52p or later). The following example runs the particle analyzer separately on the three channels of the HelaCells sample image, with the output and summary data directed to ResultsTable objects, which are saved as CSV files.

-wayne

  imp = IJ.openImage("http://wsr.imagej.net/images/hela-cells.zip");
  imp.setDisplayMode(IJ.GRAYSCALE);
  resultsTable = new ResultsTable();
  summaryTable = new ResultsTable();
  IJ.run("Set Measurements...", "area mean min centroid display");
  for (c=1; c<=3; c++) {
    imp.setC(c);
    IJ.setAutoThreshold(imp, "Default dark");
    ParticleAnalyzer.setResultsTable(resultsTable);
    ParticleAnalyzer.setSummaryTable(summaryTable);
    IJ.run(imp, "Analyze Particles...", "size=5 display summarize clear slice");
  }
  dir = IJ.getDir("home")+"Downloads/"
  resultsTable.save(dir+"Results.csv");
  summaryTable.save(dir+"Summary.csv”);




 

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: IJ.renameResults(summaryTitle,"Results") seems to have a timing issue

Aryeh Weiss
On 24/07/2019 20:11, Wayne Rasband wrote:
>> On Jul 21, 2019, at 12:59 PM, Aryeh Weiss <[hidden email]> wrote:
>>
>> When I use:
>> IJ.renameResults(summaryTitle,"Results")
>>
>> It does not reliably work in a script unless I put a delay into the code.
> It would help if you could provide a minimal script that reproduces the problem.

I have tried, but the minimal scripts run fine, probably because they
are minimal. I will keep trying, and if I have something I can
reproduce, I will post it.

> The best way to create scripts that run quickly and reliably is to avoid displaying images and tables and to work with ImagePlus and ResultsTable objects. The particle analyzer will direct its output to a ResultsTable if you call ParticleAnalyzer.setResultsTable(). Call ParticleAnalyzer.setSummaryTable() to have summary data directed to a ResultsTable (requires ImageJ 1.52p or later). The following example runs the particle analyzer separately on the three channels of the HelaCells sample image, with the output and summary data directed to ResultsTable objects, which are saved as CSV files.
>
> -wayne
>
>    imp = IJ.openImage("http://wsr.imagej.net/images/hela-cells.zip");
>    imp.setDisplayMode(IJ.GRAYSCALE);
>    resultsTable = new ResultsTable();
>    summaryTable = new ResultsTable();
>    IJ.run("Set Measurements...", "area mean min centroid display");
>    for (c=1; c<=3; c++) {
>      imp.setC(c);
>      IJ.setAutoThreshold(imp, "Default dark");
>      ParticleAnalyzer.setResultsTable(resultsTable);
>      ParticleAnalyzer.setSummaryTable(summaryTable);
>      IJ.run(imp, "Analyze Particles...", "size=5 display summarize clear slice");
>    }
>    dir = IJ.getDir("home")+"Downloads/"
>    resultsTable.save(dir+"Results.csv");
>    summaryTable.save(dir+"Summary.csv”);
>
>
>
>
Thank you for this advice. I will start to alter my scripts accordingly

--aryeh

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html