Skip to content

Commit 7d7a355

Browse files
committed
more
1 parent a038548 commit 7d7a355

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

scripts/hcp_glm.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Run GLM on HCP data using nistats.
3+
"""
4+
# Author: Elvis Dohmatob
5+
16
import os
27
import time
38
import glob
@@ -11,15 +16,11 @@
1116
make_dmtx_from_timing_files)
1217
# from pypreprocess.reporting.glm_reporter import group_one_sample_t_test
1318

14-
# sanitize directories
19+
# config
1520
n_subjects = int(os.environ.get("N_SUBJECTS", 900))
1621
root = os.environ.get("ROOT", "/")
1722
output_dir = os.path.join(root, "storage/workspace/elvis/HCP_GLM")
18-
cache_dir = os.path.join(root, "storage/workspace/elvis/nilearn_cache")
19-
mem = Memory(cache_dir)
20-
2123
tr = .72
22-
# hrf_model = "Canonical with Derivative"
2324
hrf_model = "spm + derivative"
2425
drift_model = "Cosine"
2526
hfcut = 100.
@@ -32,13 +33,14 @@
3233
cons = ["LH-RH", "RH-LH", "RF-LF", "LF-RF", "T-AVG"]
3334

3435

35-
def do_subject_glm(subject_dir, task, cons, memory=None, smoothing_fwhm=0.,
36-
directions=None, report=True):
36+
def do_subject_glm(subject_dir, task, cons, smoothing_fwhm=0., directions=None,
37+
report=True):
3738
subject_id = os.path.basename(subject_dir)
3839
stats_start_time = time.ctime()
3940
if directions is None:
4041
directions = ['LR', 'RL']
4142
subject_output_dir = os.path.join(output_dir, subject_id)
43+
memory = Memory(os.path.join(output_dir, "cache_dir", subject_id))
4244
if not os.path.exists(subject_output_dir):
4345
os.makedirs(subject_output_dir)
4446
fmri_files = [os.path.join(subject_dir,
@@ -58,7 +60,8 @@ def do_subject_glm(subject_dir, task, cons, memory=None, smoothing_fwhm=0.,
5860
if not os.path.exists(x):
5961
print("%s is missing; skipping subject %s ..." % (x, subject_id))
6062
return
61-
assert len(fmri_files) == len(design_files)
63+
if len(fmri_files) != len(design_files):
64+
raise RuntimeError
6265

6366
# the actual GLM stuff
6467
n_scans = []
@@ -139,7 +142,7 @@ def do_subject_glm(subject_dir, task, cons, memory=None, smoothing_fwhm=0.,
139142
print("\tcontrast id: %s" % contrast_id)
140143
z_map, eff_map = fmri_glm.transform(
141144
contrast_val, contrast_name=contrast_id, output_z=True,
142-
output_effects=True, output_variance=True)
145+
output_effects=True)
143146

144147
# store stat maps to disk
145148
for map_type, out_map in zip(['z', 'effects'],
@@ -166,7 +169,7 @@ def do_subject_glm(subject_dir, task, cons, memory=None, smoothing_fwhm=0.,
166169
"report_stats.html")
167170
generate_subject_stats_report(
168171
stats_report_filename, contrasts, z_maps,
169-
fmri_glm.masker_.mask_img_, threshold=3., cluster_th=15,
172+
fmri_glm.masker_.mask_img_, threshold=2.3, cluster_th=15,
170173
design_matrices=design_matrices, TR=tr, subject_id=subject_id,
171174
start_time=stats_start_time, n_scans=n_scans, paradigm=paradigm,
172175
frametimes=frametimes, drift_model=drift_model, hfcut=hfcut,
@@ -191,8 +194,8 @@ def do_subject_glm(subject_dir, task, cons, memory=None, smoothing_fwhm=0.,
191194
n_jobs = min(os.environ.get("N_JOBS", len(subject_dirs)),
192195
len(subject_dirs))
193196
first_levels = Parallel(n_jobs=n_jobs)(delayed(do_subject_glm)(
194-
subject_dir, task, cons, memory=mem,
195-
directions=["LR"]) for subject_dir in subject_dirs)
197+
subject_dir, task, cons)
198+
for subject_dir in subject_dirs)
196199
first_levels = [x for x in first_levels if x is not None]
197200
print(task, len(first_levels))
198201

0 commit comments

Comments
 (0)