Source code for osl_dynamics.utils.filenames

"""Filename containers for M/EEG processing pipelines."""

import os
from typing import Optional


[docs] class SurfaceFilenames: """Container for surface extraction file paths. Parameters ---------- root : str Root directory for surface files. """ def __init__(self, root: str):
[docs] self.root = root
os.makedirs(root, exist_ok=True)
[docs] self.fsl_dir = os.environ["FSLDIR"]
# Nifti files
[docs] self.mri_file = f"{root}/smri.nii.gz"
[docs] self.std_brain = f"{self.fsl_dir}/data/standard/MNI152_T1_1mm_brain.nii.gz"
[docs] self.std_brain_bigfov = ( f"{self.fsl_dir}/data/standard/MNI152_T1_1mm_BigFoV_facemask.nii.gz" )
# Transformations
[docs] self.mni2mri_flirt_xform_file = f"{root}/mni2mri_flirt_xform.txt"
[docs] self.mni_mri_t_file = f"{root}/mni_mri-trans.fif"
# BET mesh / surfaces
[docs] self.bet_outskin_mesh_vtk_file = f"{root}/outskin_mesh.vtk"
[docs] self.bet_inskull_mesh_vtk_file = f"{root}/inskull_mesh.vtk"
[docs] self.bet_outskull_mesh_vtk_file = f"{root}/outskull_mesh.vtk"
[docs] self.bet_outskin_mesh_file = f"{root}/outskin_mesh.nii.gz"
[docs] self.bet_outskin_plus_nose_mesh_file = f"{root}/outskin_plus_nose_mesh.nii.gz"
[docs] self.bet_inskull_mesh_file = f"{root}/inskull_mesh.nii.gz"
[docs] self.bet_outskull_mesh_file = f"{root}/outskull_mesh.nii.gz"
[docs] class CoregFilenames: """Container for coregistration file paths. Parameters ---------- root : str Root directory for coregistration files. """ def __init__(self, root: str):
[docs] self.root = root
os.makedirs(root, exist_ok=True) # Nifti files
[docs] self.mri_file = f"{root}/scaled_mri.nii.gz"
# Fif files
[docs] self.info_fif_file = f"{root}/info-raw.fif"
[docs] self.head_scaledmri_t_file = f"{root}/head_scaledmri-trans.fif"
[docs] self.head_mri_t_file = f"{root}/head_mri-trans.fif"
[docs] self.ctf_head_mri_t_file = f"{root}/ctf_head_mri-trans.fif"
[docs] self.mrivoxel_scaledmri_t_file = f"{root}/mrivoxel_scaledmri_t_file-trans.fif"
# Fiducials / headshape points
[docs] self.mri_nasion_file = f"{root}/mri_nasion.txt"
[docs] self.mri_rpa_file = f"{root}/mri_rpa.txt"
[docs] self.mri_lpa_file = f"{root}/mri_lpa.txt"
[docs] self.head_nasion_file = f"{root}/head_nasion.txt"
[docs] self.head_rpa_file = f"{root}/head_rpa.txt"
[docs] self.head_lpa_file = f"{root}/head_lpa.txt"
[docs] self.head_headshape_file = f"{root}/head_headshape.txt"
# Freesurfer mesh in native space
[docs] self.bet_outskin_surf_file = f"{root}/scaled_outskin.surf"
[docs] self.bet_outskin_plus_nose_surf_file = f"{root}/scaled_outskin_plus_nose.surf"
[docs] self.bet_inskull_surf_file = f"{root}/scaled_inskull.surf"
[docs] self.bet_outskull_surf_file = f"{root}/scaled_outskull.surf"
# BET mesh / surfaces in native space
[docs] self.bet_outskin_mesh_vtk_file = f"{root}/scaled_outskin_mesh.vtk"
[docs] self.bet_inskull_mesh_vtk_file = f"{root}/scaled_inskull_mesh.vtk"
[docs] self.bet_outskull_mesh_vtk_file = f"{root}/scaled_outskull_mesh.vtk"
[docs] self.bet_outskin_mesh_file = f"{root}/scaled_outskin_mesh.nii.gz"
[docs] self.bet_outskin_plus_nose_mesh_file = ( f"{root}/scaled_outskin_plus_nose_mesh.nii.gz" )
[docs] self.bet_inskull_mesh_file = f"{root}/scaled_inskull_mesh.nii.gz"
[docs] self.bet_outskull_mesh_file = f"{root}/scaled_outskull_mesh.nii.gz"
[docs] class OSLFilenames: """Container for all pipeline file paths for processing a single M/EEG session. Parameters ---------- outdir : str Base output directory. id : str Session identifier. preproc_file : str Path to the preprocessed data file. surfaces_dir : str Path to the surfaces directory. pos_file : str, optional Path to a .pos file (only needed for CTF data). elc_file : str, optional Path to an .elc file (alternative format for head shape points from CTF data). """ def __init__( self, outdir: str, id: str, preproc_file: str, surfaces_dir: str, pos_file: Optional[str] = None, elc_file: Optional[str] = None, ):
[docs] self.outdir = outdir
[docs] self.id = id
[docs] self.preproc_file = preproc_file
[docs] self.surfaces_dir = surfaces_dir
[docs] self.surfaces = SurfaceFilenames(surfaces_dir)
[docs] self.bem_dir = f"{outdir}/{id}/bem"
os.makedirs(self.bem_dir, exist_ok=True)
[docs] self.coreg_dir = f"{outdir}/{id}/coreg"
[docs] self.coreg = CoregFilenames(self.coreg_dir)
[docs] self.fwd_model = f"{self.coreg_dir}/model-fwd.fif"
[docs] self.pos_file = pos_file
[docs] self.elc_file = elc_file
[docs] self.src_dir = f"{outdir}/{id}/src"
os.makedirs(self.src_dir, exist_ok=True)
[docs] self.filters = f"{self.src_dir}/filters-lcmv.h5"
def __str__(self) -> str: lines = [ f"OSLFilenames for {self.id}:", f" Output directory: {self.outdir}", f" Preprocessed file: {self.preproc_file}", f" Surfaces directory: {self.surfaces_dir}", f" BEM directory: {self.bem_dir}", f" Coreg directory: {self.coreg_dir}", f" \u2514\u2500 Forward model: {self.fwd_model}", f" Source directory: {self.src_dir}", f" \u2514\u2500 lcmv filters: {self.filters}", ] if self.pos_file is not None: lines += [ f" pos file: {self.pos_file}", ] if self.elc_file is not None: lines += [ f" elc file: {self.elc_file}", ] return "\n".join(lines) def __repr__(self) -> str: return f"<OSLFilenames id='{self.id}' outdir='{self.outdir}'>"