Ejemplo n.º 1
0
 def test_subtract_noise(self):
     Q = n.diag(n.arange(1,9))
     N = n.identity(8)
     a = n.arange(2,17,2)
     n_vec = uf.rand_from_covar(N)
     Qa = uf.vdot(Q,a)
     y = Qa+n_vec
     a,ahat,err = qgea.test_recover_alms(y,Q,N,a,num_remov=-4) 
     _,nhat,err = qgea.test_recover_alms(n_vec,Q,N,a,num_remov=-4) 
     ahat_better = ahat - nhat
     W = qgea.window_fn_matrix(Q,N,num_remov=-4)
     self.assertTrue(n.allclose(n.dot(W,a),ahat_better))
Ejemplo n.º 2
0
def construct_gs_hist(del_bl=8.,num_bl=10,beam_sig=0.09,fq=0.1):
    save_tag = 'grid_del_bl_{0:.2f}_num_bl_{1}_beam_sig_{2:.2f}_fq_{3:.3f}'.format(del_bl,num_bl,beam_sig,fq)
    save_tag_mc = 'grid_del_bl_{0:.2f}_num_bl_{1}_beam_sig_{2:.2f}_fq_{3}'.format(del_bl,num_bl,beam_sig,fq)
    ys = load_mc_data('{0}/monte_carlo/{1}'.format(data_loc,save_tag_mc))
    print 'ys ',ys.shape
    
    alms_fg = qgea.generate_sky_model_alms(gsm_fits_file,lmax=3)
    alms_fg = alms_fg[:,2]

    baselines,Q,lms = load_Q_file(gh='grid',del_bl=del_bl,num_bl=num_bl,beam_sig=beam_sig,fq=fq,lmax=3)
    N = total_noise_covar(0.1,baselines.shape[0],'{0}/gsm_matrices/gsm_{1}.npz'.format(data_loc,save_tag))
    MQN = return_MQdagNinv(Q,N,num_remov=None)
    print MQN
    ahat00s = n.array([])
    for ii in xrange(ys.shape[1]):
        #_,ahat,_ = qgea.test_recover_alms(ys[:,ii],Q,N,alms_fg,num_remov=None)
        ahat = uf.vdot(MQN,ys[:,ii])
        ahat00s = n.append(n.real(ahat[0]),ahat00s)
    #print ahat00s
    print ahat00s.shape
    _,bins,_ = p.hist(ahat00s,bins=36,normed=True)

    # plot best fit line
    mu,sigma = norm.fit(ahat00s)
    print "mu, sigma = ",mu,', ',sigma
    y_fit = mpl.mlab.normpdf(bins,mu,sigma)
    p.plot(bins, y_fit, 'r--', linewidth=2)

    p.xlabel('ahat_00')
    p.ylabel('Probability')
    p.title(save_tag)
    p.annotate('mu = {0:.2f}\nsigma = {1:.2f}'.format(mu,sigma), xy=(0.05, 0.5), xycoords='axes fraction')
    p.savefig('./figures/monte_carlo/{0}.pdf'.format(save_tag))
    p.clf()
Ejemplo n.º 3
0
 def test_sum(self):
     N = n.identity(8)
     Q = n.identity(8)
     Q[0,3] = 1; Q[3,0] = 1
     a = n.arange(8); a[0] = 10
     y = uf.vdot(Q,a)
     a,ahat,err = qgea.test_recover_alms(y,Q,N,a,num_remov=1) 
     W = qgea.window_fn_matrix(Q,N,num_remov=1)
     Wa = uf.vdot(W,a)
     print 'Wa ',Wa
     print 'ahat ',ahat
     print Wa[0]/Wa[1]
     print a[0]/a[1]
     self.assertAlmostEqual(ahat[0],(a[0]+a[3])/2.)
     self.assertAlmostEqual(ahat[3],(a[0]+a[3])/2.)
     self.assertTrue(n.allclose(Wa,ahat))
Ejemplo n.º 4
0
 def test_recover_gs_ratio(self):
     print "GS Ratio"
     Q = n.diag(n.arange(1,9))
     N = n.identity(8)*50
     #N[0,0]=1
     a = n.array([16,4,0,0,0,0,0,0])#n.arange(16,1,-2)
     print 'a ',a 
     n_vec = uf.rand_from_covar(N)
     Qa = uf.vdot(Q,a)
     y = Qa+n_vec
     self.assertTrue(y.shape==(8,))
     a,ahat,err = qgea.test_recover_alms(y,Q,N,a,num_remov=0)        
     W = qgea.window_fn_matrix(Q,N,num_remov=0)
     Wa = uf.vdot(W,a)
     print 'Wa ',Wa
     print 'ahat ',ahat
     print Wa[0]/Wa[1]
     print a[0]/a[1]
     self.assertTrue(n.abs(Wa[0]/Wa[1]-a[0]/a[1])<0.1)    
Ejemplo n.º 5
0
 def test_recover_diag(self):
     Q = n.diag(n.arange(1,9)[::-1])
     N = n.identity(8)
     a = n.arange(2,17,2)
     #a = a[::-1]
     y = n.dot(Q,a)#+uf.rand_from_covar(N)
     a,ahat,err = qgea.test_recover_alms(y,Q,N,a,num_remov=3)
     print "diag"
     print a
     print ahat
     self.assertTrue(n.allclose(a[:-3],ahat[:-3]))
     self.assertTrue(n.allclose(0,ahat[-3:]))
Ejemplo n.º 6
0
 def test_recover_wind(self):
     print "Window"
     num=100
     Q = n.diag(n.arange(1,9))
     N = n.identity(8)
     a = n.arange(2,17,2)
     a1 = n.arange(2,17,2)
     ahat_avg = 0
     for ii in range(num):
         n_vec = uf.rand_from_covar(N)
         Qa = uf.vdot(Q,a)
         y = Qa+n_vec
         self.assertTrue(y.shape==(8,))
         a,ahat,err = qgea.test_recover_alms(y,Q,N,a,num_remov=-4)        
         ahat_avg += ahat
         self.assertTrue(n.all(y==n.dot(Q,a1)+n_vec))
     ahat_avg = ahat_avg/num
     W = qgea.window_fn_matrix(Q,N,num_remov=-4)
     print uf.vdot(W,a)
     print ahat_avg
     self.assertTrue(n.all(n.abs(n.dot(W,a)-ahat_avg)<0.1))
Ejemplo n.º 7
0
    def test_recover_gs(self):
        print "GS"
        num=500
        Q = n.diag(n.arange(1,9))
        N = n.identity(8)*50
        N[0,0]=1
        a = n.array([16,0,0,0,0,0,0,0])#n.arange(16,1,-2)
        print 'a ',a 
        ahat_avg = 0
        for ii in range(num):
            n_vec = uf.rand_from_covar(N)
            Qa = uf.vdot(Q,a)
            y = Qa+n_vec
            self.assertTrue(y.shape==(8,))
            a,ahat,err = qgea.test_recover_alms(y,Q,N,a,num_remov=0)        
            ahat_avg += ahat
        ahat_avg = ahat_avg/num
        W = qgea.window_fn_matrix(Q,N,num_remov=0)

        print uf.vdot(W,a)
        print ahat_avg
        self.assertTrue(n.abs(uf.vdot(W,a)[0]-ahat_avg[0])<0.1)
Ejemplo n.º 8
0
def construct_gs_hist(del_bl=8., num_bl=10, beam_sig=0.09, fq=0.1):
    save_tag = 'grid_del_bl_{0:.2f}_num_bl_{1}_beam_sig_{2:.2f}_fq_{3:.3f}'.format(
        del_bl, num_bl, beam_sig, fq)
    save_tag_mc = 'grid_del_bl_{0:.2f}_num_bl_{1}_beam_sig_{2:.2f}_fq_{3}'.format(
        del_bl, num_bl, beam_sig, fq)
    ys = load_mc_data('{0}/monte_carlo/{1}'.format(data_loc, save_tag_mc))
    print 'ys ', ys.shape

    alms_fg = qgea.generate_sky_model_alms(gsm_fits_file, lmax=3)
    alms_fg = alms_fg[:, 2]

    baselines, Q, lms = load_Q_file(gh='grid',
                                    del_bl=del_bl,
                                    num_bl=num_bl,
                                    beam_sig=beam_sig,
                                    fq=fq,
                                    lmax=3)
    N = total_noise_covar(
        0.1, baselines.shape[0],
        '{0}/gsm_matrices/gsm_{1}.npz'.format(data_loc, save_tag))
    MQN = return_MQdagNinv(Q, N, num_remov=None)
    print MQN
    ahat00s = n.array([])
    for ii in xrange(ys.shape[1]):
        #_,ahat,_ = qgea.test_recover_alms(ys[:,ii],Q,N,alms_fg,num_remov=None)
        ahat = uf.vdot(MQN, ys[:, ii])
        ahat00s = n.append(n.real(ahat[0]), ahat00s)
    #print ahat00s
    print ahat00s.shape
    _, bins, _ = p.hist(ahat00s, bins=36, normed=True)

    # plot best fit line
    mu, sigma = norm.fit(ahat00s)
    print "mu, sigma = ", mu, ', ', sigma
    y_fit = mpl.mlab.normpdf(bins, mu, sigma)
    p.plot(bins, y_fit, 'r--', linewidth=2)

    p.xlabel('ahat_00')
    p.ylabel('Probability')
    p.title(save_tag)
    p.annotate('mu = {0:.2f}\nsigma = {1:.2f}'.format(mu, sigma),
               xy=(0.05, 0.5),
               xycoords='axes fraction')
    p.savefig('./figures/monte_carlo/{0}.pdf'.format(save_tag))
    p.clf()