This is a Python code for Bispectrum on any scalar(Temprature only) map we use Binned Bispectrum estimator Bucher et. al. 2010 and arXiv:1509.08107v2 also see Casponsa et. al. 2014 Extensively use of Healpy and Healpix thanks to Gorski et.al. 2005 Eric Hivon and Andrea Zonca for Healpy """ import numpy as np import healpy as hp from multiprocessing import Process # pywigxjpf for to import python routine to evaluate # wigner 3j coefficient that comes in Guant integral import pywigxjpf as wig wig.wig_table_init(1000) wig.wig_temp_init(1000) name = "/home/sandeep/Haslam/lambda_haslam408_dsds.fits" print name Haslam_512 = hp.fitsfunc.read_map( name) # Here we Use map from point source subtracted from lambda def masking_map(map1, nside, npixs, limit): """ This routine to apply mask that we decided using count in cell scheme, we returning masked map and Binary Mask. """ area = hp.pixelfunc.nside2pixarea(nside, degrees=False) b_mask = np.zeros(hp.nside2npix(nside), dtype=np.double) # Binary Mask
rc('font',**{'family':'serif','serif':['Times','Palatino']}) rc('text', usetex=True) mpl.rcParams['xtick.major.size']=8 mpl.rcParams['ytick.major.size']=8 mpl.rcParams['xtick.labelsize']=18 mpl.rcParams['ytick.labelsize']=18 import os,os.path,shutil #from sympy import N #from sympy.physics.wigner import wigner_3j import pywigxjpf as wig lmax = 5000 wig.wig_table_init(2*lmax,9) wig.wig_temp_init(2*lmax) # Free memory space #wig.wig_temp_free() #wig.wig_table_free() Tcmb = 2.7255 * 1e6 # CMB temperature in uK spectra = np.loadtxt('scalCls.dat') ls = spectra[:lmax-1,0] tt = spectra[:lmax-1,1] * (2.*np.pi) / ls / (ls + 1) #/ Tcmb NET = 30 # Planck noise in uK(sec)**0.5 = 30; AdvACT: 5 tobs = 2.5 # Planck observation time in years = 2.5yr; AdvACT 2. fsky = 0.75 # Planck fsky=0.75; AdvACT 0.5 fwhm = 5. #Planck resolution = 5. arcmin; AdvACT 1.3
import pywigxjpf as wig 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)
# WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # 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)
import pywigxjpf pywigxjpf.wig_table_init(2*100, 9) pywigxjpf.wig_temp_init(2*100) 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 def Wigner_d(j, m1, m2, x): # using definition from A.R. Edmonds, eq 4.1.23 from scipy.special import factorial, eval_jacobi from numpy import sqrt mp, m = m1, m2 p = 1 if mp + m < 0: mp, m = -mp, -m p *= (-1) ** (mp - m) if mp < m: mp, m = m, mp p *= (-1) ** (mp - m) return (p * sqrt( factorial(j + mp) * factorial(j - mp) / (factorial(j + m) * factorial(j - m)) ) * sqrt(.5 + .5 * x) ** (mp + m) * sqrt(.5 - .5 * x) ** (mp - m) * eval_jacobi(j - mp, mp - m, mp + m, x)
import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt import numpy as np import sys sys.path.insert(0, './../wigxjpf-1.6/pywigxjpf') import pywigxjpf as wig import os opj = os.path.join outdir = '/mn/stornext/d8/ITA/spider/adri/analysis/20180108_test_spin' # Initialize wig.wig_table_init(2 * 200, 3) wig.wig_temp_init(2 * 200) # 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):', val3j m = 1 lmax = 100 trans = np.zeros((lmax + 1, lmax + 1), dtype=float) def i_ell(ell): ret = np.sqrt((2 * ell + 1) / 4. / np.pi) ret *= 4 * (-1)**ell ret /= float((ell * (ell + 1))) return ret
else: alms = np.load(data_path + newname, 'r') if intensity and pol: return alms[0], alms[1], alms[2] else: if intensity: return alms[0] if pol: return alms[1], alms[2] import pywigxjpf as wig lmax = 200 wig.wig_table_init(2 * lmax, 9) wig.wig_temp_init(2 * lmax) @jit def get_w3j(l1, l2, l3, m1, m2, m3): return wig.wig3jj([2 * l1, 2 * l2, 2 * l3, 2 * m1, 2 * m2, 2 * m3]) def get_TEB_prerequisites(maps=None, Imap_label='353', Pmap_label='353', Imap_name=None, Pmap_name=None, lmax=100, masktype='PowerSpectra', rewrite=False,
class binned_bispectrum: map_making.nside_f_est = 512 map_making.masking = 'No' map_making.apodization = 'No' wig.wig_table_init(1000) wig.wig_temp_init(1000) # binned map equation(6) casaponsa et. al. def __init__(self, Inp_alm_l, Inp_alm_nl, inp_bin, inp_fNL, NSIDE=1024, LMAX=2500): self.Inp_alm_l = Inp_alm_l self.Inp_alm_nl = Inp_alm_nl self.inp_bin = inp_bin self.Nbins = len(inp_bin) self.LMAX = LMAX self.FNL = inp_fNL self.NSIDE = NSIDE test1 = map_making(self.NSIDE) self.esti_map, self.ap_ma, self.binL = test1.binned_map( self.Nbins, self.LMAX, self.inp_bin, self.FNL, self.Inp_alm_l, self.Inp_alm_nl, beam=None, map_type='Non gaussian', beam_corr=None) self.nbin = len(inp_bin) self.npix = hp.nside2npix(self.NSIDE) self.bis = list() self.I = list() self.J = list() self.K = list() self.trip_count = list() def bispectrum(self): """ :rtype: object :return: """ for i in xrange(0, self.nbin - 1): for j in xrange(i, self.nbin - 1): for k in xrange(j, self.nbin - 1): if np.min(self.binL[k]) - np.max(self.binL[j]) <= np.max(self.binL[i]) <= np.max(self.binL[k]) \ + np.max(self.binL[j]): temp = summation(self.esti_map[i, :], self.esti_map[j, :], self.esti_map[k, :], self.ap_ma, self.npix) self.trip_count.append( count_triplet(np.min(self.binL[k]), np.max(self.binL[i]))) self.bis.append(temp) self.I.append(i) self.J.append(j) self.K.append(k) self.bis = np.asarray(self.bis) self.I = np.asarray(self.I) self.J = np.asarray(self.J) self.K = np.asarray(self.K) self.trip_count = np.asarray(self.trip_count) return self.bis, self.I, self.J, self.K, self.trip_count wig.wig_temp_free() wig.wig_table_free()