code: def cmu2nii(Y, R, template=None):
      """
      inputs:
        Y: a number-of-timepoints by number-of-voxels numpy array containing the
           image data.  Each row of Y is an fMRI volume in the original nifti
           file.
  
        R: a number-of-voxels by 3 numpy array containing the voxel locations.
           Row indices of R match the column indices in Y.
  
        template: a filename of a .nii or .nii.gz file to be used as an image
                  template.  Header information of the outputted nifti images will
                  be read from the header file.  If this argument is ignored or
                  set to None, header information will be inferred based on the
                  R array.
  
      outputs:
        nifti_file: a filename of a .nii or .nii.gz file to be converted into
                    CMU format
  
        mask_file: a filename for a .nii or .nii.gz file to be used as a mask; all
                   zero-valued voxels in the mask will be ignored in the CMU-
                   formatted output
  
      outputs:
        img: a nibabel Nifti1Image object containing the fMRI data
      """
      Y = np.array(Y, ndmin=2)
      img = nib.load(template)
      S = img.affine
      locs = np.array(
          np.dot(R - S[:3, 3], np.linalg.inv(S[0:3, 0:3])), dtype="int"
      )
  
      data = np.zeros(tuple(list(img.shape)[0:3] + [Y.shape[0]]))
  
      # loop over data and locations to fill in activations
      for i in range(Y.shape[0]):
          for j in range(R.shape[0]):
              data[locs[j, 0], locs[j, 1], locs[j, 2], i] = Y[i, j]
  
      return nib.Nifti1Image(data, affine=img.affine)
  
imports: import numpy
  import pandas
  import nibabel
  import nilearn
  from nilearn.input_data import NiftiMasker
  import nilearn.plotting
  import matplotlib
  import matplotlib.pyplot
  import holoviews
  import timecorr
  import os
  from brainiak.factoranalysis.htfa import HTFA
  import warnings
  import seaborn
label_desc: Use image node_id 9 for calling a global function with example usage: cmu2nii(Y, R, template) and returns: nib