Why not instead just take the ratio of the amplitudes of the "loudest" second and the "quietest" second?
def signaltonoise(tr):
# Here we just make an estimate of the signal-to-noise ratio
#
# Normally the trace should be pre-processed before passing to this routine, e.g.
# * remove ridiculously large values
# * remove any sequences of 0 from start or end
# * detrend
# * bandpass filter
#
# Processing:
# 1. ensure we have at least 1 seconds
# 2. take absolute values
# 3. compute the maximum of each 1-s of data, call this time series M
# 4. compute 95th and 5th percentile of M, call these M95 and M5
# 5. estimate signal-to-noise ratio as M95/M5
#
# Correction. The above seems like a poor algorithm. Why not instead just take the ratio of the amplitudes of
# the "loudest" second and the "quietest" second.