|
17 | 17 | # You should have received a copy of the GNU Lesser General Public |
18 | 18 | # License along with Heracles. If not, see <https://www.gnu.org/licenses/>. |
19 | 19 | import numpy as np |
20 | | -from collections.abc import Mapping |
21 | 20 | from .result import binned |
22 | 21 | from .transforms import cl2corr, corr2cl |
23 | 22 | from .utils import get_cl |
| 23 | +from .transforms import _cached_gauss_legendre |
24 | 24 |
|
25 | 25 | try: |
26 | 26 | from copy import replace |
|
29 | 29 | from dataclasses import replace |
30 | 30 |
|
31 | 31 |
|
32 | | -def naturalspice(d, m, fields, rcond=0.01): |
| 32 | +def naturalspice(d, m, fields, theta_max=None): |
33 | 33 | """ |
34 | 34 | Natural unmixing of the data Cl. |
35 | 35 | Args: |
36 | 36 | d: Data Cl |
37 | 37 | m: mask Cl |
38 | 38 | fields: list of fields |
39 | | - patch_hole: If True, apply the patch hole correction |
| 39 | + theta_max: maximum angle to use for the unmixing, in degrees. If None, use all angles. |
40 | 40 | Returns: |
41 | 41 | corr_d: Corrected Cl |
42 | 42 | """ |
43 | 43 | first_wd = list(d.values())[0] |
44 | 44 | first_wm = list(m.values())[0] |
45 | 45 | lmax = first_wd.shape[first_wd.axis[0]] |
46 | 46 | lmax_mask = first_wm.shape[first_wm.axis[0]] |
| 47 | + xvals, _ = _cached_gauss_legendre(lmax_mask) |
| 48 | + theta = np.arccos(xvals) * 180 / np.pi |
47 | 49 |
|
48 | 50 | # pad correlation functions to lmax_mask |
49 | 51 | d = binned(d, np.arange(0, lmax_mask + 1)) |
50 | 52 |
|
51 | 53 | wd = cl2corr(d) |
52 | 54 | wm = cl2corr(m) |
53 | | - for m_key in list(wm.keys()): |
54 | | - if isinstance(rcond, Mapping): |
55 | | - if m_key not in rcond: |
56 | | - raise KeyError(f"Missing rcond value for wm key: {m_key}") |
57 | | - _rcond = rcond[m_key] |
58 | | - else: |
59 | | - _rcond = rcond |
60 | | - _wm = wm[m_key].array |
61 | | - _wm = _wm * logistic(np.log10(abs(_wm)), x0=np.log10(_rcond * np.max(_wm))) |
62 | | - wm[m_key] = replace(wm[m_key], array=_wm) |
63 | | - |
| 55 | + if theta_max is not None: |
| 56 | + for m_key in list(wm.keys()): |
| 57 | + _wm = wm[m_key].array |
| 58 | + i_theta_max = np.abs(theta - theta_max).argmin() |
| 59 | + wm_at_theta_max = _wm[i_theta_max] |
| 60 | + _wm = _wm * logistic(np.log10(abs(_wm)), x0=np.log10(abs(wm_at_theta_max))) |
| 61 | + wm[m_key] = replace(wm[m_key], array=_wm) |
64 | 62 | corr_wds = _naturalspice(wd, wm, fields) |
65 | 63 |
|
66 | 64 | # trnasform back to Cl |
@@ -99,5 +97,5 @@ def _naturalspice(wd, wm, fields): |
99 | 97 | return corr_wds |
100 | 98 |
|
101 | 99 |
|
102 | | -def logistic(x, x0=-5, k=50): |
| 100 | +def logistic(x, x0=-2, k=50): |
103 | 101 | return 1.0 + np.exp(-k * (x - x0)) |
0 commit comments