Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
spherelib
Spherelib
Commits
4ff18c12
Commit
4ff18c12
authored
May 02, 2016
by
Maude Le Jeune
Browse files
doctest, PEP 8
parent
888e25c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
20 deletions
+20
-20
python/spherelib/bin.py
python/spherelib/bin.py
+20
-20
No files found.
python/spherelib/bin.py
View file @
4ff18c12
...
...
@@ -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
:
r
eturn
"unknown btype (should be flat or llp1)"
r
aise
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
:
r
eturn
'
unknown btype (should be flat or llp1)
'
r
aise
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__"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment