templateflow / python-client

A python client to query TemplateFlow via pyBIDS
https://templateflow.org/python-client/
Apache License 2.0
8 stars 12 forks source link

[FIX] Make download progress bar display correct units #63

Closed HippocampusGirl closed 3 years ago

HippocampusGirl commented 3 years ago

When downloading files, the progress display shows file sizes on the order of kilobytes, even though the requested file should be multiple megabytes in size. When I first encountered this, I thought the files may be corrupt, but this is not the case.

Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_desc-brain_T1w.nii.gz
3.39kB [00:00, 3.46kB/s]

Steps to reproduce this

import os
from tempfile import mkdtemp
os.environ["TEMPLATEFLOW_HOME"] = mkdtemp()

from templateflow import api
api.get("MNI152NLin2009cAsym", resolution=1, desc="brain", suffix="T1w")

Looking at the code, I discovered that the progress bar module tqdm is configured to display one download block as one byte, even though one download block can be up to 1024 bytes in size.

With the proposed fix, the correct file size is displayed

Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_desc-brain_T1w.nii.gz
100%|████████████████████████████████████████████████████████████| 3.47M/3.47M [00:01<00:00, 3.46MB/s]
oesteban commented 3 years ago

I'm going to break master by merging this, but that should be easily solvable if we do this -> https://github.com/nipreps/sdcflows/commit/fef4ac623910b08d1f95d47d397d1c19dad0e45c

Thanks much for this contribution!!