code: def threshold_activations(activations, threshold):
      """
      Threshold activations to include only the main segment exceeding the given
      threshold (i.e. first to last time/index exceeding the threshold).
  
      Parameters
      ----------
      activations : numpy array
          Activations to be thresholded.
      threshold : float
          Threshold value.
  
      Returns
      -------
      activations : numpy array
          Thresholded activations
      start : int
          Index of the first activation exceeding the threshold.
  
      Notes
      -----
  
      This function can be used to extract the main segment of beat activations
      to track only the beats where the activations exceed the threshold.
  
      """
      first = last = 0
      # use only the activations > threshold
      idx = np.nonzero(activations >= threshold)[0]
      if idx.any():
          first = max(first, np.min(idx))
          last = min(len(activations), np.max(idx) + 1)
      # return thresholded activations segment and first index
      return activations[first:last], first
  
imports: from __future__ import absolute_import, division, print_function
  import sys
  import numpy
  from ..audio.signal import signal_frame, smooth
  from ..ml.nn import average_predictions
  from ..processors import OnlineProcessor, ParallelProcessor, Processor, SequentialProcessor
label_desc: Use image node_id 4 for calling a global function with example usage: threshold_activations(activations, threshold) and returns: activations,  first