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

NmtField lmax or lmax_mask negtive don't work #223

Closed
carlosggarcia opened this issue Oct 31, 2024 · 2 comments · Fixed by #224
Closed

NmtField lmax or lmax_mask negtive don't work #223

carlosggarcia opened this issue Oct 31, 2024 · 2 comments · Fixed by #224

Comments

@carlosggarcia
Copy link
Contributor

This code fails:

f = nmt.NmtField(m, None, spin=0, lmax_mask=-1)

(also for lmax), with error. If it is intentional, the documentation needs to be updated.

File ~/mambaforge/envs/tjpcov/lib/python3.12/site-packages/pymaster/field.py:185, in NmtField.__init__(self, mask, maps, spin, templates, beam, purify_e, purify_b, n_iter, n_iter_mask, tol_pinv, wcs, lmax, lmax_mask, masked_on_input, lite, mask_22, mask_12)
    183 if lmax_mask is None:
    184     lmax_mask = self.minfo.get_lmax()
--> 185 self.ainfo = ut.NmtAlmInfo(lmax)
    186 self.ainfo_mask = ut.NmtAlmInfo(lmax_mask)
    188 # Beam

File ~/mambaforge/envs/tjpcov/lib/python3.12/site-packages/pymaster/utils.py:452, in NmtAlmInfo.__init__(self, lmax)
    450 m = np.arange(self.mmax+1)
    451 self.mstart = (m*(2*self.lmax+1-m)//2).astype(np.uint64, copy=False)
--> 452 self.nelem = int(np.max(self.mstart) + (self.lmax+1))

File ~/mambaforge/envs/tjpcov/lib/python3.12/site-packages/numpy/core/fromnumeric.py:2810, in max(a, axis, out, keepdims, initial, where)
   2692 @array_function_dispatch(_max_dispatcher)
   2693 @set_module('numpy')
   2694 def max(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
   2695          where=np._NoValue):
   2696     """
   2697     Return the maximum of an array or maximum along an axis.
   2698 
   (...)
   2808     5
   2809     """
-> 2810     return _wrapreduction(a, np.maximum, 'max', axis, None, out,
   2811                           keepdims=keepdims, initial=initial, where=where)

File ~/mambaforge/envs/tjpcov/lib/python3.12/site-packages/numpy/core/fromnumeric.py:88, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
     85         else:
     86             return reduction(axis=axis, out=out, **passkwargs)
---> 88 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

ValueError: zero-size array to reduction operation maximum which has no identity
@carlosggarcia
Copy link
Contributor Author

It might be related with this error. I believe that the check lmax <= 0 is not working at all. It seems that for lmax=0it actually computes it up to l=0

I got this error when I set lmax = 0 in the field and reuse a precomputed covariance workspace

    def comp_gaussian_covariance(cw, spin_a1, spin_a2, spin_b1, spin_b2, wa, wb, ncl11, ncl12, ncl21, ncl22, dout):
>       return _nmtlib.comp_gaussian_covariance(cw, spin_a1, spin_a2, spin_b1, spin_b2, wa, wb, ncl11, ncl12, ncl21, ncl22, dout)
E       RuntimeError: Coupling coefficients only computed up to l=0, but you requirelmax=95. Recompute this workspace with a larger lmax

@damonge
Copy link
Collaborator

damonge commented Nov 1, 2024

@carlosggarcia I think this is a problem with the documentation. If you want to use the default lmaxs, you should set them to None, which is the default. Does that make sense? I'll open a PR to fix the docs.

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

Successfully merging a pull request may close this issue.

2 participants