Commit 13a563de authored by Jait Dixit's avatar Jait Dixit

WIP: Update lm_space distance_array method

- Remove mmax. Now, lmax == mmax
- Create index and l-number on the fly
parent 6218e99b
import numpy as np
cimport numpy as np
cpdef _distance_array_helper(np.int_t x, np.ndarray[np.int_t] l,
np.int_t original_size, np.int_t lmax):
cpdef _distance_array_helper(np.ndarray[np.int_t] index_array, np.int_t lmax):
cdef np.int size = (lmax + 1) * (lmax + 1)
cdef np.ndarray res = np.zeros([size], dtype=np.float128)
res[0:lmax + 1] = np.arange(lmax + 1)
cdef np.ndarray res = np.zeros([len(index_array)], dtype=np.float128)
for i in xrange(original_size - lmax - 1):
res[i * 2 + lmax + 1] = l[i + lmax + 1]
res[i * 2 + lmax + 1] = l[i + lmax + 1]
for idx, index_full in enumerate(index_array):
if index_full <= lmax:
index_half = index_full
else:
index_half = (index_full + lmax + 1) / 2;
m = (np.ceil(((2 * lmax + 1) -
np.sqrt((2 * lmax + 1)**2 -
8 * (index_half - lmax))) / 2)).astype(int)
res[idx] = index_half - m * (2 * lmax + 1 - m) // 2
return res[x]
return res
......@@ -75,7 +75,7 @@ class LMSpace(Space):
Pixel volume of the :py:class:`lm_space`, which is always 1.
"""
def __init__(self, lmax, mmax=None, dtype=np.dtype('complex128')):
def __init__(self, lmax, dtype=np.dtype('complex128')):
"""
Sets the attributes for an lm_space class instance.
......@@ -111,7 +111,6 @@ class LMSpace(Space):
super(LMSpace, self).__init__(dtype)
self._lmax = self._parse_lmax(lmax)
self._mmax = self._parse_mmax(mmax)
def distance_array(self, distribution_strategy):
dists = arange(
......@@ -122,7 +121,7 @@ class LMSpace(Space):
l = hp.Alm.getlm(lmax=self.lmax)[0]
dists = dists.apply_scalar_function(
lambda x: _distance_array_helper(
int(x), l, hp.Alm.getsize(self.lmax), self.lmax
x, self.lmax
)
)
......@@ -177,7 +176,7 @@ class LMSpace(Space):
@property
def mmax(self):
return self._mmax
return self._lmax
def _parse_lmax(self, lmax):
lmax = np.int(lmax)
......@@ -189,20 +188,3 @@ class LMSpace(Space):
about.warnings.cprint(
"WARNING: unrecommended parameter (lmax <> 2*n+1).")
return lmax
def _parse_mmax(self, mmax):
if mmax is None:
mmax = self.lmax
else:
mmax = int(mmax)
if mmax < 1:
raise ValueError(about._errors.cstring(
"ERROR: mmax < 1 is not allowed."))
if mmax > self.lmax:
raise ValueError(about._errors.cstring(
"ERROR: mmax > lmax is not allowed."))
if mmax != self.lmax:
about.warnings.cprint(
"WARNING: unrecommended parameter combination (mmax <> lmax).")
return mmax
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment