code: def find_xyz_cut_coords(
      img, mask_img=None, activation_threshold=None
  ):
      """Find the center of the largest activation connected component.
  
      Parameters
      ----------
      img : 3D Nifti1Image
          The brain map.
  
      mask_img : 3D Nifti1Image, optional
          An optional brain mask, provided mask_img should not be empty.
  
      activation_threshold : float, optional
          The lower threshold to the positive activation. If None, the
          activation threshold is computed using the 80% percentile of
          the absolute value of the map.
  
      Returns
      -------
      x : float
          The x world coordinate.
  
      y : float
          The y world coordinate.
  
      z : float
          The z world coordinate.
  
      """
      # if a pseudo-4D image or several images were passed (cf. #922),
      # we reduce to a single 3D image to find the coordinates
      img = check_niimg_3d(img)
      data = safe_get_data(img)
  
      # when given image is empty, return (0., 0., 0.)
      if np.all(data == 0.0):
          warnings.warn(
              "Given img is empty. "
              f"Returning default cut_coords={DEFAULT_CUT_COORDS} instead."
          )
          x_map, y_map, z_map = DEFAULT_CUT_COORDS
          return np.asarray(
              coord_transform(x_map, y_map, z_map, img.affine)
          ).tolist()
  
      # Retrieve optional mask
      if mask_img is not None:
          mask_img = check_niimg_3d(mask_img)
          mask = safe_get_data(mask_img)
          if not np.allclose(mask_img.affine, img.affine):
              raise ValueError(
                  f"Mask affine: \n{mask_img.affine}\n "
                  f"is different from img affine: \n{img.affine}"
              )
      else:
          mask = None
  
      # To speed up computations, we work with partial views of the array,
      # and keep track of the offset
      offset = np.zeros(3)
  
      # Deal with masked arrays:
      if hasattr(data, "mask"):
          not_mask = np.logical_not(data.mask)
          if mask is None:
              mask = not_mask
          else:
              mask *= not_mask
          data = np.asarray(data)
  
      # Get rid of potential memmapping
      data = as_ndarray(data)
      my_map = data.copy()
      if mask is not None:
          # check against empty mask
          if mask.sum() == 0.0:
              warnings.warn(
                  "Could not determine cut coords: "
                  "Provided mask is empty. "
                  "Returning center of mass instead."
              )
              cut_coords = center_of_mass(np.abs(my_map)) + offset
              x_map, y_map, z_map = cut_coords
              return np.asarray(
                  coord_transform(x_map, y_map, z_map, img.affine)
              ).tolist()
          slice_x, slice_y, slice_z = find_objects(mask.astype(int))[0]
          my_map = my_map[slice_x, slice_y, slice_z]
          mask = mask[slice_x, slice_y, slice_z]
          my_map *= mask
          offset += [slice_x.start, slice_y.start, slice_z.start]
      # Testing min and max is faster than np.all(my_map == 0)
      if my_map.max() == my_map.min() == 0:
          warnings.warn(
              "Could not determine cut coords: "
              "All values were masked. "
              "Returning center of mass of unmasked data instead."
          )
          # Call center of mass on initial data since my_map is zero.
          # Therefore, do not add offset to cut_coords.
          cut_coords = center_of_mass(np.abs(data))
          x_map, y_map, z_map = cut_coords
          return np.asarray(
              coord_transform(x_map, y_map, z_map, img.affine)
          ).tolist()
      if activation_threshold is None:
          activation_threshold = fast_abs_percentile(
              my_map[my_map != 0].ravel(), 80
          )
      try:
          eps = 2 * np.finfo(activation_threshold).eps
      except ValueError:
          # The above will fail for exact types, eg integers
          eps = 1e-15
  
      mask = np.abs(my_map) > (activation_threshold - eps)
      # mask may be zero everywhere in rare cases
      if mask.max() == 0:
          warnings.warn(
              "Could not determine cut coords: "
              "All voxels were masked by the thresholding. "
              "Returning the center of mass instead."
          )
          cut_coords = center_of_mass(np.abs(my_map)) + offset
          x_map, y_map, z_map = cut_coords
          return np.asarray(
              coord_transform(x_map, y_map, z_map, img.affine)
          ).tolist()
  
      mask = largest_connected_component(mask)
      slice_x, slice_y, slice_z = find_objects(mask.astype(int))[0]
      my_map = my_map[slice_x, slice_y, slice_z]
      mask = mask[slice_x, slice_y, slice_z]
      my_map *= mask
      offset += [slice_x.start, slice_y.start, slice_z.start]
  
      # For the second threshold, we use a mean, as it is much faster,
      # although it is less robust
      second_threshold = np.abs(np.mean(my_map[mask]))
      second_mask = np.abs(my_map) > second_threshold
      if second_mask.sum() > 50:
          my_map *= largest_connected_component(second_mask)
      cut_coords = center_of_mass(np.abs(my_map))
      x_map, y_map, z_map = cut_coords + offset
  
      # Return as a list of scalars
      return np.asarray(
          coord_transform(x_map, y_map, z_map, img.affine)
      ).tolist()
  
file_path: nilearn/nilearn/plotting/find_cuts.py
imports: import numbers
  import warnings
  import numpy
  from scipy.ndimage import center_of_mass, find_objects, label
  from nilearn.image import get_data
  from .._utils import check_niimg_3d, check_niimg_4d
  from .._utils.extmath import fast_abs_percentile
  from .._utils.ndimage import largest_connected_component
  from .._utils.niimg import safe_get_data
  from .._utils.numpy_conversions import as_ndarray
  from ..image import iter_img, new_img_like, reorder_img
  from ..image.image import smooth_array
  from ..image.resampling import coord_transform, get_mask_bounds
label_desc: Use image node_id 1 for calling a global function with example usage: find_xyz_cut_coords(img, mask_img, activation_threshold) and returns: np, np, np, np, np