original_docstring: 
          Load a transform into the surface database. If the transform exists already, update it
          If it does not exist, copy the reference epi into the filestore and insert.
  
          Parameters
          ----------
          subject : str
              Name of the subject
          name : str
              Name to identify the transform
          xfm : (4,4) array
              The affine transformation matrix
          xfmtype : str, optional
              Type of the provided transform, either magnet space or coord space.
              Defaults to 'magnet'.
          reference : str, optional
              The nibabel-compatible reference image associated with this transform.
              Required if name not in database
          
docstring: Load a transform into the surface database. If the transform exists already, update it
  If it does not exist, copy the reference epi into the filestore and insert.
  
  Parameters
  
  subject : str
  Name of the subject
  name : str
  Name to identify the transform
  xfm : (4,4) array
  The affine transformation matrix
  xfmtype : str, optional
  Type of the provided transform, either magnet space or coord space.
  Defaults to 'magnet'.
  reference : str, optional
  The nibabel-compatible reference image associated with this transform.
  Required if name not in database
docstring_tokens: Load a transform into the surface database . If the transform exists already update it If it does not exist copy the reference epi into the filestore and insert . Parameters subject : str Name of the subject name : str Name to identify the transform xfm : ( 4 4 ) array The affine transformation matrix xfmtype : str optional Type of the provided transform either magnet space or coord space . Defaults to ' magnet ' . reference : str optional The nibabel - compatible reference image associated with this transform . Required if name not in database
code: def save_xfm(self, subject, name, xfm, xfmtype="magnet", reference=None):
          """
          Load a transform into the surface database. If the transform exists already, update it
          If it does not exist, copy the reference epi into the filestore and insert.
  
          Parameters
          ----------
          subject : str
              Name of the subject
          name : str
              Name to identify the transform
          xfm : (4,4) array
              The affine transformation matrix
          xfmtype : str, optional
              Type of the provided transform, either magnet space or coord space.
              Defaults to 'magnet'.
          reference : str, optional
              The nibabel-compatible reference image associated with this transform.
              Required if name not in database
          """
          if xfmtype not in ["magnet", "coord"]:
              raise TypeError("Unknown transform type")
  
          import nibabel
  
          path = os.path.join(self.filestore, subject, "transforms", name)
          fname = os.path.join(path, "matrices.xfm")
          if os.path.exists(fname):
              jsdict = json.load(open(fname))
          else:
              os.mkdir(path)
              if reference is None:
                  raise ValueError("Please specify a reference")
              fpath = os.path.join(path, "reference.nii.gz")
              nib = nibabel.load(reference)
              data = nib.get_data()
              if len(data.shape) > 3:
                  import warnings
                  warnings.warn('You are importing a 4D dataset, automatically selecting the first volume as reference')
                  data = data[...,0]
              out = nibabel.Nifti1Image(data, nib.get_affine(), header=nib.get_header())
              nibabel.save(out, fpath)
  
              jsdict = dict()
  
          nib = nibabel.load(os.path.join(path, "reference.nii.gz"))
          if xfmtype == "magnet":
              jsdict['magnet'] = xfm.tolist()
              jsdict['coord'] = np.dot(np.linalg.inv(nib.get_affine()), xfm).tolist()
          elif xfmtype == "coord":
              jsdict['coord'] = xfm.tolist()
              jsdict['magnet'] = np.dot(nib.get_affine(), xfm).tolist()
          
          files = self.get_paths(subject)
          if len(glob.glob(files['masks'].format(xfmname=name, type="*"))) > 0:
              raise ValueError('Refusing to change a transform with masks')
              
          json.dump(jsdict, open(fname, "w"), sort_keys=True, indent=4)
code_tokens: def save_xfm ( self , subject , name , xfm , xfmtype = "magnet" , reference = None ) : if xfmtype not in [ "magnet" , "coord" ] : raise TypeError ( "Unknown transform type" ) import nibabel path = os . path . join ( self . filestore , subject , "transforms" , name ) fname = os . path . join ( path , "matrices.xfm" ) if os . path . exists ( fname ) : jsdict = json . load ( open ( fname ) ) else : os . mkdir ( path ) if reference is None : raise ValueError ( "Please specify a reference" ) fpath = os . path . join ( path , "reference.nii.gz" ) nib = nibabel . load ( reference ) data = nib . get_data ( ) if len ( data . shape ) > 3 : import warnings warnings . warn ( 'You are importing a 4D dataset, automatically selecting the first volume as reference' ) data = data [ ... , 0 ] out = nibabel . Nifti1Image ( data , nib . get_affine ( ) , header = nib . get_header ( ) ) nibabel . save ( out , fpath ) jsdict = dict ( ) nib = nibabel . load ( os . path . join ( path , "reference.nii.gz" ) ) if xfmtype == "magnet" : jsdict [ 'magnet' ] = xfm . tolist ( ) jsdict [ 'coord' ] = np . dot ( np . linalg . inv ( nib . get_affine ( ) ) , xfm ) . tolist ( ) elif xfmtype == "coord" : jsdict [ 'coord' ] = xfm . tolist ( ) jsdict [ 'magnet' ] = np . dot ( nib . get_affine ( ) , xfm ) . tolist ( ) files = self . get_paths ( subject ) if len ( glob . glob ( files [ 'masks' ] . format ( xfmname = name , type = "*" ) ) ) > 0 : raise ValueError ( 'Refusing to change a transform with masks' ) json . dump ( jsdict , open ( fname , "w" ) , sort_keys = True , indent = 4 )
short_docstring: Load a transform into the surface database.
short_docstring_tokens: Load a transform into the surface database .
comment: """
          Load a transform into the surface database. If the transform exists already, update it
          If it does not exist, copy the reference epi into the filestore and insert.
  
          Parameters
          ----------
          subject : str
              Name of the subject
          name : str
              Name to identify the transform
          xfm : (4,4) array
              The affine transformation matrix
          xfmtype : str, optional
              Type of the provided transform, either magnet space or coord space.
              Defaults to 'magnet'.
          reference : str, optional
              The nibabel-compatible reference image associated with this transform.
              Required if name not in database
          """