code: def parcel_input(mask_images, learning_images, ths=0.5, fdim=None):
      """Instantiating a Parcel structure from a give set of input
  
      Parameters
      ----------
      mask_images: string or Nifti1Image or list of strings/Nifti1Images,
                   paths of mask image(s) that define(s) the common space.
      learning_images: (nb_subject-) list of  (nb_feature-) list of strings,
                       paths of feature images used as input to the
                       parcellation procedure
      ths=.5: threshold to select the regions that are common across subjects.
              if ths = .5, thethreshold is half the number of subjects
      fdim: int, optional
            if nb_feature (the dimension of the data) used in subsequent analyses
            if greater than fdim,
            a PCA is performed to reduce the information in the data
            Byd efault, no reduction is performed
  
      Returns
      -------
      domain : discrete_domain.DiscreteDomain instance
          that stores the spatial information on the parcelled domain
      feature: (nb_subect-) list of arrays of shape (domain.size, fdim)
          feature information available to parcellate the data
      """
      nb_subj = len(learning_images)
  
      # get a group-level mask
      if isinstance(mask_images, str):
          mask = mask_images
      elif isinstance(mask_images, Nifti1Image):
          mask = mask_images
      else:
          # mask_images should be a list
          grp_mask = intersect_masks(mask_images, threshold=ths) > 0
          mask = Nifti1Image(
              grp_mask.astype("u1"), get_affine(load(mask_images[0]))
          )
  
      # build the domain
      domain = grid_domain_from_image(mask, nn=6)
      # nn = 6 for speed up and stability
  
      # load the functional data
      feature = []
      nbeta = len(learning_images[0])
      for s in range(nb_subj):
          if len(learning_images[s]) != nbeta:
              raise ValueError("Inconsistent number of dimensions")
          feature.append(
              np.array(
                  [
                      domain.make_feature_from_image(b)
                      for b in learning_images[s]
                  ]
              ).T
          )
  
      # Possibly reduce the dimension of the functional data
      if (len(feature[0].shape) == 1) or (fdim is None):
          return domain, feature
      if fdim < feature[0].shape[1]:
          import numpy.linalg as nl
  
          subj = np.concatenate(
              [s * np.ones(feature[s].shape[0]) for s in range(nb_subj)]
          )
          cfeature = np.concatenate(feature)
          cfeature -= np.mean(cfeature, 0)
          m1, m2, m3 = nl.svd(cfeature, 0)
          cfeature = np.dot(m1, np.diag(m2))
          cfeature = cfeature[:, 0:fdim]
          feature = [cfeature[subj == s] for s in range(nb_subj)]
  
      return domain, feature
  
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 2 for calling a global function with example usage: parcel_input(mask_images, learning_images, ths, fdim) and returns: domain,  feature, domain,  feature