-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_feat-img_surface.py
47 lines (39 loc) · 1.31 KB
/
convert_feat-img_surface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Convert NiMARE-generated feature maps to surfaces and save to a Pickle file."""
import os.path as op
import pickle
from glob import glob
import nibabel as nib
import numpy as np
from nilearn import surface
from nilearn.datasets import fetch_surf_fsaverage, load_mni152_brain_mask
image_dir = "/home/data/nbc/misc-projects/meta-gradients/code/feature_maps"
out_dir = "/home/data/nbc/misc-projects/meta-gradients/code"
mask = load_mni152_brain_mask()
feature_images = sorted(glob(op.join(image_dir, "*_association-test_z.nii.gz")))
surf_dict = {}
for img in feature_images:
tmp_feat_name = op.basename(img).split("_")[0]
print(tmp_feat_name)
fsaverage = fetch_surf_fsaverage(mesh="fsaverage5")
surf_lh = surface.vol_to_surf(
nib.load(img),
fsaverage.pial_left,
radius=6.0,
interpolation="nearest",
kind="ball",
n_samples=None,
mask_img=mask,
)
surf_rh = surface.vol_to_surf(
nib.load(img),
fsaverage.pial_right,
radius=6.0,
interpolation="nearest",
kind="ball",
n_samples=None,
mask_img=mask,
)
surf = np.transpose(np.hstack((surf_lh, surf_rh)))
surf_dict[tmp_feat_name] = surf
with open(op.join(out_dir, "ns_feature_maps_surface.pkl.gz"), "wb") as fo:
pickle.dump(surf_dict, fo)