code: def subdomain_from_balls(domain, positions, radii):
      """Create discrete ROIs as a set of balls within a certain
      coordinate systems.
  
      Parameters
      ----------
      domain: StructuredDomain instance,
          the description of a discrete domain
      positions: array of shape(k, dim):
          the positions of the balls
      radii: array of shape(k):
          the sphere radii
  
      """
      # checks
      if np.size(positions) == positions.shape[0]:
          positions = np.reshape(positions, (positions.size), 1)
      if positions.shape[1] != domain.em_dim:
          raise ValueError(
              "incompatible dimensions for domain and positions"
          )
      if positions.shape[0] != np.size(radii):
          raise ValueError("incompatible positions and radii provided")
  
      label = -np.ones(domain.size)
  
      for k in range(radii.size):
          supp = (
              np.sum((domain.coord - positions[k]) ** 2, 1)
              < radii[k] ** 2
          )
          label[supp] = k
  
      return SubDomains(domain, label)
  
imports: import numpy
  from nibabel import Nifti1Image, load
  from nipy.io.nibcompat import get_affine, get_header
  from .None import discrete_domain
label_desc: Use image node_id 4 for calling a global function with example usage: subdomain_from_balls(domain, positions, radii) and returns: SubDomains