Skip to content

Commit

Permalink
cov bin
Browse files Browse the repository at this point in the history
  • Loading branch information
damonge committed Dec 31, 2023
1 parent 3453260 commit 995ff86
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
12 changes: 5 additions & 7 deletions pymaster/bins.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ class NmtBin(object):
by all pseudo-Cl computations carried out using this
bandpower scheme.
"""
def __init__(self, bpws, ells, lmax=None, weights=None,
def __init__(self, *, bpws, ells, lmax=None, weights=None,
f_ell=None):
self.bin = None

if (bpws is None) or (ells is None):
raise KeyError("Must supply bandpower arrays")

if lmax is None:
lmax = np.amax(ells)
self.lmax = int(lmax)
Expand Down Expand Up @@ -231,7 +228,8 @@ def get_ell_list(self, b):
(`array`) array of multipoles associated with bandpower
``b``.
"""
return lib.get_ell_list(self.bin, b, lib.get_nell(self.bin, b))
return lib.get_ell_list(self.bin, int(b),
lib.get_nell(self.bin, int(b)))

def get_weight_list(self, b):
"""
Expand All @@ -246,8 +244,8 @@ def get_weight_list(self, b):
(`array`) weights associated to multipoles in bandpower
``b``.
"""
return lib.get_weight_list(self.bin, b,
lib.get_nell(self.bin, b))
return lib.get_weight_list(self.bin, int(b),
lib.get_nell(self.bin, int(b)))

def get_effective_ells(self):
"""
Expand Down
27 changes: 26 additions & 1 deletion pymaster/tests/test_bins.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,37 @@ def __init__(self):
self.bvf = nmt.NmtBin(lmax=self.lmax, bpws=bpws, ells=ells,
weights=weights, f_ell=fell)
self.l_edges = np.arange(2, self.lmax+2, 4, dtype=int)
self.be = nmt.NmtBin.from_edges(self.l_edges[:-1], self.l_edges[1:])
self.be = nmt.NmtBin.from_edges(self.l_edges[:-1],
self.l_edges[1:], is_Dell=True)


BT = BinTester()


def test_bins_nside():
b1 = nmt.NmtBin.from_nside_linear(nside=256, nlb=4, is_Dell=True)
b2 = nmt.NmtBin.from_lmax_linear(lmax=3*256-1, nlb=4, is_Dell=True)
ls1 = b1.get_effective_ells()
ls2 = b2.get_effective_ells()
assert np.allclose(ls1, ls2, atol=0, rtol=1E-10)


def test_bins_defaults():
ells = np.arange(BT.lmax+1, dtype=int)
bpws = ells // 4
b = nmt.NmtBin(ells=ells, bpws=bpws)
# Default ell_max
assert b.lmax == BT.lmax

# Default weights
for i in np.unique(bpws):
w = b.get_weight_list(i)
# Equal weights
assert len(np.unique(w)) == 1
# Normalised
assert np.fabs(w[0] - 1/len(w)) < 1E-5


def test_bins_errors():
# Tests raised exceptions
ells = np.arange(BT.lmax - 4, dtype=int)+2
Expand Down

0 comments on commit 995ff86

Please sign in to comment.