code: def __trim_beats(
      localscore: np.ndarray, beats: np.ndarray, trim: bool
  ) -> np.ndarray:
      """Remove spurious leading and trailing beats"""
      smooth_boe = scipy.signal.convolve(
          localscore[beats],
          scipy.signal.get_window("hann", 5, fftbins=False),
          "same",
      )
  
      if trim:
          threshold = 0.5 * ((smooth_boe**2).mean() ** 0.5)
      else:
          threshold = 0.0
  
      valid = np.argwhere(smooth_boe > threshold)
  
      return beats[valid.min() : valid.max()]
  
file_path: librosa/librosa/beat.py
imports: import numpy
  import scipy
  import scipy.stats
  from ._cache import cache
  from .None import core
  from .None import onset
  from .None import util
  from .feature import tempogram, fourier_tempogram
  from .feature import tempo
  from .util.exceptions import ParameterError
  from .util.decorators import moved
  from typing import Any, Callable, Optional, Tuple
label_desc: Use image node_id 8 for calling a global function with example usage: __trim_beats(localscore, beats, trim) and returns: beats