Commit 4ff18c12 authored by Maude Le Jeune's avatar Maude Le Jeune
Browse files

doctest, PEP 8

parent 888e25c1
......@@ -47,7 +47,7 @@ def get_binMatrix(bins, btype='flat', lmax=None):
elif btype=='llp1':
Mbins[q,rg] = rg*(rg+1)*(2*rg+1)
else:
return "unknown btype (should be flat or llp1)"
raise Exception("unknown btype (should be flat or llp1)")
nrm = np.sum(Mbins[q,rg])
Mbins[q,rg] /= 1.0*nrm
return Mbins
......@@ -91,7 +91,7 @@ def bin_covariance(covmat, bins, nmode=None):
bincov[:,:,q] = tmpcov
return bincov
def uniformbin (lstart, lstop, deltal):
def uniformbin(lstart, lstop, deltal):
""" Return description of flat bins of constant length.
>>> uniformbin(0,10,2)
......@@ -149,7 +149,7 @@ def get_nmode(bins, btype='flat'):
rg = np.arange(bins.shape[1])
nmode[q] /= 1.*np.sum(bins[q,:]**4/(2*rg+1))
else:
return 'unknown btype (should be flat or llp1)'
raise Exception("unknown btype (should be flat or llp1)")
return nmode
def gaussbeam(fwhm_arcmin, lmax):
......@@ -209,7 +209,7 @@ def smooth_cl(cl, dloverl=0.1, width=None, n=0):
else:
return clsmooth
def bin_cl (cl, bins):
def bin_cl(cl, bins):
""" Return binned power spectrum.
>>> bin_cl(np.arange(10), uniformbin(0,9,2))
......@@ -226,7 +226,7 @@ def bin_cl (cl, bins):
return cq
def unbin_cl (cq, bins):
def unbin_cl(cq, bins):
""" Return unbinned power spectrum.
>>> b = uniformbin(0,9,2)
......@@ -243,7 +243,7 @@ def unbin_cl (cq, bins):
cl[rg] = cq[q]
return cl
def make_prolate (bands, rule=1, thetas=[]):
def make_prolate(bands, rule=1, thetas=[]):
""" Build prolate window functions.
bands is a list of integers defining windows limits.
......@@ -269,7 +269,7 @@ def make_prolate (bands, rule=1, thetas=[]):
spherelib_bin._make_prolate(bands, bins, thetas, rule)
return np.squeeze(bins.T)
def make_spline (bands, order=3):
def make_spline(bands, order=3):
""" Build spline window functions.
>>> make_spline([0,5,10])
......@@ -280,30 +280,30 @@ def make_spline (bands, order=3):
nwin = len(bands)-2
bands = array(bands, dtype=int32)
bins = zeros((nwin, lmax+1), dtype=float64)
spherelib_bin._make_spline (bands, bins, order)
spherelib_bin._make_spline(bands, bins, order)
return np.squeeze(bins.T)
def norm_cl (cl, type="sphere"):
def norm_cl(cl, type="sphere"):
""" Return re-normalized spectra.
cl: array-like, cl values (lmax+1)
type: string. 'sphere': normalised in energy w.r.t. the nb of spherical modes
'line' : normalized in energy as an ell**2(N) function
'max' : normalized as an ell**infinity(N) function (with maximum value = 1)
type: 'sphere': normalised in energy w.r.t. the nb of spherical modes
'line' : normalized in energy as an ell**2(N) function
'max' : normalized as an ell**infinity(N) function (with maximum value = 1)
>>> norm_cl(np.arange(5))
array([ 0. , 0.23374429, 0.46748858, 0.70123288, 0.93497717])
"""
lmax = len(cl)-1
ELL = arange(lmax+1)
ELL = np.arange(lmax+1)
if type=='sphere':
norm = sum( (cl**2) * (2*ELL+1) ) / (4*pi)
norm = np.sum((cl**2) * (2*ELL+1) ) / (4*pi)
elif type=='line':
norm = sum( cl**2 )
norm = np.sum(cl**2)
elif type=="max":
norm = max(abs(cl))**2
norm = max(np.abs(cl))**2
else:
raise Exception ("norm_cl: norm must be one of the following: \"sphere\", \"line\", \"max\" ");
raise Exception("norm_cl: norm must be one of the following: \"sphere\", \"line\", \"max\" ");
return cl*( norm**(-0.5) )
if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment