Last active
February 21, 2018 17:55
-
-
Save oesteban/1a18c85543e920b0e62a074f7a8759a7 to your computer and use it in GitHub Desktop.
GIFTI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nibabel as nb | |
from nipype.utils.filemanip import fname_presuffix | |
def center_surface(in_gifti, newpath=None, | |
offset_from=['VolGeomC_R', 'VolGeomC_A', 'VolGeomC_S']): | |
gii = nb.load(in_gifti) | |
offset = [float(gii.darrays[0].meta.metadata[v]) for v in offset_from] | |
data = gii.darrays[0].data + offset | |
meta = gii.darrays[0].meta.metadata | |
for k in offset_from: | |
meta[k] = '%f' % 0.0 | |
gii.darrays[0] = nb.gifti.GiftiDataArray( | |
data=data.astype('float32'), | |
datatype='NIFTI_TYPE_FLOAT32', | |
intent='NIFTI_INTENT_POINTSET', | |
meta=meta, | |
coordsys=gii.darrays[0].coordsys | |
) | |
gii.darrays[1] = nb.gifti.GiftiDataArray( | |
data=gii.darrays[1].data.astype('float32'), | |
datatype='NIFTI_TYPE_FLOAT32', | |
intent='NIFTI_INTENT_TRIANGLE', | |
meta=meta, | |
coordsys=nb.gifti.GiftiCoordSystem(dataspace='NIFTI_XFORM_UNKNOWN'), | |
) | |
out_file = fname_presuffix( | |
in_gifti[:-len('.surf.gii')], | |
suffix='_offset.surf.gii', | |
use_ext=False, | |
newpath=newpath) | |
gii.to_filename(out_file) | |
return out_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment