def to_fsl(self, anat_nii, direction='func>anat'):
        """Converts a pycortex transform to an FSL transform.

        Uses the stored "reference" file provided when the transform was created (usually 
        a functional data or statistical volume) and the supplied anatomical file to 
        create an FSL transform. By default, returns the transform FROM the refernce volume
        (usually the functional data volume) to the anatomical volume (`anat_nii` input). 

        Parameters
        ----------
        anat_nii : str or nibabel.Nifti1Image
            nibabel image object (or path to nibabel-readable image) for anatomical volume from 
            which cortical surface was created

        direction : str, optional {'func>anat', 'anat>func'}
            Direction of transform to return. Defaults to 'func>anat'

        Notes
        -----
        This function will only work for "coord" transform objects, (those retrieved with 
        cortex.db.get_xfm(xfmtype='coord',...)). It will fail hard for "magnet" transforms!

        """
        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 __HOLE__:
            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
dataset/ETHPy150Open gallantlab/pycortex/cortex/xfm.py/Transform.to_fsl