code: def hparcel(
      domain,
      ldata,
      nb_parcel,
      nb_perm=0,
      niter=5,
      mu=10.0,
      dmax=10.0,
      lamb=100.0,
      chunksize=1.0e5,
      verbose=0,
      initial_mask=None,
  ):
      """
      Function that performs the parcellation by optimizing the
      inter-subject similarity while retaining the connectedness
      within subject and some consistency across subjects.
  
      Parameters
      ----------
      domain: discrete_domain.DiscreteDomain instance,
              yields all the spatial information on the parcelled domain
      ldata: list of (n_subj) arrays of shape (domain.size, dim)
             the feature data used to inform the parcellation
      nb_parcel: int,
                 the number of parcels
      nb_perm: int, optional,
               the number of times the parcellation and prfx
               computation is performed on sign-swaped data
      niter: int, optional,
             number of iterations to obtain the convergence of the method
             information in the clustering algorithm
      mu: float, optional,
          relative weight of anatomical information
      dmax: float optional,
            radius of allowed deformations
      lamb: float optional
            parameter to control the relative importance of space vs function
      chunksize; int, optional
                 number of points used in internal sub-sampling
      verbose: bool, optional,
               verbosity mode
      initial_mask: array of shape (domain.size, nb_subj), optional
                    initial subject-depedent masking of the domain
  
      Returns
      -------
      Pa: the resulting parcellation structure appended with the labelling
      """
      # a various parameters
      nbvox = domain.size
      nb_subj = len(ldata)
      if initial_mask is None:
          initial_mask = np.ones((nbvox, nb_subj), np.int_)
  
      graphs = []
      feature = []
  
      for s in range(nb_subj):
          # build subject-specific models of the data
          lnvox = np.sum(initial_mask[:, s] > -1)
          lac = domain.coord[initial_mask[:, s] > -1]
          beta = np.reshape(ldata[s], (lnvox, ldata[s].shape[1]))
          lf = np.hstack(
              (beta, mu * lac / (1.0e-15 + np.std(domain.coord, 0)))
          )
          feature.append(lf)
          g = wgraph_from_coo_matrix(domain.topology)
          g.remove_trivial_edges()
          graphs.append(g)
  
      # main function
      all_labels, proto_anat = _optim_hparcel(
          feature,
          domain,
          graphs,
          nb_parcel,
          lamb,
          dmax,
          niter,
          initial_mask,
          chunksize=chunksize,
          verbose=verbose,
      )
  
      # write the individual labelling
      labels = -np.ones((nbvox, nb_subj)).astype(np.int_)
      for s in range(nb_subj):
          labels[initial_mask[:, s] > -1, s] = all_labels[s]
  
      # compute the group-level labels
      template_labels = voronoi(domain.coord, proto_anat)
  
      # create the parcellation
      pcl = MultiSubjectParcellation(
          domain,
          individual_labels=labels,
          template_labels=template_labels,
          nb_parcel=nb_parcel,
      )
      pcl.make_feature("functional", np.rollaxis(np.array(ldata), 1, 0))
  
      if nb_perm > 0:
          prfx0 = perm_prfx(
              domain,
              graphs,
              feature,
              nb_parcel,
              ldata,
              initial_mask,
              nb_perm,
              niter,
              dmax,
              lamb,
              chunksize,
          )
          return pcl, prfx0
      else:
          return pcl
  
file_path: nipy/nipy/labs/spatial_models/hierarchical_parcellation.py
imports: from warnings import warn
  import numpy
  from numpy.random import rand
  from nipy.algorithms.clustering.utils import kmeans, voronoi
  from nipy.algorithms.graph.field import Field
  from nipy.algorithms.graph.graph import wgraph_from_coo_matrix
  from .parcellation import MultiSubjectParcellation
label_desc: Use image node_id 9 for calling a global function with example usage: hparcel(domain, ldata, nb_parcel, nb_perm, niter, mu, dmax, lamb, chunksize, verbose, initial_mask) and returns: pcl,  prfx0, pcl