示例#1
0
    def test_speed(self):
        self.test_dir = os.path.dirname(os.path.realpath(__file__)) + '/'
        self.blmequ = sv.read_real_alm(self.test_dir + 'bx125.195.bin')
        self.blmax = 5
        self.freq = 125.195#my correct answers are computed with c=300,so im rescaing freq here to compensate
        self.zenithequ = sv.ctos(np.fromfile(self.test_dir + 'zenith.bin', dtype = 'float32'))[1:]
        self.zenithequ[0] = np.pi/2 - self.zenithequ[0]
        self.zenithequ = np.array(self.zenithequ)[::-1]
        self.correct_result = np.loadtxt(self.test_dir + 'Revised_Location_Visibilties_for_21_m_south_21_m_east_0_m_up_xx_pol_125.195_MHz.dat')
        self.correct_result = self.correct_result[:-1, 1] + 1j * self.correct_result[:-1, 2]
        self.nside = 128

        self.vs = sv.Visibility_Simulator()
        self.vs.initial_zenith = self.zenithequ
        self.vs.Blm = sv.expand_real_alm(self.blmequ)
        self.rot = np.fromfile(self.test_dir + 'x5rot.bin', dtype = 'float32').reshape((3,3))

        nside = self.nside
        print "Reading fits...",
        sys.stdout.flush()
        pca1 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm1.fits' + str(nside))
        pca2 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm2.fits' + str(nside))
        pca3 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm3.fits' + str(nside))
        gsm = 422.952*(0.307706*pca1+-0.281772*pca2+0.0123976*pca3)
        print "Done reading"
        sys.stdout.flush()
        equatorial_GSM = np.zeros(12*nside**2,'float')

        #rotate sky map
        print "Rotating map...",
        sys.stdout.flush()
        for i in range(12*nside**2):
            ang = hp.rotator.Rotator(coord='cg')(hpf.pix2ang(nside,i))
            pixindex, weight = hpf.get_neighbours(nside,ang[0],ang[1])
            for pix in range(len(pixindex)):
                equatorial_GSM[i] += weight[pix]*gsm[pixindex[pix]]
        print "Done rotating"
        sys.stdout.flush()

        print "Creating map alm...",
        sys.stdout.flush()
        self.alm = sv.convert_healpy_alm(hp.sphtfunc.map2alm(equatorial_GSM), 3 * nside - 1)
        print "Done alm"
        sys.stdout.flush()

        print "Computing visibilities...",
        sys.stdout.flush()
        timer = time.time()
        self.result = self.vs.calculate_visibility(sv.expand_real_alm(self.alm), d=self.rot.dot(np.array([21.0,21.0,0.0])), freq=self.freq, nt=len(self.correct_result), L = 3*self.nside-1, verbose = True)
        print "done", (time.time() - timer)/60, 'min'
        sys.stdout.flush()
        #print len(self.result), np.argmax(np.real(self.result)) - np.argmax(np.real(self.correct_result)), np.argmax(np.imag(self.result)) - np.argmax(np.imag(self.correct_result))
        plt.plot(np.real(self.result), 'r--', np.real(self.correct_result), 'b--')
        plt.show()
        plt.plot(np.imag(self.result), 'r--', np.imag(self.correct_result), 'b--')
        plt.show()
示例#2
0
    def setUp(self):
        self.test_dir = os.path.dirname(os.path.realpath(__file__)) + '/'
        self.blmequ = sv.read_real_alm(self.test_dir + 'blm5.bin')
        self.blmax = 5
        self.freq = 150. / 300. * 299.792458  #my correct answers are computed with c=300,so im rescaing freq here to compensate
        self.zenithequ = sv.ctos(
            np.fromfile(self.test_dir + 'zenith.bin', dtype='float32'))[1:]
        self.zenithequ[0] = np.pi / 2 - self.zenithequ[0]
        self.zenithequ = np.array(self.zenithequ)[::-1]
        self.blvequ = np.fromfile(self.test_dir + 'blv.bin', dtype='float32')
        self.correct_BB = sv.read_alm(self.test_dir + 'BB47.bin')
        self.correct_cm = np.fromfile(self.test_dir + 'cm47.bin',
                                      dtype='complex64')
        self.correct_result = np.fromfile(
            self.test_dir + 'final47.bin', dtype='complex64'
        )  # * (len(self.correct_cm))**0.5 #correct result did not use correct normalization n**0.5 in fourier
        self.nside = 16
        healpix = np.zeros(12 * self.nside**2)
        healpix[420] = 1
        healpix[752] = 1
        self.alm = sv.convert_healpy_alm(hp.sphtfunc.map2alm(healpix),
                                         3 * self.nside - 1)

        self.vs = sv.Visibility_Simulator()
        self.vs.initial_zenith = self.zenithequ
        self.vs.Blm = sv.expand_real_alm(self.blmequ)
示例#3
0
    def test_josh_gsm(self):
        self.result = {}
        colors = ['r', 'b', 'c', 'g']
        for self.nside, color in zip([32, 64, 128, 256], colors):
            nside = self.nside
            pca1 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm1.fits' +
                                        str(nside))
            pca2 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm2.fits' +
                                        str(nside))
            pca3 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm3.fits' +
                                        str(nside))
            gsm = 422.952 * (0.307706 * pca1 + -0.281772 * pca2 +
                             0.0123976 * pca3)
            equatorial_GSM = np.zeros(12 * nside**2, 'float')
            #rotate sky map
            for i in range(12 * nside**2):
                ang = hp.rotator.Rotator(coord='cg')(hpf.pix2ang(nside, i))
                equatorial_GSM[i] = hpf.get_interp_val(gsm, ang[0], ang[1])
            self.alm = sv.convert_healpy_alm(
                hp.sphtfunc.map2alm(equatorial_GSM), 3 * nside - 1)
            timer = time.time()
            self.result[nside] = self.vs.calculate_visibility(
                sv.expand_real_alm(self.alm),
                d=self.rot.dot(np.array([15.0, 21.0, 0.0])),
                freq=self.freq,
                nt=len(self.correct_result) - 1,
                L=3 * self.nside - 1,
                verbose=False)
            print(time.time() - timer) / 60., "minutes for nside = %i" % nside
            sys.stdout.flush()
            plt.plot(np.real(self.result[nside]), '%s--' % color)

        #plt.plot(np.real(self.correct_result), 'g--')
        #plt.plot(np.real(self.result32), 'r--', np.real(self.result64), 'b--', np.real(self.correct_result), 'g--')
        plt.show()
示例#4
0
 def test_visibility_fft(self):
     timer = time.time()
     self.result = self.vs.calculate_visibility(sv.expand_real_alm(
         self.alm),
                                                d=np.array([0, 3, 0]),
                                                freq=self.freq,
                                                nt=(6 * self.nside - 1),
                                                L=3 * self.nside - 1,
                                                verbose=False)
     print "Total time: %f" % (float(time.time() - timer) / 60)
     np.testing.assert_almost_equal(
         np.abs((self.result - self.correct_result) / self.correct_result),
         np.zeros(len(self.correct_result)), 5)
示例#5
0
 def test_visibility(self):
     self.result = self.vs.calculate_visibility(
         sv.expand_real_alm(self.alm),
         d=np.array([0, 3, 0]),
         freq=self.freq,
         tlist=np.arange(0, 24, 24. / (6 * self.nside - 1)),
         L=3 * self.nside - 1,
         verbose=False)
     #plt.plot(np.real(self.result), 'r--', np.real(self.correct_result), 'bs', np.imag(self.result), 'r--', np.imag(self.correct_result), 'bs')
     #plt.show()
     np.testing.assert_almost_equal(
         np.abs((self.result - self.correct_result) / self.correct_result),
         np.zeros(len(self.correct_result)), 5)
    def setUp(self):
        self.test_dir = os.path.dirname(os.path.realpath(__file__)) + '/'
        self.blmequ = sv.read_real_alm(self.test_dir + 'blm5.bin')
        self.blmax = 5
        self.freq = 150./300.*299.792458#my correct answers are computed with c=300,so im rescaing freq here to compensate
        self.zenithequ = sv.ctos(np.fromfile(self.test_dir + 'zenith.bin', dtype = 'float32'))[1:]
        self.zenithequ[0] = np.pi/2 - self.zenithequ[0]
        self.zenithequ = np.array(self.zenithequ)[::-1]
        self.blvequ = np.fromfile(self.test_dir + 'blv.bin', dtype = 'float32')
        self.correct_BB = sv.read_alm(self.test_dir + 'BB47.bin')
        self.correct_cm = np.fromfile(self.test_dir + 'cm47.bin', dtype = 'complex64')
        self.correct_result = np.fromfile(self.test_dir + 'final47.bin', dtype = 'complex64')# * (len(self.correct_cm))**0.5 #correct result did not use correct normalization n**0.5 in fourier
        self.nside = 16
        healpix = np.zeros(12*self.nside**2)
        healpix[420] = 1
        healpix[752] = 1
        self.alm = sv.convert_healpy_alm(hp.sphtfunc.map2alm(healpix), 3 * self.nside - 1)

        self.vs = sv.Visibility_Simulator()
        self.vs.initial_zenith = self.zenithequ
        self.vs.Blm = sv.expand_real_alm(self.blmequ)
示例#7
0
 def test_josh_gsm(self):
     self.nside = 32
     nside = self.nside
     pca1 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm1.fits' + str(nside))
     pca2 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm2.fits' + str(nside))
     pca3 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm3.fits' + str(nside))
     gsm = 422.952*(0.307706*pca1+-0.281772*pca2+0.0123976*pca3)
     equatorial_GSM = np.zeros(12*nside**2,'float')
     #rotate sky map
     for i in range(12*nside**2):
         ang = hp.rotator.Rotator(coord='cg')(hpf.pix2ang(nside,i))
         equatorial_GSM[i] = hpf.get_interp_val(gsm, ang[0], ang[1])
     self.alm = sv.convert_healpy_alm(hp.sphtfunc.map2alm(equatorial_GSM), 3 * nside - 1)
     self.result32 = self.vs.calculate_visibility(sv.expand_real_alm(self.alm), d=self.rot.dot(np.array([6.0,3.0,0.0])), freq=self.freq, nt=len(self.correct_result)-1, L = 3*self.nside-1, verbose = False)
     print self.result32[0], self.result32[-1]
     print self.correct_result[0], self.correct_result[-1]
     #self.nside = 64
     #nside = self.nside
     #pca1 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm1.fits' + str(nside))
     #pca2 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm2.fits' + str(nside))
     #pca3 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm3.fits' + str(nside))
     #gsm = 422.952*(0.307706*pca1+-0.281772*pca2+0.0123976*pca3)
     #equatorial_GSM = np.zeros(12*nside**2,'float')
     ##rotate sky map
     #for i in range(12*nside**2):
         #ang = hp.rotator.Rotator(coord='cg')(hpf.pix2ang(nside,i))
         #pixindex, weight = hpf.get_neighbours(nside,ang[0],ang[1])
         #for pix in range(len(pixindex)):
             #equatorial_GSM[i] += weight[pix]*gsm[pixindex[pix]]
     #self.alm = sv.convert_healpy_alm(hp.sphtfunc.map2alm(equatorial_GSM), 3 * nside - 1)
     #self.result64 = self.vs.calculate_visibility(sv.expand_real_alm(self.alm), d=self.rot.dot(np.array([6.0,3.0,0.0])), freq=self.freq, nt=len(self.correct_result)-1, L = 3*self.nside-1, verbose = False)
     #plt.plot(np.real(self.result32), 'r--', np.real(self.result64), 'b--', np.real(self.correct_result), 'g--')
     #plt.show()
     #plt.plot(np.imag(self.result32), 'r--', np.imag(self.result64), 'b--', np.imag(self.correct_result), 'g--')
     #plt.show()
     plt.plot(np.real(self.result32), 'r--', np.real(self.correct_result), 'g--')
     plt.show()
    def test_josh_gsm(self):
        self.result = {}
        colors = ['r','b','c','g']
        for self.nside, color in zip([32, 64, 128, 256], colors):
            nside = self.nside
            pca1 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm1.fits' + str(nside))
            pca2 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm2.fits' + str(nside))
            pca3 = hp.fitsfunc.read_map(self.test_dir + '/../data/gsm3.fits' + str(nside))
            gsm = 422.952*(0.307706*pca1+-0.281772*pca2+0.0123976*pca3)
            equatorial_GSM = np.zeros(12*nside**2,'float')
            #rotate sky map
            for i in range(12*nside**2):
                ang = hp.rotator.Rotator(coord='cg')(hpf.pix2ang(nside,i))
                equatorial_GSM[i] = hpf.get_interp_val(gsm, ang[0], ang[1])
            self.alm = sv.convert_healpy_alm(hp.sphtfunc.map2alm(equatorial_GSM), 3 * nside - 1)
            timer = time.time()
            self.result[nside] = self.vs.calculate_visibility(sv.expand_real_alm(self.alm), d=self.rot.dot(np.array([15.0,21.0,0.0])), freq=self.freq, nt=len(self.correct_result)-1, L = 3*self.nside-1, verbose = False)
            print (time.time() - timer)/60., "minutes for nside = %i"%nside
            sys.stdout.flush();
            plt.plot(np.real(self.result[nside]), '%s--'%color)

        #plt.plot(np.real(self.correct_result), 'g--')
        #plt.plot(np.real(self.result32), 'r--', np.real(self.result64), 'b--', np.real(self.correct_result), 'g--')
        plt.show()
 def test_visibility_fft(self):
     timer = time.time()
     self.result = self.vs.calculate_visibility(sv.expand_real_alm(self.alm), d=np.array([0,3,0]), freq=self.freq, nt=(6*self.nside-1), L = 3*self.nside-1, verbose = False)
     print "Total time: %f"%(float(time.time() - timer)/60)
     np.testing.assert_almost_equal(np.abs((self.result-self.correct_result)/self.correct_result), np.zeros(len(self.correct_result)), 5)
 def test_visibility(self):
     self.result = self.vs.calculate_visibility(sv.expand_real_alm(self.alm), d=np.array([0,3,0]), freq=self.freq, tlist=np.arange(0,24,24./(6*self.nside-1)), L = 3*self.nside-1, verbose = False)
     #plt.plot(np.real(self.result), 'r--', np.real(self.correct_result), 'bs', np.imag(self.result), 'r--', np.imag(self.correct_result), 'bs')
     #plt.show()
     np.testing.assert_almost_equal(np.abs((self.result-self.correct_result)/self.correct_result), np.zeros(len(self.correct_result)), 5)
示例#11
0
            sys.stdout.flush()
            ####rotate sky map and get alm
            print "Rotating GSM",
            sys.stdout.flush()
            GSMs[nside] = np.zeros((3, 12 * nside**2), 'float')
            for i in range(12 * nside**2):
                ang = g2e_rotator(hpf.pix2ang(nside, i))
                for j in range(3):
                    GSMs[nside][j, i] = hpf.get_interp_val(
                        pcas[j], ang[0], ang[1])
            print "Done."
        gsm_weights = gsm_weights_f(np.log(freqs[f]))
        print "GSM weights:", gsm_weights
        sys.stdout.flush()

        gsm = gsm_weights[0] * (gsm_weights[1] * GSMs[nside][0] +
                                gsm_weights[2] * GSMs[nside][1] +
                                gsm_weights[3] * GSMs[nside][2])
        alm = sv.convert_healpy_alm(hp.sphtfunc.map2alm(gsm), 3 * nside - 1)
        result = vs.calculate_visibility(sv.expand_real_alm(alm),
                                         d=ubl,
                                         freq=freqs[f],
                                         nt=nt,
                                         L=3 * nside - 1,
                                         verbose=True)
        result.astype('complex64').tofile(
            opdir +
            '/Visibilties_for_%i_south_%i_east_0_up_%s%s_pol_%.1f_MHz_%i_step.bin'
            % (unit_ubl[0], unit_ubl[1], pol, pol, freqs[f], nt))
        print "Time taken %.4f" % (float((time.time() - timer) / 60.))
        nside = min(nside, 512)
        L = nside*3 - 1
        print "Using nside = %i for GSM."%nside,
        sys.stdout.flush()
        if nside not in GSMs:
            print "Loading..."
            sys.stdout.flush()
            pcas = [hp.fitsfunc.read_map(datadir + '/gsm%i.fits'%(i+1) + str(nside), verbose=False) for i in range(3)]
            print "done.",
            sys.stdout.flush()
            ####rotate sky map and get alm
            print "Rotating GSM",
            sys.stdout.flush()
            GSMs[nside] = np.zeros((3,12*nside**2),'float')
            for i in range(12*nside**2):
                ang = g2e_rotator(hpf.pix2ang(nside,i))
                for j in range(3):
                    GSMs[nside][j,i] = hpf.get_interp_val(pcas[j], ang[0], ang[1])
            print "Done."
        gsm_weights = gsm_weights_f(np.log(freqs[f]))
        print "GSM weights:", gsm_weights
        sys.stdout.flush()

        gsm = gsm_weights[0]*(gsm_weights[1]*GSMs[nside][0] + gsm_weights[2]*GSMs[nside][1] + gsm_weights[3]*GSMs[nside][2])
        alm = sv.convert_healpy_alm(hp.sphtfunc.map2alm(gsm), 3 * nside - 1)
        result = vs.calculate_visibility(sv.expand_real_alm(alm), d=ubl, freq=freqs[f], nt=nt, L = 3*nside-1, verbose = True)
        result.astype('complex64').tofile(opdir+'/Visibilties_for_%i_south_%i_east_0_up_%s%s_pol_%.1f_MHz_%i_step.bin'%(unit_ubl[0],unit_ubl[1],pol,pol,freqs[f],nt))
        print "Time taken %.4f"%(float((time.time()-timer)/60.))