def get_anat(cls): from nipy.utils.data import templates if cls.anat is not None: return cls.anat, cls.anat_sform, cls.anat_max filename = templates.get_filename( 'ICBM152', '1mm', 'T1_brain.nii.gz') if not os.path.exists(filename): raise OSError('Cannot find template file T1_brain.nii.gz' 'required to plot anatomy. Possible path: %s' % filename) anat_im = load(filename) anat = anat_im.get_data() anat = anat.astype(np.float) anat_mask = ndimage.morphology.binary_fill_holes(anat > 0) anat = np.ma.masked_array(anat, np.logical_not(anat_mask)) cls.anat_sform = anat_im.get_affine() cls.anat = anat cls.anat_max = anat.max() return cls.anat, cls.anat_sform, cls.anat_max
def find_mni_template(): """ Try to find an MNI template on the disk. """ from nipy.utils.data import templates, DataError try: filename = templates.get_filename( 'ICBM152', '1mm', 'T1_brain.nii.gz') if os.path.exists(filename): return filename except DataError: pass possible_paths = [ ('', 'usr', 'share', 'fsl', 'data', 'standard', 'avg152T1_brain.nii.gz'), ('', 'usr', 'local', 'share', 'fsl', 'data', 'standard', 'avg152T1_brain.nii.gz'), ] if 'FSLDIR' in os.environ: fsl_path = os.environ['FSLDIR'].split(os.sep) fsl_path.extend('data', 'standard', 'avg152T1_brain.nii.gz') possible_paths.append() for path in possible_paths: filename = os.sep.join((path)) if os.path.exists(filename): return filename