Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 864defe

Browse files
author
Adam Richie-Halford
committed
Add progress bar to Subject.download()
1 parent 9608e9b commit 864defe

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

dmriprep/data.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import pandas as pd
1414
from dask import compute, delayed
1515
from dask.diagnostics import ProgressBar
16+
from tqdm.auto import tqdm
1617

1718

1819
mod_logger = logging.getLogger(__name__)
@@ -203,8 +204,12 @@ def postprocess(self):
203204
raise NotImplementedError
204205

205206
def download(self, directory, include_site=False, overwrite=False):
206-
results = [delayed(sub.download)(directory, include_site, overwrite)
207-
for sub in self.subjects]
207+
results = [delayed(sub.download)(
208+
directory=directory,
209+
include_site=include_site,
210+
overwrite=overwrite,
211+
pbar=False
212+
) for sub in self.subjects]
208213

209214
with ProgressBar():
210215
compute(*results, scheduler="threads")
@@ -373,7 +378,8 @@ def _organize_s3_keys(self):
373378
self._valid = False
374379
self._s3_keys = None
375380

376-
def download(self, directory, include_site=False, overwrite=False):
381+
def download(self, directory, include_site=False,
382+
overwrite=False, pbar=True):
377383
if include_site:
378384
directory = op.join(directory, self.site)
379385

@@ -383,14 +389,25 @@ def download(self, directory, include_site=False, overwrite=False):
383389
)) for p in v] for k, v in self.s3_keys.items()
384390
}
385391

386-
for ftype, s3_keys in self.s3_keys.items():
392+
pbar_ftypes = tqdm(self.s3_keys.keys(),
393+
desc=f"Downloading {self.subject_id}")
394+
395+
for ftype in pbar_ftypes:
396+
pbar_ftypes.set_description(
397+
f"Downloading {self.subject_id} ({ftype})"
398+
)
399+
s3_keys = self.s3_keys[ftype]
387400
if isinstance(s3_keys, str):
388401
_download_from_s3(fname=files[ftype],
389402
bucket=self.study.bucket,
390403
key=s3_keys,
391404
overwrite=overwrite)
392405
elif all(isinstance(x, str) for x in s3_keys):
393-
for key, fname in zip(s3_keys, files[ftype]):
406+
file_zip = tqdm(zip(s3_keys, files[ftype]),
407+
desc=f"{ftype}",
408+
total=len(s3_keys),
409+
leave=False)
410+
for key, fname in file_zip:
394411
_download_from_s3(fname=fname,
395412
bucket=self.study.bucket,
396413
key=key,
@@ -420,7 +437,7 @@ def _determine_directions(self,
420437
421438
Parameters
422439
----------
423-
input_files : InputFiles namedtuple
440+
input_files : dict
424441
The local input files for the subject
425442
426443
input_type : "s3" or "local", default="s3"
@@ -572,8 +589,8 @@ def _separate_sessions(self, input_files, multiples_policy='sessions',
572589
573590
Returns
574591
-------
575-
list of InputFiles namedtuples
576-
List of InputFiles namedtuples for each session ID.
592+
dict of dicts
593+
Dict of Dicts of file names
577594
"""
578595
if multiples_policy not in ['sessions', 'concatenate']:
579596
raise ValueError('`multiples_policy` must be either "sessions" or '

docker/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies:
99
- graphviz
1010
- ipython
1111
- pandas
12+
- tqdm
1213
- pip:
1314
- "--editable=git+https://github.com/nipy/nipype@fa0a101fec2d010dcb68910000f66d7c64e5d03e#egg=nipype"
1415
- bids

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313

1414
requirements = [
1515
'Click>=6.0',
16-
'nipype',
16+
'dask',
1717
'dipy',
18+
'nipype',
1819
'pandas',
1920
'parse',
20-
'dask',
21+
'tqdm',
2122
]
2223

2324
setup_requirements = ['pytest-runner', ]

0 commit comments

Comments
 (0)