Skip to content

Commit

Permalink
Add tqdm progress bar to dials.import
Browse files Browse the repository at this point in the history
Give the user some hint as to the progress i.e. the computer is doing
something when you impoet thousands of files.

Resolves dials/dials#2783

Only show progress bar if > 1 file and isatty
  • Loading branch information
graeme-winter committed Oct 31, 2024
1 parent 834cb48 commit fde4a2b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions newsfragments/768.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``dials.import``: add a progress bar for the import process, particularly
useful when importing thousands of files
9 changes: 8 additions & 1 deletion src/dxtbx/model/experiment_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import Any, Callable, Generator, Iterable

import natsort
from tqdm import tqdm

import dxtbx
from dxtbx.format.Format import Format
Expand Down Expand Up @@ -671,7 +672,13 @@ def from_filenames(
format_groups = collections.defaultdict(list)
if format_kwargs is None:
format_kwargs = {}
for filename in to_process:

if os.isatty and len(filenames) > 1:
filename_iter = tqdm(to_process, total=len(filenames))
else:
filename_iter = to_process

for filename in filename_iter:
# We now have a file, pre-opened by Format.open_file (therefore
# cached). Determine its type, and prepare to put into a group
format_class = find_format.find_format(filename)
Expand Down

0 comments on commit fde4a2b

Please sign in to comment.