44import time
55
66from ij import IJ # pylint: disable-msg=import-error
7- from ij .plugin .frame import RoiManager # pylint: disable-msg=import-error
87from ij .measure import ResultsTable # pylint: disable-msg=import-error
8+ from ij .plugin .frame import RoiManager # pylint: disable-msg=import-error
99
1010from ..log import LOG as log
1111
@@ -30,19 +30,18 @@ def error_exit(msg):
3030
3131
3232def elapsed_time_since (start , end = None ):
33- """Prints the elapsed time for execution
33+ """Generate a string with the time elapsed between the two timepoints.
3434
3535 Parameters
3636 ----------
37- start : time
38- Start time
39- end : time, optional
40- End time
37+ start : time.time
38+ Start time.
39+ end : time.time , optional
40+ End time. If skipped the current time will be used.
4141
4242 Returns
4343 -------
4444 str
45- Formatted time elapsed
4645 """
4746
4847 if not end :
@@ -54,19 +53,18 @@ def elapsed_time_since(start, end=None):
5453
5554
5655def percentage (part , whole ):
57- """Returns the percentage of a value based on total
56+ """Calculate the percentage of a value based on total.
5857
5958 Parameters
6059 ----------
6160 part : float
62- Part
61+ Part.
6362 whole : float
64- Complete size
63+ Complete size.
6564
6665 Returns
6766 -------
6867 float
69- Percentage
7068 """
7169 return 100 * float (part ) / float (whole )
7270
@@ -82,7 +80,7 @@ def calculate_mean_and_stdv(float_values):
8280 Returns
8381 -------
8482 [float, float]
85- Mean and standard deviation of the list.
83+ Mean (1st item) and standard deviation (2nd item) of the list.
8684 """
8785 mean = sum (float_values ) / len (float_values )
8886 tot = 0.0
@@ -92,17 +90,21 @@ def calculate_mean_and_stdv(float_values):
9290
9391
9492def find_focus (imp ):
95- """Function to get the focused stack. Works on single-channel images only.
93+ """Find the slice of a stack that seems to bet the best focused one.
94+
95+ NOTE: currently only single-channel stacks are supported.
96+
97+ FIXME: explain what the function is actually doing, i.e. how does it decide
98+ what "the best focused one" is?
9699
97100 Parameters
98101 ----------
99- imp : ImagePlus
102+ imp : ij. ImagePlus
100103 A single-channel ImagePlus.
101104
102105 Returns
103106 -------
104107 int
105- Slice number which seems to be the best focused one.
106108 """
107109
108110 imp_dimensions = imp .getDimensions ()
@@ -138,8 +140,8 @@ def find_focus(imp):
138140def progressbar (progress , total , line_number , prefix = "" ):
139141 """Progress bar for the IJ log window.
140142
141- FIXME: how is this different from show_progressbar() above? Please explain
142- in the function description here .
143+ Show a progress bar in the log window of Fiji at a specific line independent
144+ of the main Fiji progress bar .
143145
144146 Parameters
145147 ----------
@@ -153,14 +155,34 @@ def progressbar(progress, total, line_number, prefix=""):
153155 Text to use before the progress bar, by default ''.
154156 """
155157
156- size = 30
158+ size = 20
157159 x = int (size * progress / total )
158160 IJ .log (
159161 "\\ Update%i:%s[%s%s] %i/%i\r "
160- % (line_number , prefix , "#" * x , "." * (size - x ), progress , total )
162+ % (
163+ line_number ,
164+ timed_log (prefix , True ),
165+ "#" * x ,
166+ "." * (size - x ),
167+ progress ,
168+ total ,
169+ )
161170 )
162171
163172
173+ def timed_log (message , as_string = False ):
174+ """Print a message to the ImageJ log window with a timestamp added.
175+
176+ Parameters
177+ ----------
178+ message : str
179+ Message to print
180+ """
181+ if as_string :
182+ return time .strftime ("%H:%M:%S" , time .localtime ()) + ": " + message + " "
183+ IJ .log (time .strftime ("%H:%M:%S" , time .localtime ()) + ": " + message + " " )
184+
185+
164186def get_free_memory ():
165187 """Get the free memory thats available to ImageJ.
166188
@@ -186,16 +208,11 @@ def setup_clean_ij_environment(rm=None, rt=None):
186208 rt : ResultsTable, optional
187209 A reference to an IJ-ResultsTable instance.
188210 """
189- # FIXME: use function(s) from the "roimanager" module!
190211 if not rm :
191- rm = RoiManager .getInstance ()
192- if not rm :
193- rm = RoiManager ()
212+ rm = roimanager .get_roimanager ()
194213
195214 if not rt :
196- rt = ResultsTable .getInstance ()
197- if not rt :
198- rt = ResultsTable ()
215+ rt = resultstable .get_resultstable ()
199216
200217 rm .runCommand ("reset" )
201218 rt .reset ()
0 commit comments