def to_fsl(self, anat_nii, direction='func>anat'):
        import nibabel
        import numpy.linalg as npl
        inv = npl.inv
        ## -- Internal notes -- ## 
        # pycortex transforms are internally stored as anatomical space -> functional data space
        # transforms. Thus the anatomical file is the "infile" in FSL-speak.
        infile = anat_nii

        try:
            inIm = nibabel.load(infile)
        except AttributeError:
            inIm = infile
        in_hdr = inIm.get_header()
        ref_hdr = self.reference.get_header()
        # get_zooms gets the positive voxel sizes as returned in the header
        inspace = np.diag(in_hdr.get_zooms()[:3] + (1,))
        refspace = np.diag(ref_hdr.get_zooms()[:3] + (1,))
        # Since FSL does not use the full transform info in the nifti header, 
        # determine whether the transform indicates that the X axis should be 
        # flipped; if so, flip the X axis (for both infile and reffile)
        if npl.det(in_hdr.get_best_affine())>=0:
            print("Determinant is > 0: FLIPPING!")
            inspace = np.dot(inspace, _x_flipper(in_hdr.get_data_shape()[0]))
        if npl.det(ref_hdr.get_best_affine())>=0:
            print("Determinant is > 0: FLIPPING!")
            refspace = np.dot(refspace, _x_flipper(ref_hdr.get_data_shape()[0]))

        inAffine = inIm.get_affine()
        
        fslx = np.dot(refspace,np.dot(self.xfm,np.dot(inAffine,inv(inspace))))
        if direction=='func>anat':
            return inv(fslx)
        elif direction=='anat>func':
            return fslx
Converts a pycortex transform to an FSL transform.
dataset/ETHPy150Open gallantlab/pycortex/cortex/xfm.py/Transform.to_fsl