pyspec/spectrum.py
def calc_ispec(k,l,E,ndim=2):
    """ Calculates the azimuthally-averaged spectrum

        Parameters
        ===========
        - E is the two-dimensional spectrum
        - k is the wavenumber is the x-direction
        - l is the wavenumber in the y-direction

        Output
        ==========
        - kr: the radial wavenumber
        - Er: the azimuthally-averaged spectrum """

    dk = np.abs(k[2]-k[1])
    dl = np.abs(l[2]-l[1])

    k, l = np.meshgrid(k,l)

    wv = np.sqrt(k**2+l**2)

    if k.max()>l.max():
        kmax = l.max()
    else:
        kmax = k.max()

    if ndim==3:
        nl, nk, nomg = E.shape
    elif ndim==2:
        nomg = 1

    dkr = np.sqrt(dk**2 + dl**2)
    kr =  np.arange(dkr/2.,kmax+dkr/2.,dkr)
    Er = np.zeros((kr.size,nomg))


    for i in range(kr.size):

        fkr =  (wv>=kr[i]-dkr/2) & (wv<=kr[i]+dkr/2)
        dth = np.pi / (fkr.sum()-1)
        if ndim==2:
            Er[i] = (E[fkr]*(wv[fkr]*dth)).sum()
        elif ndim==3:
            Er[i] = (E[fkr]*(wv[fkr]*dth)).sum(axis=(0,1))


    return kr, Er.squeeze()
 Calculates the azimuthally-averaged spectrum

        Parameters
        ===========
        - E is the two-dimensional spectrum
        - k is the wavenumber is the x-direction
        - l is the wavenumber in the y-direction

        Output
        ==========
        - kr: the radial wavenumber
        - Er: the azimuthally-averaged spectrum 
Calculates the azimuthally-averaged spectrum
Parameters

E is the two-dimensional spectrum
k is the wavenumber is the x-direction
l is the wavenumber in the y-direction

Output

the radial wavenumber
Er: the azimuthally-averaged spectrum
Calculates the azimuthally - averaged spectrum Parameters E is the two - dimensional spectrum k is the wavenumber is the x - direction l is the wavenumber in the y - direction Output the radial wavenumber Er : the azimuthally - averaged spectrum
def calc_ispec(k,l,E,ndim=2):
    dk = np.abs(k[2]-k[1])
    dl = np.abs(l[2]-l[1])
    k, l = np.meshgrid(k,l)
    wv = np.sqrt(k**2+l**2)
    if k.max()>l.max():
        kmax = l.max()
    else:
        kmax = k.max()
    if ndim==3:
        nl, nk, nomg = E.shape
    elif ndim==2:
        nomg = 1
    dkr = np.sqrt(dk**2 + dl**2)
    kr =  np.arange(dkr/2.,kmax+dkr/2.,dkr)
    Er = np.zeros((kr.size,nomg))
    for i in range(kr.size):
        fkr =  (wv>=kr[i]-dkr/2) & (wv<=kr[i]+dkr/2)
        dth = np.pi / (fkr.sum()-1)
        if ndim==2:
            Er[i] = (E[fkr]*(wv[fkr]*dth)).sum()
        elif ndim==3:
            Er[i] = (E[fkr]*(wv[fkr]*dth)).sum(axis=(0,1))
    return kr, Er.squeeze()
def calc_ispec ( k , l , E , ndim = 2 ) : dk = np . abs ( k [ 2 ] - k [ 1 ] ) dl = np . abs ( l [ 2 ] - l [ 1 ] ) k , l = np . meshgrid ( k , l ) wv = np . sqrt ( k ** 2 + l ** 2 ) if k . max ( ) > l . max ( ) : kmax = l . max ( ) else : kmax = k . max ( ) if ndim == 3 : nl , nk , nomg = E . shape elif ndim == 2 : nomg = 1 dkr = np . sqrt ( dk ** 2 + dl ** 2 ) kr = np . arange ( dkr / 2. , kmax + dkr / 2. , dkr ) Er = np . zeros ( ( kr . size , nomg ) ) for i in range ( kr . size ) : fkr = ( wv >= kr [ i ] - dkr / 2 ) & ( wv <= kr [ i ] + dkr / 2 ) dth = np . pi / ( fkr . sum ( ) - 1 ) if ndim == 2 : Er [ i ] = ( E [ fkr ] * ( wv [ fkr ] * dth ) ) . sum ( ) elif ndim == 3 : Er [ i ] = ( E [ fkr ] * ( wv [ fkr ] * dth ) ) . sum ( axis = ( 0 , 1 ) ) return kr , Er . squeeze ( )
Calculates the azimuthally-averaged spectrum
Parameters
Calculates the azimuthally - averaged spectrum Parameters
""" Calculates the azimuthally-averaged spectrum

        Parameters
        ===========
        - E is the two-dimensional spectrum
        - k is the wavenumber is the x-direction
        - l is the wavenumber in the y-direction

        Output
        ==========
        - kr: the radial wavenumber
        - Er: the azimuthally-averaged spectrum """
k
l
E
ndim