|
22 | 22 | from itertools import combinations |
23 | 23 | from ..utils import add_to_Cls, sub_to_Cls |
24 | 24 | from ..core import update_metadata |
25 | | -from ..result import Result, get_result_array |
| 25 | +from ..result import Result, get_result_array, binned |
26 | 26 | from ..mapping import transform |
27 | 27 | from ..twopoint import angular_power_spectra |
28 | | -from ..unmixing import _naturalspice, logistic |
29 | | -from ..transforms import _cl2corr, cl2corr, corr2cl |
| 28 | +from ..unmixing import _naturalspice |
| 29 | +from ..transforms import cl2corr, corr2cl |
30 | 30 |
|
31 | 31 | try: |
32 | 32 | from copy import replace |
@@ -76,12 +76,11 @@ def jackknife_cls( |
76 | 76 | if mask_correction == "Full": |
77 | 77 | vis_alms_jk = _sum_alms_except(vis_alms_regions, regions) |
78 | 78 | _cls_mm = angular_power_spectra(vis_alms_jk) |
79 | | - alphas = get_mask_correlation_ratio(_cls_mm, mls0, unmixed=unmixed) |
80 | | - _wcls = cl2corr(_cls) |
81 | | - _wcls = _naturalspice(_wcls, alphas, fields) |
82 | | - _cls = corr2cl(_wcls) |
| 79 | + _cls = correct_footprint_naturalspice( |
| 80 | + _cls, _cls_mm, mls0, fields, unmixed=unmixed |
| 81 | + ) |
83 | 82 | elif mask_correction == "Fast": |
84 | | - _cls = correct_footprint_reduction( |
| 83 | + _cls = correct_footprint_fsky( |
85 | 84 | _cls, jk_maps, fields, *regions, unmixed=unmixed |
86 | 85 | ) |
87 | 86 | else: |
@@ -220,7 +219,7 @@ def correct_bias(cls, jkmaps, fields, jk=0, jk2=0): |
220 | 219 | return cls |
221 | 220 |
|
222 | 221 |
|
223 | | -def correct_footprint_reduction(cls, jkmaps, fields, jk=0, jk2=0, unmixed=False): |
| 222 | +def correct_footprint_fsky(cls, jkmaps, fields, jk=0, jk2=0, unmixed=False): |
224 | 223 | """ |
225 | 224 | Corrects the Cls for the footprint reduction due to taking out a region. |
226 | 225 | inputs: |
@@ -249,33 +248,42 @@ def correct_footprint_reduction(cls, jkmaps, fields, jk=0, jk2=0, unmixed=False) |
249 | 248 | return _cls |
250 | 249 |
|
251 | 250 |
|
252 | | -def get_mask_correlation_ratio(Mljk, Mls0, unmixed=False): |
| 251 | +def _mask_correlation_ratio(mljk, mls0, unmixed=False): |
| 252 | + alphas = {} |
| 253 | + wmls0 = cl2corr(mls0) |
| 254 | + wmljk = cl2corr(mljk) |
| 255 | + for key in list(wmljk.keys()): |
| 256 | + _wmljk = wmljk[key].array |
| 257 | + _wmls0 = wmls0[key].array |
| 258 | + alpha = _wmljk |
| 259 | + if not unmixed: |
| 260 | + alpha = alpha / _wmls0 |
| 261 | + alphas[key] = replace(mls0[key], array=alpha) |
| 262 | + return alphas |
| 263 | + |
| 264 | + |
| 265 | +def correct_footprint_naturalspice(cls, cls_mm, mls0, fields, unmixed=False): |
253 | 266 | """ |
254 | | - Computes the ratio of the correlation |
255 | | - functions of the masks Cls. |
256 | | - input: |
257 | | - Mljk (np.array): mask of delete1 Cls |
258 | | - Mls0 (np.array): mask Cls |
| 267 | + Corrects the Cls for footprint reduction using the full NaMaster/naturalspice approach. |
| 268 | + inputs: |
| 269 | + cls (dict): Dictionary of data Cls |
| 270 | + cls_mm (dict): Dictionary of jackknife mask Cls |
| 271 | + mls0 (dict): Dictionary of full mask Cls |
| 272 | + fields (dict): Dictionary of fields |
259 | 273 | unmixed (bool): unmix the Cls |
260 | 274 | returns: |
261 | | - alpha (Float64): Mask correction factor |
| 275 | + cls (dict): Corrected Cls |
262 | 276 | """ |
263 | | - alphas = {} |
264 | | - for key in list(Mljk.keys()): |
265 | | - mljk = Mljk[key] |
266 | | - mls0 = Mls0[key] |
267 | | - # Transform to real space |
268 | | - wmljk = _cl2corr(mljk) |
269 | | - wmljk = wmljk.T[0] |
270 | | - wmljk *= logistic(np.log10(abs(wmljk))) |
271 | | - # Compute alpha |
272 | | - alpha = wmljk |
273 | | - if not unmixed: |
274 | | - wmls0 = _cl2corr(mls0) |
275 | | - wmls0 = wmls0.T[0] |
276 | | - alpha /= wmls0 |
277 | | - alphas[key] = replace(Mls0[key], array=alpha) |
278 | | - return alphas |
| 277 | + alphas = _mask_correlation_ratio(cls_mm, mls0, unmixed=unmixed) |
| 278 | + first_cls = list(cls.values())[0] |
| 279 | + first_mls = list(mls0.values())[0] |
| 280 | + lmax = first_cls.shape[first_cls.axis[0]] |
| 281 | + lmax_mask = first_mls.shape[first_mls.axis[0]] |
| 282 | + cls = binned(cls, np.arange(0, lmax_mask + 1)) |
| 283 | + wcls = cl2corr(cls) |
| 284 | + wcls = _naturalspice(wcls, alphas, fields) |
| 285 | + cls = corr2cl(wcls) |
| 286 | + return binned(cls, np.arange(0, lmax + 1)) |
279 | 287 |
|
280 | 288 |
|
281 | 289 | def jackknife_covariance(dict, nd=1): |
|
0 commit comments