|
3 | 3 | from pathlib import Path |
4 | 4 | from functools import partial |
5 | 5 | from .utils import build_model |
6 | | - |
| 6 | +import tqdm |
7 | 7 |
|
8 | 8 | class Analysis: |
9 | 9 | """ Analysis object class. Object representing an analysis that can be |
@@ -240,20 +240,42 @@ def get_report(self, id, run_id=None): |
240 | 240 | """ |
241 | 241 | return self.get(id=id, sub_route='report', run_id=run_id) |
242 | 242 |
|
243 | | - def upload_neurovault(self, id, tarball, validation_hash, force=False, |
| 243 | + def upload_neurovault(self, id, validation_hash, subject_paths=None, |
| 244 | + group_paths=None, collection_id=None, force=False, |
244 | 245 | n_subjects=None): |
245 | 246 | """ Submit analysis for report generation |
246 | 247 | :param str id: Analysis hash_id. |
247 | | - :param str tarball: Path to tarball. |
248 | 248 | :param str validation_hash: Validation hash string. |
| 249 | + :param list(str) subject_paths: List of image paths. |
| 250 | + :param list(str) group_paths: List of image paths. |
249 | 251 | :param bool force: Force upload with unique timestamped name. |
250 | 252 | :param int n_subjects: Number of subjects in analysis. |
251 | 253 | :return: client response object |
252 | 254 | """ |
253 | | - files = {'tarball': open(tarball, 'rb')} |
254 | | - return self.post(id=id, sub_route='upload', files=files, |
255 | | - validation_hash=validation_hash, force=force, |
256 | | - n_subjects=n_subjects) |
| 255 | + # Do group, then subject level |
| 256 | + if group_paths is not None: |
| 257 | + print("Uploading group images") |
| 258 | + for path in tqdm.tqdm(group_paths): |
| 259 | + files = {'image_file': open(path, 'rb')} |
| 260 | + req = self.post( |
| 261 | + id=id, sub_route='upload', files=files, level='GROUP', |
| 262 | + validation_hash=validation_hash, force=force, |
| 263 | + n_subjects=n_subjects, collection_id=collection_id) |
| 264 | + if collection_id is None: |
| 265 | + collection_id = req['collection_id'] |
| 266 | + |
| 267 | + if subject_paths is not None: |
| 268 | + print("Uploading subject images") |
| 269 | + for path in tqdm.tqdm(subject_paths): |
| 270 | + files = {'image_file': open(path, 'rb')} |
| 271 | + req = self.post( |
| 272 | + id=id, sub_route='upload', files=files, level='SUBJECT', |
| 273 | + validation_hash=validation_hash, force=force, |
| 274 | + collection_id=collection_id) |
| 275 | + if collection_id is None: |
| 276 | + collection_id = req['collection_id'] |
| 277 | + |
| 278 | + return req |
257 | 279 |
|
258 | 280 | def get_uploads(self, id): |
259 | 281 | """ Get NeuroVault uploads associated with this analysis |
|
0 commit comments