Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHINO example without visualisations + AAL parcellation. #240

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/oxford/no_viz_pipeline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Pipeline without any visualisations
-----------------------------------

Sometimes there are errors when generating plots. In this pipeline we use OSL without any visualisations.
100 changes: 100 additions & 0 deletions examples/oxford/no_viz_pipeline/do_rhino.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""RHINO without any visualisations.

"""

# Authors: Chetan Gohil <chetan.gohil@psych.ox.ac.uk>

import numpy as np

from osl.source_recon import setup_fsl, rhino

setup_fsl("/opt/ohba/fsl/6.0.5") # this is where FSL is installed on hbaws

# Directories
preproc_dir = "output/preproc"
anat_dir = "path/to/smri/dir"
coreg_dir = "output/coreg"

# Files ({subject} will be replaced by the name for the subject)
preproc_file = preproc_dir + "/{subject}_tsss_preproc_raw.fif"
smri_file = anat_dir + "/{subject}/anat/{subject}_T1w.nii"

# Subjects to coregister
subjects = ["sub-001", "sub-002"]

def fix_headshape_points(src_dir, subject, preproc_file, smri_file):
filenames = rhino.get_coreg_filenames(src_dir, subject)

# Load saved headshape and nasion files
hs = np.loadtxt(filenames["polhemus_headshape_file"])
nas = np.loadtxt(filenames["polhemus_nasion_file"])
lpa = np.loadtxt(filenames["polhemus_lpa_file"])
rpa = np.loadtxt(filenames["polhemus_rpa_file"])

# Remove headshape points on the nose
remove = np.logical_and(hs[1] > max(lpa[1], rpa[1]), hs[2] < nas[2])
hs = hs[:, ~remove]

# Remove headshape points on the neck
remove = hs[2] < min(lpa[2], rpa[2]) - 4
hs = hs[:, ~remove]

# Remove headshape points far from the head in any direction
remove = np.logical_or(
hs[0] < lpa[0] - 5,
np.logical_or(
hs[0] > rpa[0] + 5,
hs[1] > nas[1] + 5,
),
)
hs = hs[:, ~remove]

# Overwrite headshape file
np.savetxt(filenames["polhemus_headshape_file"], hs)


# Main RHINO code

for subject in subjects:

# Input files
preproc_file_ = preproc_file.format(subject=subject)
smri_file_ = smri_file.format(subject=subject)

# Extract fiducials and headshape points
filenames = rhino.get_coreg_filenames(src_dir, subject)
rhino.extract_polhemus_from_info(
fif_file=preproc_file_,
headshape_outfile=filenames["polhemus_headshape_file"],
nasion_outfile=filenames["polhemus_nasion_file"],
rpa_outfile=filenames["polhemus_rpa_file"],
lpa_outfile=filenames["polhemus_lpa_file"],
)

# Clean up headshape points
fix_headshape_points(src_dir, subject, preproc_file_, smri_file_)

# Extract surfaces from the structural
rhino.compute_surfaces(
smri_file=smri_file_,
subjects_dir=src_dir,
subject=subject,
include_nose=False,
)

# Coregistration
rhino.coreg(
fif_file=preproc_file_,
subjects_dir=src_dir,
subject=subject,
use_headshape=True,
use_nose=False,
)

# Forward model
rhino.forward_model(
subjects_dir=src_dir,
subject=subject,
model="Single Layer"
gridstep=8,
)
2 changes: 1 addition & 1 deletion examples/oxford/ssp_pipeline/4_coregister.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from osl import source_recon, utils

# Directories
preproc_dir = "/output/preproc_ssp"
preproc_dir = "output/preproc_ssp"
anat_dir = "path/to/smri/dir"
coreg_dir = "output/coreg"
fsl_dir = "/opt/ohba/fsl/6.0.5" # this is where FSL is installed on hbaws
Expand Down
Binary file not shown.
Loading