code: def find_cut_coords(map, mask=None, activation_threshold=None):
      """Find the center of the largest activation connect component.
  
      Parameters
      -----------
      map : 3D ndarray
          The activation map, as a 3D image.
      mask : 3D ndarray, boolean, optional
          An optional brain mask.
      activation_threshold : float, optional
          The lower threshold to the positive activation. If None, the
          activation threshold is computed using find_activation.
  
      Returns
      -------
      x: float
          the x coordinate in voxels.
      y: float
          the y coordinate in voxels.
      z: float
          the z coordinate in voxels.
      """
      # 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(map, "mask"):
          not_mask = np.logical_not(map.mask)
          if mask is None:
              mask = not_mask
          else:
              mask *= not_mask
          map = np.asarray(map)
      my_map = map.copy()
      if mask is not None:
          slice_x, slice_y, slice_z = ndimage.find_objects(mask)[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() == 0) and (my_map.min() == 0):
          return 0.5 * np.array(map.shape)
      if activation_threshold is None:
          activation_threshold = stats.scoreatpercentile(
              np.abs(my_map[my_map != 0]).ravel(), 80
          )
      mask = np.abs(my_map) > activation_threshold - 1.0e-15
      mask = largest_cc(mask)
      slice_x, slice_y, slice_z = ndimage.find_objects(mask)[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_cc(second_mask)
      cut_coords = ndimage.center_of_mass(np.abs(my_map))
      return cut_coords + offset
  
file_path: nipy/nipy/labs/viz_tools/coord_tools.py
imports: import warnings
  import numpy
  from scipy import ndimage, stats
  from ..datasets.transforms.affine_utils import get_bounds
  from ..mask import largest_cc
label_desc: Use image node_id 2 for calling a global function with example usage: find_cut_coords(map, mask, activation_threshold) and returns: unknown, unknown