Skip to content

Commit 18b91ec

Browse files
committed
population_template: Better progress bars on non-interactive terminals
1 parent a47b150 commit 18b91ec

File tree

1 file changed

+9
-3
lines changed
  • python/mrtrix3/commands/population_template

1 file changed

+9
-3
lines changed

python/mrtrix3/commands/population_template/execute.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#
1414
# For more details, see http://www.mrtrix.org/.
1515

16-
import json, os, shutil
16+
import json, os, shutil, sys
1717
from mrtrix3 import MRtrixError
1818
from mrtrix3 import app, image, matrix, path, run
1919
from .contrasts import Contrasts
@@ -608,7 +608,10 @@ def execute(): #pylint: disable=unused-variable
608608
transform_average_driftref = matrix.load_transform('linear_transform_average_init.txt')
609609

610610
def linear_msg():
611-
return f'Optimising template with linear registration (stage {level+1} of {len(linear_scales)}; {regtype})'
611+
return 'Optimising template with linear registration' \
612+
+ (f' (stage {level+1} of {len(linear_scales)}; {regtype})' \
613+
if sys.stderr.isatty \
614+
else f' ({len(linear_scales)} stages)')
612615
progress = app.ProgressBar(linear_msg, len(linear_scales) * len(ins) * (1 + n_contrasts + int(use_masks)))
613616
for level, (regtype, scale, niter, lmax) in enumerate(zip(linear_type, linear_scales, linear_niter, linear_lmax)):
614617
for inp in ins:
@@ -808,7 +811,10 @@ def linear_msg():
808811
os.mkdir('warps')
809812
level = 0
810813
def nonlinear_msg():
811-
return f'Optimising template with non-linear registration (stage {level+1} of {len(nl_scales)})'
814+
return 'Optimising template with non-linear registration' \
815+
+ (f' (stage {level+1} of {len(nl_scales)})' \
816+
if sys.stderr.isatty \
817+
else f' ({len(nl_scales)} stages)')
812818
progress = app.ProgressBar(nonlinear_msg, len(nl_scales) * len(ins))
813819
for level, (scale, niter, lmax) in enumerate(zip(nl_scales, nl_niter, nl_lmax)):
814820
for inp in ins:

0 commit comments

Comments
 (0)