def __init__(self, alm): [tlm, elm, blm] = alm self.lmaxt = Alm.getlmax(len(tlm)) self.lmaxe = Alm.getlmax(len(elm)) self.lmaxb = Alm.getlmax(len(blm)) self.lmax = max(self.lmaxt, self.lmaxe, self.lmaxb) self.elm = elm self.blm = blm self.tlm = tlm
def alm_splice(alm_lo, alm_hi, lsplit): """Returns an alm with lmax = lmax(alm_hi) which is alm_lo for (l <= lsplit) alm_hi for (l > lsplit.) """ if hasattr(alm_lo, 'alm_splice'): return alm_lo.alm_splice(alm_hi, lsplit) alm_lo_lmax = Alm.getlmax(len(alm_lo)) alm_hi_lmax = Alm.getlmax(len(alm_hi)) assert alm_lo_lmax >= lsplit and alm_hi_lmax >= lsplit alm_re = np.copy(alm_hi) for m in range(0, lsplit + 1): alm_re[(m * (2 * alm_hi_lmax + 1 - m) // 2 + m):(m * (2 * alm_hi_lmax + 1 - m) // 2 + lsplit + 1)] = \ alm_lo[(m * (2 * alm_lo_lmax + 1 - m) // 2 + m):(m * (2 * alm_lo_lmax + 1 - m) // 2 + lsplit + 1)] return alm_re
def __init__(self, alm): [elm, blm] = alm assert len(elm) == len(blm), (len(elm), len(blm)) self.lmax = Alm.getlmax(len(elm)) self.elm = elm self.blm = blm
def alm_copy(alm, lmax=None): """Copies the alm array, with the option to reduce its lmax. """ if hasattr(alm, 'alm_copy'): return alm.alm_copy(lmax=lmax) lmox = Alm.getlmax(len(alm)) assert (lmax <= lmox) if (lmox == lmax) or (lmax is None): ret = np.copy(alm) else: ret = np.zeros(Alm.getsize(lmax), dtype=np.complex) for m in range(0, lmax + 1): ret[((m * (2 * lmax + 1 - m) // 2) + m):(m * (2 * lmax + 1 - m) // 2 + lmax + 1)] = \ alm[((m * (2 * lmox + 1 - m) // 2) + m):(m * (2 * lmox + 1 - m) // 2 + lmax + 1)] return ret
def alm2rlm(alm): """Converts a complex alm to 'real harmonic' coefficients rlm. This 'real harmonic' form is used for the dense matrix preconditioner tools. """ lmax = Alm.getlmax(alm.size) rlm = np.zeros((lmax + 1)**2, dtype=float) ls = np.arange(0, lmax + 1) l2s = ls**2 rt2 = np.sqrt(2.) rlm[l2s] = alm[ls].real for m in range(1, lmax + 1): rlm[l2s[m:] + 2 * m - 1] = alm[m * (2 * lmax + 1 - m) // 2 + ls[m:]].real * rt2 rlm[l2s[m:] + 2 * m + 0] = alm[m * (2 * lmax + 1 - m) // 2 + ls[m:]].imag * rt2 return rlm