コード例 #1
0
ファイル: test_wavemoth.py プロジェクト: wavemoth/wavemoth
def test_legendre_transforms():
    nmaps = 2
    plan = make_plan(nmaps, nthreads=3)
    k = np.arange(1, 3)
    for l in range(lmax + 1):
        for m in range(l, lmax + 1):
            plan.input[lm_to_idx_mmajor(l, m), :] = 10 * k * np.cos(l * 0.1) * np.sqrt(m)
    plan.input[1, :] = (5 + 5j) * k
    plan.input[2, :] = 34 + 3j
    plan.perform_legendre_transform()
    work = plan.get_work()


    nodes = get_ring_thetas(Nside, positive_only=True)
    work0 = np.zeros((lmax + 1, 2, 2 * Nside, nmaps), dtype=np.complex128)
    idx = 0
    for m in range(lmax + 1):
        Lambda = compute_normalized_associated_legendre(m, nodes, lmax,
                                                        epsilon=1e-30).T
        ncoef = lmax - m + 1
        a_l = plan.input[idx:idx + ncoef, :]
        idx += ncoef
        for odd in range(2):
            work0[m, odd, :, :] = np.dot(a_l[odd::2, :].T, Lambda[odd::2, :]).T


    assert_almost_equal(work0, work)
    
    if 0:
        as_matrix(work[:, 0, :, 0]).plot()
        as_matrix(work0[:, 0, :, 0]).plot()
        plt.show()
コード例 #2
0
def test_legendre_transforms():
    nmaps = 2
    plan = make_plan(nmaps, nthreads=3)
    k = np.arange(1, 3)
    for l in range(lmax + 1):
        for m in range(l, lmax + 1):
            plan.input[lm_to_idx_mmajor(l, m), :] = 10 * k * np.cos(
                l * 0.1) * np.sqrt(m)
    plan.input[1, :] = (5 + 5j) * k
    plan.input[2, :] = 34 + 3j
    plan.perform_legendre_transform()
    work = plan.get_work()

    nodes = get_ring_thetas(Nside, positive_only=True)
    work0 = np.zeros((lmax + 1, 2, 2 * Nside, nmaps), dtype=np.complex128)
    idx = 0
    for m in range(lmax + 1):
        Lambda = compute_normalized_associated_legendre(m,
                                                        nodes,
                                                        lmax,
                                                        epsilon=1e-30).T
        ncoef = lmax - m + 1
        a_l = plan.input[idx:idx + ncoef, :]
        idx += ncoef
        for odd in range(2):
            work0[m, odd, :, :] = np.dot(a_l[odd::2, :].T, Lambda[odd::2, :]).T

    assert_almost_equal(work0, work)

    if 0:
        as_matrix(work[:, 0, :, 0]).plot()
        as_matrix(work0[:, 0, :, 0]).plot()
        plt.show()
コード例 #3
0
ファイル: stripify_matrix.py プロジェクト: wavemoth/wavemoth
from wavemoth import *
from wavemoth.healpix import *
from wavemoth.fastsht import *
from cmb import as_matrix
from wavemoth.butterfly import *
from matplotlib import pyplot as plt
from wavemoth.lib import stripify

from concurrent.futures import ProcessPoolExecutor#, ThreadPoolExecutor
from wavemoth.utils import FakeExecutor

from numpy.linalg import norm
def logabs(x): return np.log(np.abs(x))


Nside = 64
lmax = 3 * Nside
nodes = get_ring_thetas(Nside, positive_only=True)
m = 2 * Nside
Lambda = compute_normalized_associated_legendre(m, nodes, lmax).T

stripes = stripify(Lambda)

X = Lambda * 0
for ra, rb, ca, cb in stripes:
    X[ra:rb, ca:cb] = 1
as_matrix(X).plot()

print stripes
#as_matrix(np.log10(np.abs(Lambda) + 1e-150)).plot()
コード例 #4
0
ファイル: even_odd.py プロジェクト: wgsproul/wavemoth
B_odd = B[1::2, :]

#as_matrix(P[::2, :]).plot()
#as_matrix(P[1::2, :]).plot()
 
iden_list1, ipol_list1, A_ip1 = sparse_interpolative_decomposition(B_even, 1e-13)
#iden_list2, ipol_list2, A_ip2 = sparse_interpolative_decomposition(B[1::2, :], 1e-13)

filter1 = permutations_to_filter(iden_list1, ipol_list1).astype(np.bool)
print filter1

#filter1[...] = False

S = lssolve(B_even, iden_list1)

as_matrix(A_ip1).plot()
as_matrix(S).plot()

B_k = B_even[:, ~filter1]
B_recon = np.dot(B_k, A_ip1)
B_other = B[:, filter1]

as_matrix(B_other).plot()

print np.linalg.norm(B_even[:, filter1] - B_recon)

#as_matrix(np.log(np.abs(A_ip1))).plot()
#as_matrix(np.log(np.abs(C))).plot()

#as_matrix(np.dot(B_odd[:, filter1], S) - B_odd[:, ~filter1]).plot()
コード例 #5
0
ファイル: P_plots.py プロジェクト: wavemoth/wavemoth
from __future__ import division

# Stick .. in PYTHONPATH
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))


from wavemoth import *
from wavemoth.healpix import *
from cmb import as_matrix

lmax = 400
Nside = 256
m = 100

nodes = get_ring_thetas(Nside)
P = compute_normalized_associated_legendre(m, nodes, lmax)

as_matrix(P[:300, :]).plot()
コード例 #6
0
from cmb import as_matrix
from wavemoth.butterfly import *
from matplotlib import pyplot as plt
from wavemoth.lib import stripify

from concurrent.futures import ProcessPoolExecutor  #, ThreadPoolExecutor
from wavemoth.utils import FakeExecutor

from numpy.linalg import norm


def logabs(x):
    return np.log(np.abs(x))


Nside = 64
lmax = 3 * Nside
nodes = get_ring_thetas(Nside, positive_only=True)
m = 2 * Nside
Lambda = compute_normalized_associated_legendre(m, nodes, lmax).T

stripes = stripify(Lambda)

X = Lambda * 0
for ra, rb, ca, cb in stripes:
    X[ra:rb, ca:cb] = 1
as_matrix(X).plot()

print stripes
#as_matrix(np.log10(np.abs(Lambda) + 1e-150)).plot()
コード例 #7
0
ファイル: P_plots.py プロジェクト: wgsproul/wavemoth
from __future__ import division

# Stick .. in PYTHONPATH
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

from wavemoth import *
from wavemoth.healpix import *
from cmb import as_matrix

lmax = 400
Nside = 256
m = 100

nodes = get_ring_thetas(Nside)
P = compute_normalized_associated_legendre(m, nodes, lmax)

as_matrix(P[:300, :]).plot()
コード例 #8
0
ファイル: even_odd.py プロジェクト: wgsproul/wavemoth
B_odd = B[1::2, :]

# as_matrix(P[::2, :]).plot()
# as_matrix(P[1::2, :]).plot()

iden_list1, ipol_list1, A_ip1 = sparse_interpolative_decomposition(B_even, 1e-13)
# iden_list2, ipol_list2, A_ip2 = sparse_interpolative_decomposition(B[1::2, :], 1e-13)

filter1 = permutations_to_filter(iden_list1, ipol_list1).astype(np.bool)
print filter1

# filter1[...] = False

S = lssolve(B_even, iden_list1)

as_matrix(A_ip1).plot()
as_matrix(S).plot()

B_k = B_even[:, ~filter1]
B_recon = np.dot(B_k, A_ip1)
B_other = B[:, filter1]

as_matrix(B_other).plot()

print np.linalg.norm(B_even[:, filter1] - B_recon)

# as_matrix(np.log(np.abs(A_ip1))).plot()
# as_matrix(np.log(np.abs(C))).plot()

# as_matrix(np.dot(B_odd[:, filter1], S) - B_odd[:, ~filter1]).plot()