code: def write_parcellation_images(
      Pa, template_path=None, indiv_path=None, subject_id=None, swd=None
  ):
      """Write images that describe the spatial structure of the parcellation
  
      Parameters
      ----------
      Pa : MultiSubjectParcellation instance,
           the description of the parcellation
      template_path: string, optional,
                     path of the group-level parcellation image
      indiv_path: list of strings, optional
                  paths of the individual parcellation images
      subject_id: list of strings of length Pa.nb_subj
                  subject identifiers, used to infer the paths when not available
      swd: string, optional
           output directory used to infer the paths when these are not available
      """
      # argument check
      if swd is None:
          from tempfile import mkdtemp
  
          swd = mkdtemp()
  
      if subject_id is None:
          subject_id = ["subj_%04d" % s for s in range(Pa.nb_subj)]
  
      if len(subject_id) != Pa.nb_subj:
          raise ValueError("subject_id does not match parcellation")
  
      # If necessary, generate the paths
      if template_path is None:
          template_path = os.path.join(swd, "template_parcel.nii")
      if indiv_path is None:
          indiv_path = [
              os.path.join(swd, f"parcel{subject_id[s]}.nii")
              for s in range(Pa.nb_subj)
          ]
  
      # write the template image
      tlabs = Pa.template_labels.astype(np.int16)
      template = SubDomains(Pa.domain, tlabs)
      template_img = template.to_image(
          fid="id",
          roi=True,
          descrip="Intra-subject parcellation template",
      )
      save(template_img, template_path)
  
      # write subject-related stuff
      for s in range(Pa.nb_subj):
          # write the individual label images
          labs = Pa.individual_labels[:, s]
          parcellation = SubDomains(Pa.domain, labs)
          parcellation_img = parcellation.to_image(
              fid="id", roi=True, descrip="Intra-subject parcellation"
          )
          save(parcellation_img, indiv_path[s])
  
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 3 for calling a global function with example usage: write_parcellation_images(Pa, template_path, indiv_path, subject_id, swd) without return types