def __trim_beats(localscore, beats, trim):
smooth_boe = scipy.signal.convolve(localscore[beats],<EOL>scipy.signal.hann(<NUM_LIT:5>),<EOL>'<STR_LIT>')<EOL>if trim:<EOL><INDENT>threshold = <NUM_LIT:0.5> * ((smooth_boe**<NUM_LIT:2>).mean()**<NUM_LIT:0.5>)<EOL><DEDENT>else:<EOL><INDENT>threshold = <NUM_LIT:0.0><EOL><DEDENT>valid = np.argwhere(smooth_boe > threshold)<EOL>return beats[valid.min():valid.max()]<EOL>
Final post-processing: throw out spurious leading/trailing beats