code: def parcellation_based_analysis(
      Pa,
      test_images,
      test_id="one_sample",
      rfx_path=None,
      condition_id="",
      swd=None,
  ):
      """This function computes parcel averages and RFX at the parcel-level
  
      Parameters
      ----------
      Pa: MultiSubjectParcellation instance
          the description of the parcellation
      test_images: (Pa.nb_subj-) list of paths
                   paths of images used in the inference procedure
      test_id: string, optional,
            if test_id=='one_sample', the one_sample statstic is computed
            otherwise, the parcel-based signal averages are returned
      rfx_path: string optional,
                path of the resulting one-sample test image, if applicable
      swd: string, optional
           output directory used to compute output path if rfx_path is not given
      condition_id: string, optional,
                    contrast/condition id  used to compute output path
  
      Returns
      -------
      test_data: array of shape(Pa.nb_parcel, Pa.nb_subj)
                 the parcel-level signal average if test is not 'one_sample'
      prfx: array of shape(Pa.nb_parcel),
            the one-sample t-value if test_id is 'one_sample'
      """
      nb_subj = Pa.nb_subj
  
      # 1. read the test data
      if len(test_images) != nb_subj:
          raise ValueError("Inconsistent number of test images")
  
      test = np.array(
          [Pa.domain.make_feature_from_image(ti) for ti in test_images]
      ).T
      test_data = Pa.make_feature("", np.array(test))
  
      if test_id != "one_sample":
          return test_data
  
      # 2. perform one-sample test
      # computation
      from ..utils.reproducibility_measures import ttest
  
      prfx = ttest(test_data)
  
      # Write the stuff
      template = SubDomains(Pa.domain, Pa.template_labels)
      template.set_roi_feature("prfx", prfx)
      wim = template.to_image("prfx", roi=True)
      hdr = get_header(wim)
      hdr[
          "descrip"
      ] = "parcel-based random effects image (in t-variate)"
      if rfx_path is not None:
          save(wim, rfx_path)
  
      return prfx
  
file_path: nipy/nipy/labs/spatial_models/parcel_io.py
imports: import os.path
  from warnings import warn
  import numpy
  from nibabel import Nifti1Image, load, save
  from nipy.algorithms.clustering.utils import kmeans
  from nipy.io.nibcompat import get_affine, get_header
  from ..mask import intersect_masks
  from .discrete_domain import grid_domain_from_image
  from .mroi import SubDomains
label_desc: Use image node_id 4 for calling a global function with example usage: parcellation_based_analysis(Pa, test_images, test_id, rfx_path, condition_id, swd) and returns: prfx, test_data