Skip to content

Commit

Permalink
add fmriprep flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Shotgunosine committed Feb 6, 2024
1 parent f6e18d1 commit b163b2d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
32 changes: 24 additions & 8 deletions contarg/cli/run_normgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from joblib import Parallel, delayed
import numpy as np
import click
from contarg.normgrid import load_liston_surfs
from contarg.normgrid import load_liston_surfs, load_surfaces
from contarg.stimgrid import run_opt_and_save_outputs, angle_between
from contarg.utils import surf_data_from_cifti
import templateflow
Expand Down Expand Up @@ -50,21 +50,43 @@ def normgrid():
show_default=True,
help="Number of jobs to run in parallel to find targets",
)
@click.option(
"--surf_src",
type=str,
default='liston',
show_default=True,
help='flag to indicate where data is coming from, options are liston or fmriprep')
@click.option("--bids-dir", type=click.Path(), help="Bids directory", required=False)
@click.option("--fmriprep-dir", type=click.Path(), help="FMRIPREP directory", required=False)
@click.option("--anat-dir", type=click.Path(), help="contarg anat outputs directory", required=False)
def sim_gyral_lip(headmodel_dir, searchgrid_dir, out_dir, src_surf_dir,
coil='MagVenture_MCF-B65.ccd', distancetoscalp=2,
surf_src='liston', njobs=1):
surf_src='liston', bids_dir=None, fmriprep_dir=None, anat_dir=None, njobs=1):
HeadModel_dir = Path(headmodel_dir)
SearchGrid_dir = Path(searchgrid_dir)
src_surf_dir = Path(src_surf_dir)
out_dir = Path(out_dir)

try:
m2m_dir = sorted(HeadModel_dir.glob('m2m*'))[0]

except IndexError:
raise FileNotFoundError(f"No m2m directory found in {HeadModel_dir}")
skinsurf_path = m2m_dir / 'Skin.surf.gii'
subject = '_'.join(m2m_dir.parts[-1].split('_')[1:])
headmesh_path = m2m_dir / f'{subject}.msh'

# load surfaces
if surf_src == 'liston':
surfaces = load_liston_surfs(subject, src_surf_dir)
elif surf_src =='fmriprep':
if bids_dir is None or fmriprep_dir is None or anat_dir is None:
raise ValueError("Must specify bids_dir, fmriprep_dir, and anat_dir if surf_src is fmriprep")
layout = BIDSLayout(bids_dir, derivatives=fmriprep_dir)
surfaces = load_surfaces(subject, layout, anat_dir, overwrite=False)
else:
raise NotImplementedError

cortical_points, normals = np.load((SearchGrid_dir / 'SearchGrid.npy').as_posix())

if not np.isclose(np.linalg.norm(normals, axis=1), 1).all():
Expand Down Expand Up @@ -193,12 +215,6 @@ def sim_gyral_lip(headmodel_dir, searchgrid_dir, out_dir, src_surf_dir,
medial_wall['l'] = templateflow.api.get(template='fsLR', density='32k', desc='nomedialwall', hemi='L')
medial_wall['r'] = templateflow.api.get(template='fsLR', density='32k', desc='nomedialwall', hemi='R')

# load surfaces
if surf_src == 'liston':
surfaces = load_liston_surfs(subject, src_surf_dir)
else:
raise NotImplementedError

consolidated_paths = [sim_dir / f"sub-{subject}_simulation-{sim_run_n:02d}_desc-{metric}_stat.nii.gz" for metric in
['magnE', 'Ei', 'Ej', 'Ek', 'target']]
cifti_outs = []
Expand Down
12 changes: 10 additions & 2 deletions contarg/normgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,8 +1391,16 @@ def run_clusters(subject, concat_nii, clust_outdir, src_surf_dir,
return ref_clusters, ref_ts, ref_repts, dstim_clusters, dstim_verts


def make_uncert_surfaces(subject, src_surf_dir, uncert_dir, overwrite=False):
surfaces = load_liston_surfs(subject, src_surf_dir)
def make_uncert_surfaces(subject, src_surf_dir, uncert_dir, overwrite=False, fmriprep=False,
layout=None, anat_dir=None):
if fmriprep:
if layout is None:
raise ValueError("Must pass a layout if fmriprep is True")
if anat_dir is None:
raise ValueError("Must pass an anat_dir if ")
surfaces = load_surfaces(subject=subject, layout=layout, anat_dir=anat_dir, overwrite=overwrite)
else:
surfaces = load_liston_surfs(subject, src_surf_dir)

medial_wall = {}
medial_wall['l'] = templateflow.api.get(template='fsLR', density='32k', desc='nomedialwall', hemi='L')
Expand Down

0 comments on commit b163b2d

Please sign in to comment.