Skip to content

Commit 6a414a1

Browse files
authored
Merge pull request #68 from neuroscout/enh/report_enh
Enhance report getters, upload t-maps first
2 parents c436c34 + f5f3189 commit 6a414a1

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

pyns/models/analysis.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,13 @@ def create_analysis(self, *, name, dataset_name, predictor_names,
224224
"specified runs.")
225225

226226
# Build model
227+
if transformations:
228+
transformations = transformations.copy()
227229
model = build_model(
228230
name, predictor_names, task,
229231
subject=subject, run=run, session=session,
230-
hrf_variables=hrf_variables, transformations=transformations,
232+
hrf_variables=hrf_variables,
233+
transformations=transformations,
231234
contrasts=contrasts, dummy_contrasts=dummy_contrasts
232235
)
233236

@@ -260,13 +263,33 @@ def generate_report(self, id, run_id=None):
260263
"""
261264
return self.post(id=id, sub_route='report', params=dict(run_id=run_id))
262265

263-
def get_report(self, id, run_id=None):
266+
def get_report(self, id, run_id=None, loop_wait=True):
264267
""" Get generated reports for analysis
265268
:param str id: Analysis hash_id.
266269
:param int run_id: Optional run_id to constrain report.
267270
:return: client response object
268271
"""
269-
return self.get(id=id, sub_route='report', run_id=run_id)
272+
report = self.get(id=id, sub_route='report', run_id=run_id)
273+
if loop_wait:
274+
while report['status'] == 'PENDING':
275+
time.sleep(2)
276+
report = self.get_report(id=id, run_id=run_id)
277+
278+
return report
279+
280+
def get_design_matrix(self, id, run_id=None,
281+
loop_wait=True):
282+
""" Get report design_matrix
283+
:param str id: Analysis hash_id
284+
:param int run_id: Optional run_id to constrain report.
285+
:param boolean loop_wait: Wait for result from report
286+
"""
287+
report = self.get_report(id=id, run_id=run_id, loop_wait=loop_wait)
288+
289+
if report['status'] == 'OK':
290+
return report['result']['design_matrix']
291+
else:
292+
return report['status']
270293

271294
def plot_report(self, id, run_id=None, plot_type='design_matrix_plot',
272295
loop_wait=True):
@@ -279,12 +302,7 @@ def plot_report(self, id, run_id=None, plot_type='design_matrix_plot',
279302
if altair is None:
280303
raise ImportError("Altair is required to plot_reports")
281304

282-
report = self.get_report(id=id, run_id=run_id)
283-
284-
if loop_wait:
285-
while report['status'] == 'PENDING':
286-
time.sleep(2)
287-
report = self.get_report(id=id, run_id=run_id)
305+
report = self.get_report(id=id, run_id=run_id, loop_wait=loop_wait)
288306

289307
if report['status'] == 'OK':
290308
for p in report['result'][plot_type]:
@@ -304,10 +322,18 @@ def upload_neurovault(self, id, validation_hash, subject_paths=None,
304322
:param int n_subjects: Number of subjects in analysis.
305323
:return: client response object
306324
"""
325+
326+
def _ts_first(paths):
327+
tmaps = [t for t in paths if 'stat-t' in t]
328+
for t in tmaps:
329+
paths.remove(t)
330+
331+
return tmaps + group_paths
332+
307333
# Do group, then subject level
308334
if group_paths is not None:
309335
print("Uploading group images")
310-
for path in tqdm.tqdm(group_paths):
336+
for path in tqdm.tqdm(_ts_first(group_paths)):
311337
files = {'image_file': open(path, 'rb')}
312338
req = self.post(
313339
id=id, sub_route='upload', files=files, level='GROUP',
@@ -318,7 +344,7 @@ def upload_neurovault(self, id, validation_hash, subject_paths=None,
318344

319345
if subject_paths is not None:
320346
print("Uploading subject images")
321-
for path in tqdm.tqdm(subject_paths):
347+
for path in tqdm.tqdm(_ts_first(subject_paths)):
322348
files = {'image_file': open(path, 'rb')}
323349
req = self.post(
324350
id=id, sub_route='upload', files=files, level='SUBJECT',

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
long_description = fh.read()
66

77
setup(name='pyns',
8-
version='0.4',
8+
version='0.4.1',
99
description='Neuroscout API wrapper',
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)