Skip to content

Commit 6ec307f

Browse files
authored
general mcms implemented (#237)
1 parent 1855928 commit 6ec307f

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

pymaster/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
compute_coupled_cell_flat,
100100
compute_full_master_flat,
101101
uncorr_noise_deprojection_bias,
102+
get_general_coupling_matrix,
102103
)
103104
from pymaster.covariance import ( # noqa
104105
NmtCovarianceWorkspace,

pymaster/tests/test_master.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,3 +767,36 @@ def test_fkp_normalization_errors():
767767
# Two potentially different catalog fields
768768
with pytest.raises(ValueError):
769769
nmt.NmtWorkspace.from_fields(fc, fcb, b, normalization='FKP')
770+
771+
772+
def test_general_mcmc():
773+
# Create disc mask
774+
nside = 256
775+
nell = 3*nside
776+
npix = hp.nside2npix(nside)
777+
mask = np.zeros(npix)
778+
mask[hp.query_disc(nside, [1, 0, 0], np.radians(30))] = 1
779+
780+
f0 = nmt.NmtField(mask, None, spin=0)
781+
f2 = nmt.NmtField(mask, None, spin=2)
782+
b = nmt.NmtBin.from_nside_linear(nside, nlb=10)
783+
w00 = nmt.NmtWorkspace.from_fields(f0, f0, b)
784+
w02 = nmt.NmtWorkspace.from_fields(f0, f2, b)
785+
w22 = nmt.NmtWorkspace.from_fields(f2, f2, b)
786+
787+
mcm00 = w00.get_coupling_matrix()
788+
mcm02 = w02.get_coupling_matrix().reshape([nell, 2, nell, 2])
789+
mcm02 = mcm02[:, 0, :, 0]
790+
mcm22 = w22.get_coupling_matrix().reshape([nell, 4, nell, 4])
791+
mcmee_ee = mcm22[:, 0, :, 0]
792+
mcmee_bb = mcm22[:, 0, :, 3]
793+
mcm22 = mcmee_ee + mcmee_bb
794+
795+
pclm = hp.anafast(mask)
796+
m00 = nmt.get_general_coupling_matrix(pclm, 0, 0, 0, 0)
797+
m02 = nmt.get_general_coupling_matrix(pclm, 0, 2, 0, 2)
798+
m22 = nmt.get_general_coupling_matrix(pclm, 2, 2, 2, 2)
799+
800+
assert np.amax(np.fabs(m00-mcm00)/np.amax(mcm00)) < 1E-10
801+
assert np.amax(np.fabs(m02-mcm02)/np.amax(mcm02)) < 1E-10
802+
assert np.amax(np.fabs(m22-mcm22)/np.amax(mcm22)) < 1E-10

pymaster/workspaces.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,33 @@ def compute_full_master_flat(f1, f2, b, cl_noise=None, cl_guess=None,
11721172

11731173

11741174
def get_general_coupling_matrix(pcl_mask, s1, s2, n1, n2):
1175-
""" Returns a general mode-coupling matrix
1176-
TODO
1175+
""" Returns a general mode-coupling matrix of the form
1176+
1177+
.. math::
1178+
M_{\\ell \\ell'}=\\sum_{\\ell''}
1179+
\\frac{(2\\ell'+1)(2\\ell''+1)}{4\\pi}
1180+
\\tilde{C}^{uv}_\\ell
1181+
\\left(\\begin{array}{ccc}
1182+
\\ell & \\ell' & \\ell'' \\\\
1183+
n_1 & -s_1 & s_1-n_1
1184+
\\end{array}\\right)
1185+
\\left(\\begin{array}{ccc}
1186+
\\ell & \\ell' & \\ell'' \\\\
1187+
n_2 & -s_2 & s_2-n_2
1188+
\\end{array}\\right)
1189+
1190+
Args:
1191+
pcl_mask (`array`): 1D array containing the power spectrum
1192+
of the masks :math:`\\tilde{C}_\\ell^{uw}`.
1193+
s1 (:obj:`int`): spin index :math:`s_1` above.
1194+
s2 (:obj:`int`): spin index :math:`s_2` above.
1195+
n1 (:obj:`int`): spin index :math:`n_1` above.
1196+
n2 (:obj:`int`): spin index :math:`n_2` above.
1197+
1198+
Returns:
1199+
(`array`): 2D array of shape ``[nl, nl]``, where ``nl`` is
1200+
the size of ``pcl_mask``, containing the mode-coupling
1201+
matrix for multipoles from 0 to ``nl-1``.
11771202
"""
11781203

11791204
lmax = len(pcl_mask)-1

0 commit comments

Comments
 (0)