Exemple #1
0
def calc_b_iso(Tlm, Elm, Blm, ls, ms, hs, lmax=100):
    result = np.zeros((lmax + 1, lmax + 1))
    for i in np.arange(len(ls)):
        l1 = ls[i]
        m1 = ms[i]
        for j in np.arange(len(ls)):
            l2 = ls[j]
            m2 = ms[j]
            for k in np.arange(len(ms)):
                l3 = ls[j]
                m3 = ms[k]
                factor = 2.
                if l1 == l2:
                    factor = 1.

                w3jfactor = wig.wig3jj(
                    [2 * l1, 2 * l2, 2 * l2, 2 * m1, 2 * m2,
                     2 * m3])  #get_w3j(l1,l2,l2,m1,m2,m2)
                result[
                    l1,
                    l2] += w3jfactor  #Tlm[i] * Elm[j] * Blm[j] * factor * w3jfactor

            #if hs[l1,l2,l2] == 0.:
            #    result[l1,l2] = 0.
            #else:
            #    result[l1,l2] /= hs[l1,l2,l2]

    return result
Exemple #2
0
def calc_b_iso(Tlm, Elm, Blm,
               ls, ms, hs, lmax=100):
    result = np.zeros((lmax+1,lmax+1)) 
    for i in np.arange(len(ls)):
        l1 = ls[i]
        m1 = ms[i]
        for j in np.arange(len(ls)):
            l2 = ls[j]
            m2 = ms[j]
            for k in np.arange(len(ms)):
                l3 = ls[j]
                m3 = ms[k]
                factor = 2.
                if l1==l2:
                    factor = 1.

                w3jfactor = wig.wig3jj([2*l1, 2*l2, 2*l2, 2*m1, 2*m2, 2*m3])#get_w3j(l1,l2,l2,m1,m2,m2)
                result[l1,l2] += w3jfactor#Tlm[i] * Elm[j] * Blm[j] * factor * w3jfactor

            #if hs[l1,l2,l2] == 0.:
            #    result[l1,l2] = 0.
            #else:
            #    result[l1,l2] /= hs[l1,l2,l2]
                
    return result
Exemple #3
0
def w3j_factor(L, l, lp):
    """This computes the wigner-3j symbol for m's all zeros
    """
    #w3j = N(wigner_3j(L, l, lp, 0, 0, 0))
    #w3j = w3j_000(L, l, lp)
    w3j = val3j = wig.wig3jj([2*L, 2*l, 2*lp, 0, 0, 0])
    res = w3j**2 * (2.*l + 1.) * (2.*lp + 1.) / (4.*np.pi)

    return res
Exemple #4
0
    for i in xrange(0, Nbin):
        for j in xrange(0, i + 1):
            for k in xrange(0, j + 1):

                i3 = index[i]
                i2 = index[j]
                i1 = index[k]
                Bis = 0.0

                # we applied selection condition tirangle inequality and#parity condition
                if abs(i2 - i1) <= i3 <= i2 + i1 and (i3 + i2 + i1) % 2 == 0:

                    # Intiation of array for wigner 3j coefficient evaluation

                    b = [2 * i1, 2 * i2, 2 * i3, 2 * 0, 2 * 0, 2 * 0]
                    wigner = wig.wig3jj(b)

                    alpha = np.sqrt(
                        (2 * i1 + 1) * (2 * i2 + 1) *
                        (2 * i3 + 1)) * (wigner / np.sqrt(np.pi * 4.0))

                    # Bispectrum Estimation
                    for ipix in xrange(0, npix):
                        Bis += Esti_Map[i, ipix] * Esti_Map[
                            j, ipix] * Esti_Map[k, ipix]  #*Binary_Mask[ipix]

                    # All sky correction
                    Bis /= (4.0 * np.pi * npix)  #np.sum(Binary_Mask))
                    # Counting triplets in given bin
                    tripCount = count_triplet(i1, i3)
                    Bis /= (1.0 * tripCount)
Exemple #5
0
import sys

failure = int(sys.argv[1])

print('WIGXJPF python error handling test (%d)' % failure)
sys.stdout.flush()

# Initialize
if (failure != 1):
    wig.wig_table_init(2 * 100 if failure != 2 else 2 * 1,
                       9 if failure != 3 else -1)
if (failure != 4):
    wig.wig_temp_init(2 * 100 if failure != 5 else 1)

# Note that arguments are in two_j = 2*j.
val3j = wig.wig3jj(2* 10 , 2* 15 , 2* 10 ,\
                   2*(-3), 2* 12 , 2*(-9))
if failure == 6:
    val3j = wig.wig3jj(2* 1000 , 2* 1500 , 2* 1000 ,\
                       2*(-300), 2* 1200 , 2*(-900))
print('3J(10  15  10; -3  12  -9): %.12g' % val3j)
sys.stdout.flush()

val6j = wig.wig6jj(2* 10 , 2* 15 , 2* 10 ,\
                   2*  7,  2*  7 , 2*  9)
if failure == 7:
    val6j = wig.wig6jj(2* 1000 , 2* 1500 , 2* 1000 ,\
                       2*  700,  2*  700 , 2*  900)
print('6J{10  15  10;  7   7   9}: %.12g' % val6j)
sys.stdout.flush()

val9j = wig.wig9jj( 1,  2,  3,\
Exemple #6
0
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with WIGXJPF.  If not, see
#  <http://www.gnu.org/licenses/>.
#

import pywigxjpf as wig

print('WIGXJPF python test program')

# Initialize
wig.wig_table_init(2 * 100, 9)
wig.wig_temp_init(2 * 100)

# Note that arguments are in two_j = 2*j.
val3j = wig.wig3jj(2* 10 , 2* 15 , 2* 10 ,\
                   2*(-3), 2* 12 , 2*(-9))
print('3J(10  15  10; -3  12  -9): %.12g' % val3j)

val6j = wig.wig6jj(2* 10 , 2* 15 , 2* 10 ,\
                   2*  7,  2*  7 , 2*  9)
print('6J{10  15  10;  7   7   9}: %.12g' % val6j)

val9j = wig.wig9jj( 1,  2,  3,\
                    4,  6,  8, \
                    3,  6,  9 )
print('9J{0.5 1 1.5; 2 3 4; 1.5 3 4.5}: %.12g' % val9j)

print('Using the (numpy) array interface')

val3j = wig.wig3jj_array([2* 10 , 2* 15 , 2* 10 ,\
                          2*(-3), 2* 12 , 2*(-9)])
def clebsch_gordan(two_j1,  two_j2,  two_j3,  two_m1,  two_m2,  two_m3):
    from math import sqrt
    threej = pywigxjpf.wig3jj((two_j1,  two_j2,  two_j3,
                             two_m1,  two_m2,  -two_m3))
    phase = -1 if (two_m3+two_j1-two_j2) % 4 == 2 else 1
    return phase * sqrt(float(two_j3+1)) * threej
Exemple #8
0
    return ret


n = 0
for lidx, ell in enumerate(xrange(2, lmax + 1)):
    print ell
    for lpidx, ellp in enumerate(xrange(2, lmax + 1)):
        n += 1
        for ellpp in xrange(np.abs(ell - ellp), ell + ellp + 1):

            if ellpp < 2:
                continue

            val = np.sqrt(2 * ellpp + 1) * i_ell(ellpp)
            #            print val
            val *= wig.wig3jj(
                [2 * ell, 2 * ellp, 2 * ellpp, 2 * -m, 2 * (m + 2), 2 * -2])
            #            print val
            val *= wig.wig3jj(
                [2 * ell, 2 * ellp, 2 * ellpp, 2 * 2, 2 * 0, 2 * -2])
            #            print val
            trans[lidx, lpidx] += val

        trans[lidx, lpidx] *= np.sqrt(2 * ellp + 1)

    trans[lidx, :] *= np.sqrt((2 * ell + 1) / 4. / np.pi)
trans *= 2 * np.pi
trans *= (-1)**m

# Free memory space
wig.wig_temp_free()
wig.wig_table_free()
Exemple #9
0
def get_w3j(l1, l2, l3, m1, m2, m3):
    return wig.wig3jj([2 * l1, 2 * l2, 2 * l3, 2 * m1, 2 * m2, 2 * m3])
Exemple #10
0
def get_w3j(l1,l2,l3,m1,m2,m3):
    return wig.wig3jj([2*l1, 2*l2, 2*l3, 2*m1, 2*m2, 2*m3])
Exemple #11
0
def bispec_estimator(nside_f_est, loop, limit):
    """
    :param nside_f_est:
    :param loop:
    :param limit:
    :return:
    """
    npix = hp.nside2npix(nside_f_est)
    print npix
    binary_mask = masking_map(Haslam_512, nside_f_est, npix, limit)
    ap_map = apodiz(binary_mask)
    haslam = Haslam_512 * ap_map
    lmax = 250
    nbin = 249
    index = np.linspace(2, 250, nbin)  #logrithmic bins
    for k in xrange(len(index)):
        index[k] = int(index[k])
    print index

    # creating filtered map
    est_map = np.zeros((nbin, npix), dtype=np.float64)
    fwhm = 56. / 3600.  # For Haslam FWHM is 56 arc min
    beam_l = hp.sphtfunc.gauss_beam(m.radians(fwhm), lmax=lmax, pol=False)

    for i in xrange(0, nbin):
        window_func = np.zeros(lmax, float)
        ini = int(index[i])
        if ini < 250:
            window_func[ini] = 1.0
            alms = hp.sphtfunc.map2alm(haslam, lmax=lmax, iter=3)
            alm_obs = hp.sphtfunc.almxfl(alms,
                                         window_func,
                                         mmax=None,
                                         inplace=True)
            beam = 1. / beam_l
            alm_obs = hp.sphtfunc.almxfl(alm_obs,
                                         beam,
                                         mmax=None,
                                         inplace=True)
            alm_true = alm_obs
            est_map[i, :] = hp.sphtfunc.alm2map(alm_true, nside_f_est)

    bin_cl = hp.sphtfunc.anafast(haslam, lmax=lmax, iter=3)

    s1 = '/home/sandeep/final_Bispectrum/DimensionlessQ_Bispec/Temp_Fluctuation'
    s2 = '/Rework_16April2017/DimensionLess_Bin_Bispectrum_%d_%d.txt' % (
        nside_f_est, loop)
    file_name = s1 + s2

    with open(file_name, 'w') as f:
        f.write("Bis\tangAvg_Bis\tVarB\tCl1\tCl2\tCl3\ti3\ti2\ti1\n")
        for i in xrange(0, nbin):
            for j in xrange(0, i + 1):
                for k in xrange(0, j + 1):
                    i3 = index[i]
                    i2 = index[j]
                    i1 = index[k]
                    if abs(i2 -
                           i1) <= i3 <= i2 + i1 and (i3 + i2 + i1) % 2 == 0:
                        b = [2 * i1, 2 * i2, 2 * i3, 2 * 0, 2 * 0, 2 * 0]
                        wigner = wig.wig3jj(b)
                        alpha = np.sqrt(((2 * i1 + 1) * (2 * i2 + 1) *
                                         (2 * i3 + 1)) / (4. * np.pi)) * wigner
                        m1 = est_map[i, :]
                        m2 = est_map[j, :]
                        m3 = est_map[k, :]
                        bis = summation(m1, m2, m3, ap_map, npix)
                        ang_avg_bis = bis / alpha
                        var_bis = g(
                            i1, i2,
                            i3) * alpha**2 * bin_cl[i] * bin_cl[j] * bin_cl[k]
                        f.write(
                            "%0.6e\t%0.6e\t%0.6e\t%0.6e\t%0.6e\t%0.6e\t%d\t%d\t%d\n"
                            % (bis, ang_avg_bis, var_bis, bin_cl[i], bin_cl[j],
                               bin_cl[k], i3, i2, i1))