Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of NmtBin.from_lmax_linear shows error #216

Open
aniket-nath opened this issue Sep 25, 2024 · 1 comment
Open

Usage of NmtBin.from_lmax_linear shows error #216

aniket-nath opened this issue Sep 25, 2024 · 1 comment

Comments

@aniket-nath
Copy link

The following code is being used to estimate the power spectrum

def power_namaster(map_dat, mask_dat, nside, binsize=4, lmax=None):
    fwhm = np.deg2rad(56/60)
    if lmax is None:
        lmax = 3*nside-1
    map_dat = hp.remove_monopole(map_dat)
    map_dat = hp.remove_dipole(map_dat)
    pixwin = hp.pixwin(nside)
    bl = hp.gauss_beam(fwhm, lmax=3*nside-1, pol=False)*pixwin
    f_map = nmt.NmtField(mask_dat, [map_dat], beam=bl,)
    b = nmt.NmtBin.from_lmax_linear(lmax=lmax, nlb=binsize)
  
    no_bin = nmt.NmtBin.from_nside_linear(nside, 1)
    b_ell = b.get_effective_ells()
    n_ell = b_ell.shape[0]
    co_ell = b_ell*(b_ell+1)/(2*np.pi)

    wsync = nmt.NmtWorkspace()
    wsync.compute_coupling_matrix(f_map, f_map, b)
    w_th = nmt.NmtWorkspace()
    w_th.compute_coupling_matrix(f_map, f_map, no_bin)
    cl_sync = compute_master(f_map, f_map, wsync)[0]
    cl_th = np.append([0.0, 0.0], compute_master(f_map, f_map, w_th)[0])

    w00 = nmt.NmtWorkspace()
    w00.compute_coupling_matrix(f_map, f_map, b)
    cw = nmt.NmtCovarianceWorkspace()
    cw.compute_coupling_coefficients(f_map, f_map, f_map, f_map)

    covar_00_00 = nmt.gaussian_covariance(cw,
                                           0, 0, 0, 0,  # Spins of the 4 fields
                                           [cl_th], 
                                            [cl_th],
                                            [cl_th],
                                            [cl_th],
                                            w00, wb=w00).reshape([n_ell, 1, n_ell, 1])
    covar_00_00 = covar_00_00[:, 0, :, 0]
    err = np.diag(covar_00_00)
    return b_ell, cl_sync, err

When called this produces the following error!

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[36], [line 1](vscode-notebook-cell:?execution_count=36&line=1)
----> [1](vscode-notebook-cell:?execution_count=36&line=1) ell, cl, err = power_namaster(map_dat=map_dat, mask_dat=mask_dat, nside=128, binsize=10, lmax=2*128)

Cell In[35], [line 18](vscode-notebook-cell:?execution_count=35&line=18)
     [15](vscode-notebook-cell:?execution_count=35&line=15) co_ell = b_ell*(b_ell+1)/(2*np.pi)
     [17](vscode-notebook-cell:?execution_count=35&line=17) wsync = nmt.NmtWorkspace()
---> [18](vscode-notebook-cell:?execution_count=35&line=18) wsync.compute_coupling_matrix(f_map, f_map, b)
     [19](vscode-notebook-cell:?execution_count=35&line=19) w_th = nmt.NmtWorkspace()
     [20](vscode-notebook-cell:?execution_count=35&line=20) w_th.compute_coupling_matrix(f_map, f_map, no_bin)

File ~/miniconda3/envs/cosmos/lib/python3.12/site-packages/pymaster/workspaces.py:119, in NmtWorkspace.compute_coupling_matrix(self, fl1, fl2, bins, is_teb, l_toeplitz, l_exact, dl_band)
    [117](https://vscode-remote+ssh-002dremote-002b10-002e10-002e0-002e139.vscode-resource.vscode-cdn.net/home/aniket/power_spectrum/~/miniconda3/envs/cosmos/lib/python3.12/site-packages/pymaster/workspaces.py:117)     raise ValueError("Fields have incompatible pixelizations.")
    [118](https://vscode-remote+ssh-002dremote-002b10-002e10-002e0-002e139.vscode-resource.vscode-cdn.net/home/aniket/power_spectrum/~/miniconda3/envs/cosmos/lib/python3.12/site-packages/pymaster/workspaces.py:118) if fl1.ainfo.lmax != bins.lmax:
--> [119](https://vscode-remote+ssh-002dremote-002b10-002e10-002e0-002e139.vscode-resource.vscode-cdn.net/home/aniket/power_spectrum/~/miniconda3/envs/cosmos/lib/python3.12/site-packages/pymaster/workspaces.py:119)     raise ValueError(f"Maximum multipoles in bins ({bins.lmax}) "
    [120](https://vscode-remote+ssh-002dremote-002b10-002e10-002e0-002e139.vscode-resource.vscode-cdn.net/home/aniket/power_spectrum/~/miniconda3/envs/cosmos/lib/python3.12/site-packages/pymaster/workspaces.py:120)                      f"and fields ({fl1.ainfo.lmax}) "
    [121](https://vscode-remote+ssh-002dremote-002b10-002e10-002e0-002e139.vscode-resource.vscode-cdn.net/home/aniket/power_spectrum/~/miniconda3/envs/cosmos/lib/python3.12/site-packages/pymaster/workspaces.py:121)                      "are not the same.")
    [122](https://vscode-remote+ssh-002dremote-002b10-002e10-002e0-002e139.vscode-resource.vscode-cdn.net/home/aniket/power_spectrum/~/miniconda3/envs/cosmos/lib/python3.12/site-packages/pymaster/workspaces.py:122) if self.wsp is not None:
    [123](https://vscode-remote+ssh-002dremote-002b10-002e10-002e0-002e139.vscode-resource.vscode-cdn.net/home/aniket/power_spectrum/~/miniconda3/envs/cosmos/lib/python3.12/site-packages/pymaster/workspaces.py:123)     lib.workspace_free(self.wsp)

ValueError: Maximum multipoles in bins (256) and fields (383) are not the same.
@damonge
Copy link
Collaborator

damonge commented Sep 25, 2024

As the error message says, the NmtBin and NmtFields have been initialised with different ell_maxs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants