def _safe_snr_calculation(s, n):
    """
    Helper used in this module for all snr calculations.   snr is
    always defined as a ratio of signal amplitude divided by noise amplitude.
    An issue is that with simulation data it is very common to have a noise
    window that is pure zeros.   If computed naively snr would then be
    normally be returned as NaN.  NaNs can cause a lot of mysterious errors
    so we handle that differently here.  When noise amplitude is 0 we
    then test the signal amplitude.  If it is nonzero we return large
    number defined inside this function as 999999.9 (just under 1 million).
    If both amplitudes are zero we return -1.0 which can be properly treated
    as an error or data with low snr.
    """
    if n == 0.0:
        if s > 0.0:
            return 999999.9
        else:
            return -1.0
    else:
        return s / n