pyspec/spectrum.py
def avg_per_decade(k,E,nbins = 10):
    """ Averages the spectra with nbins per decade

        Parameters
        ===========
        - E is the spectrum
        - k is the original wavenumber array
        - nbins is the number of bins per decade

        Output
        ==========
        - ki: the wavenumber for the averaged spectrum
        - Ei: the averaged spectrum """

    dk = 1./nbins
    logk = np.log10(k)

    logki = np.arange(np.floor(logk.min()),np.ceil(logk.max())+dk,dk)
    Ei = np.zeros_like(logki)

    for i in range(logki.size):

        f = (logk>logki[i]-dk/2) & (logk<logki[i]+dk/2)

        if f.sum():
            Ei[i] = E[f].mean()
        else:
            Ei[i] = 0.

    ki = 10**logki
    fnnan = np.nonzero(Ei)
    Ei = Ei[fnnan]
    ki = ki[fnnan]

    return ki,Ei
 Averages the spectra with nbins per decade

        Parameters
        ===========
        - E is the spectrum
        - k is the original wavenumber array
        - nbins is the number of bins per decade

        Output
        ==========
        - ki: the wavenumber for the averaged spectrum
        - Ei: the averaged spectrum 
Averages the spectra with nbins per decade
Parameters

E is the spectrum
k is the original wavenumber array
nbins is the number of bins per decade

Output

the wavenumber for the averaged spectrum
Ei: the averaged spectrum
Averages the spectra with nbins per decade Parameters E is the spectrum k is the original wavenumber array nbins is the number of bins per decade Output the wavenumber for the averaged spectrum Ei : the averaged spectrum
def avg_per_decade(k,E,nbins = 10):
    dk = 1./nbins
    logk = np.log10(k)
    logki = np.arange(np.floor(logk.min()),np.ceil(logk.max())+dk,dk)
    Ei = np.zeros_like(logki)
    for i in range(logki.size):
        f = (logk>logki[i]-dk/2) & (logk<logki[i]+dk/2)
        if f.sum():
            Ei[i] = E[f].mean()
        else:
            Ei[i] = 0.
    ki = 10**logki
    fnnan = np.nonzero(Ei)
    Ei = Ei[fnnan]
    ki = ki[fnnan]
    return ki,Ei
def avg_per_decade ( k , E , nbins = 10 ) : dk = 1. / nbins logk = np . log10 ( k ) logki = np . arange ( np . floor ( logk . min ( ) ) , np . ceil ( logk . max ( ) ) + dk , dk ) Ei = np . zeros_like ( logki ) for i in range ( logki . size ) : f = ( logk > logki [ i ] - dk / 2 ) & ( logk < logki [ i ] + dk / 2 ) if f . sum ( ) : Ei [ i ] = E [ f ] . mean ( ) else : Ei [ i ] = 0. ki = 10 ** logki fnnan = np . nonzero ( Ei ) Ei = Ei [ fnnan ] ki = ki [ fnnan ] return ki , Ei
Averages the spectra with nbins per decade
Parameters
Averages the spectra with nbins per decade Parameters
""" Averages the spectra with nbins per decade

        Parameters
        ===========
        - E is the spectrum
        - k is the original wavenumber array
        - nbins is the number of bins per decade

        Output
        ==========
        - ki: the wavenumber for the averaged spectrum
        - Ei: the averaged spectrum """
k
E
nbins