Ejemplo n.º 1
0
def plotCorrelationFunction():

    ####################################################################
    ### Simu

    ###
    for i in range(0, nbMocks__):
        plt.errorbar(numpy.arange(nbBin__), xi_dat__[:, i], fmt="o")
    plt.xlabel(r"$index \, bin$")
    plt.ylabel(r"$\xi_{Simu}(s)$")
    myTools.deal_with_plot(False, False, True)
    plt.show()

    ### mean:
    meanXi2D = numpy.mean(xi_dat__, axis=1)
    plt.errorbar(numpy.arange(nbBin__), meanXi2D, fmt="o")
    plt.xlabel(r"$index \, bin$")
    plt.ylabel(r"$<\xi_{Simu}(s)>$")
    myTools.deal_with_plot(False, False, True)
    plt.show()

    ### 2D:
    meanXi2D = myTools.convert1DTo2D(meanXi2D, nbBinY2D__, nbBinX2D__)
    myTools.plot2D(
        meanXi2D,
        [minX2D__, maxX2D__, minY2D__, maxY2D__],
        "s_{\perp} \, [h^{-1} Mpc]",
        "s_{\parallel} \, [h^{-1} Mpc]",
        "\\xi_{Simu}^{qf}",
    )

    ####################################################################
    ### Fit

    ###
    for i in range(0, nbMocks__):
        plt.errorbar(numpy.arange(nbBin__), xi_fit__[:, i], fmt="o")
    plt.xlabel(r"$index \, bin$")
    plt.ylabel(r"$\xi_{Fit}(s)$")
    myTools.deal_with_plot(False, False, True)
    plt.show()

    ### mean:
    meanXi2D = numpy.mean(xi_fit__, axis=1)
    plt.errorbar(numpy.arange(nbBin__), meanXi2D, fmt="o")
    plt.xlabel(r"$index \, bin$")
    plt.ylabel(r"$<\xi_{Fit}(s)>$")
    myTools.deal_with_plot(False, False, True)
    plt.show()

    ### 2D:
    meanXi2D = myTools.convert1DTo2D(meanXi2D, nbBinY2D__, nbBinX2D__)
    myTools.plot2D(
        meanXi2D,
        [minX2D__, maxX2D__, minY2D__, maxY2D__],
        "s_{\perp} \, [h^{-1} Mpc]",
        "s_{\parallel} \, [h^{-1} Mpc]",
        "\\xi_{Fit}^{qf}",
    )
Ejemplo n.º 2
0
	def plot_distortion_matrix(self):
	
		path = self._path_to_txt_file_folder + self._prefix + '_distortionMatrix_'+ self._middlefix + '.txt'
		matrix = numpy.loadtxt(path)
		
		### Blind the zero terms
		matrix[ (matrix==0.) ] = numpy.float('nan')

		myTools.plot2D(matrix)
		#myTools.plotCovar([matrix],['Distortion matrix'])

		return
Ejemplo n.º 3
0
def plotDataAndFit_2D():
    """
	"""

    ### but the xi from a flat array to a 2D array
    xxx = myTools.convert1DTo2D(xxx__, nbBinY2D__, nbBinX2D__)
    yyy_dat = myTools.convert1DTo2D(xi_dat__, nbBinY2D__, nbBinX2D__)
    yyy_fit = myTools.convert1DTo2D(xi_fit__, nbBinY2D__, nbBinX2D__)
    yyy_err = myTools.convert1DTo2D(xi_err__, nbBinY2D__, nbBinX2D__)
    yyy_res = myTools.convert1DTo2D(xi_res__, nbBinY2D__, nbBinX2D__)

    yyy_dat[(yyy_fit == 0.0)] = float("nan")
    yyy_err[(yyy_fit == 0.0)] = float("nan")
    yyy_res[(yyy_fit == 0.0)] = float("nan")
    yyy_fit[(yyy_fit == 0.0)] = float("nan")
    edge = [0.0, 200.0, -200.0, 200.0]

    ### Plot the arrays
    for i in numpy.arange(0, 3):

        coef = numpy.power(xxx, 1.0 * i)

        a = ""
        if i == 1:
            a += "|s|."
        elif i == 2:
            a += "|s|^{2}."

            ### data
        myTools.plot2D(
            coef * yyy_dat,
            edge,
            "s_{\\perp} \\, [h^{-1} Mpc]",
            "s_{\parallel} \\, [h^{-1} Mpc]",
            a + "\\xi_{Simu}(\\, \\overrightarrow{s} \\,)",
            "Simu",
        )
        ### Fit
        myTools.plot2D(
            coef * yyy_fit,
            edge,
            "s_{\\perp} \\, [h^{-1} Mpc]",
            "s_{\parallel} \\, [h^{-1} Mpc]",
            a + "\\xi_{Fit}(\\, \\overrightarrow{s} \\,)",
            "Fit",
        )
        ### residuals
        myTools.plot2D(
            coef * yyy_res,
            edge,
            "s_{\\perp} \\, [h^{-1} Mpc]",
            "s_{\parallel} \\, [h^{-1} Mpc]",
            a + "(\\xi_{Simu}-\\xi_{Fit})/\\xi_{error \, Simu}",
            "residuals",
        )

    return
Ejemplo n.º 4
0
def plotDataAndFit_2D():
	'''
	'''
	
	### but the xi from a flat array to a 2D array
	xxx     = numpy.zeros( shape=(100,50) )
	yyy_dat = numpy.zeros( shape=(100,50) )
	yyy_fit = numpy.zeros( shape=(100,50) )
	yyy_err = numpy.zeros( shape=(100,50) )
	
	for i in range(0,nbBin__):
		xxx[i/50][i%50]     = xxx__[i]
		yyy_dat[i/50][i%50] = xi_dat__[i]
		yyy_fit[i/50][i%50] = xi_fit__[i]
		yyy_err[i/50][i%50] = xi_err__[i]
	
	yyy_dat[ (yyy_fit==0.) ] = float('nan')
	yyy_err[ (yyy_fit==0.) ] = float('nan')
	yyy_fit[ (yyy_fit==0.) ] = float('nan')
	edge = [0., 200., -200., 200.]
	
	### Plot the arrays
	for i in numpy.arange(0,3):

		coef = numpy.power(xxx,1.*i)
		
		a = ''
		if (i==1):
			a += '|s|.'
		elif (i==2):
			a += '|s|^{2}.'
			
		### data
		myTools.plot2D(coef*yyy_dat, edge, 's_{\\perp} \\, [h^{-1} Mpc]', 's_{\parallel} \\, [h^{-1} Mpc]', a+'\\xi(\\, \\overrightarrow{s} \\,)', 'data')
		### Fit
		myTools.plot2D(coef*yyy_fit, edge, 's_{\\perp} \\, [h^{-1} Mpc]', 's_{\parallel} \\, [h^{-1} Mpc]', a+'\\xi(\\, \\overrightarrow{s} \\,)', 'fit')
		### residuals
		myTools.plot2D(coef*(yyy_dat-yyy_fit)/yyy_err, edge, 's_{\\perp} \\, [h^{-1} Mpc]', 's_{\parallel} \\, [h^{-1} Mpc]', a+'\\xi_{data}-\\xi_{fit}', 'residuals')
		
	return
Ejemplo n.º 5
0
def plot_cat():

	path = '/home/gpfs/manip/mnt0607/bao/Spectra/DR14Q_v1_0.fits'
	cat = pyfits.open(path, memmap=True)[1].data

	print "  The size of the catalogue is           : " + str(cat.size)
	cat = cat[ cat['RA']!=0. ]
	#print '  removed ra==0 : size = ', cat.size
	#cat = cat[ cat["Z"]>minRedshift__]
	#print "  We keep Z > " + str(minRedshift__) + "  , the size is      : " + str(cat.size)
	#cat = cat[ cat["Z"]<=maxRedshift__]
	#print "  We keep Z <= " + str(maxRedshift__) + "  , the size is      : " + str(cat.size)
	#cat = cat[ cat['MJD']>=55000]
	#print "  We keep MJD>=55000  , the size is      : " + str(cat.size)

	'''
	cut = [ [2.,2.5], [2.5,3.], [3.,3.5], [3.5,4.], [4.,4.5], [4.5,5.],[5.,5.96] ]
	for el in cut:
		a = cat[ numpy.logical_and( cat['Z']>=el[0],cat['Z']<el[1] ) ]
		print el[0], el[1], a.size
	'''

	print cat.size
	gal = cat['GAL_EXT'][:,0]
	psf = cat['PSFMAG'][:,0]

	
	### redshift
	ar1     = cat['RA']
	ar2     = cat['DEC']
	ar3     = cat['Z']
	nbBinsX = numpy.arange(0,360+5,5)
	nbBinsY = numpy.arange(-90,90+5,5)
	we      = numpy.ones(ar1.size)
	mean, err, number = myTools.Get_2DTProfile(ar1, ar2, ar3, nbBinsX, nbBinsY,we)
	mean[mean==0.] = numpy.float('nan')
	mean = numpy.transpose(mean)
	myTools.plot2D(mean)
	number[number==0.] = numpy.float('nan')
	number = numpy.transpose(number)
	myTools.plot2D(number)
	### gal extinction
	ar1     = cat['RA'][gal>0.]
	ar2     = cat['DEC'][gal>0.]
	ar3     = gal[gal>0.]
	nbBinsX = numpy.arange(0,360+5,5)
	nbBinsY = numpy.arange(-90,90+5,5)
	we      = numpy.ones(ar1.size)
	mean, err, number = myTools.Get_2DTProfile(ar1, ar2, ar3, nbBinsX, nbBinsY,we)
	mean[mean==0.] = numpy.float('nan')
	mean = numpy.transpose(mean)
	myTools.plot2D(mean)
	number[number==0.] = numpy.float('nan')
	number = numpy.transpose(number)
	myTools.plot2D(number)
	### psf
	ar1     = cat['RA'][psf>0.]
	ar2     = cat['DEC'][psf>0.]
	ar3     = psf[psf>0.]
	nbBinsX = numpy.arange(0,360+5,5)
	nbBinsY = numpy.arange(-90,90+5,5)
	we      = numpy.ones(ar1.size)
	mean, err, number = myTools.Get_2DTProfile(ar1, ar2, ar3, nbBinsX, nbBinsY,we)
	mean[mean==0.] = numpy.float('nan')
	mean = numpy.transpose(mean)
	myTools.plot2D(mean)
	number[number==0.] = numpy.float('nan')
	number = numpy.transpose(number)
	myTools.plot2D(number)
	

	### Geometry
	plt.errorbar(cat['RA'],cat['DEC'],fmt='o')
	plt.xlabel('RA')
	plt.ylabel('DEC')
        plt.show()
	### redshift
	plt.hist(cat['Z'],bins=100)
	plt.xlabel('Z')
	plt.show()
	### other
	plt.hist(gal[gal>0.],bins=100)
	plt.show()
	### other
	plt.hist(psf[psf>0.],bins=100)
	plt.show()
	### Geometry
	plt.errorbar(cat['Z'][gal>0.],gal[gal>0.],fmt='o',alpha=0.3)
	plt.show()
	### Geometry
	plt.errorbar(cat['Z'][psf>0.],psf[psf>0.],fmt='o',alpha=0.3)
	plt.show()

	return
		myTools.deal_with_plot(False,False,False)
		plt.xlim([ numpy.min(xxx)-10., numpy.max(xxx)+10. ])
		plt.show()
	
	return b1b2





path = '/home/gpfs/manip/mnt0607/bao/hdumasde/Results/Txt/FitsFile_DR12_Guy/xi_delta_QSO_distortionMatrix_2D_LYA_QSO.txt'
print path
data = numpy.loadtxt(path)
print data
print numpy.diag(data)
myTools.plot2D(data)
a = myTools.plotCovar([data],['a'])



#nbPixel = nbBin1D__
nbPixel = nbBin2D__

'''
#### Matrix from Nicolas
data = numpy.loadtxt("/home/gpfs/manip/mnt0607/bao/hdumasde/Code/CrossCorrelation/chain_annalys_delta/Correlation/run/xcf_v5_8_guy_c2_baseline.dmat")
distortionMatrix = numpy.zeros( shape=(nbBin2D__,nbBin2D__) )
save0 = data[:,0].astype(int)
save1 = data[:,1].astype(int)
save2 = data[:,2]
size = save2.size
Ejemplo n.º 7
0
plt.title(r'$1D: \, \delta_{LYA} \, - \, \delta_{LYA} $', fontsize=40)
plt.xlabel(r'$s \, [h^{-1}.Mpc]$', fontsize=40)
plt.ylabel(r'$\xi (s)$', fontsize=40)
myTools.deal_with_plot(False,False,True)
plt.xlim([ numpy.min(xi1D[:,0])-10., numpy.max(xi1D[:,0])+10. ])
plt.xlim([ 4., numpy.max(xi1D[:,0])+10. ])
plt.show()
		





cov1D = numpy.cov(numpy.load('/home/gpfs/manip/mnt0607/bao/hdumasde/Mock_JMLG/v1547/Results/xi_1D_delta_delta_LYA_result_cov.npy'))
myTools.plot2D(cov1D)
myTools.plot2D(myTools.getCorrelationMatrix(cov1D))













Ejemplo n.º 8
0
	plt.title(r'$\delta_{'+forest__+'} \, - \, \delta_{'+forest__+'}$', fontsize=40)
	plt.xlabel(r'$|s| \, [h^{-1}.Mpc]$', fontsize=40)
	myTools.deal_with_plot(False,False,True)
	plt.xlim([ numpy.min(xxx)-10., numpy.max(xxx)+10. ])
	plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
	plt.show()





ni = 10
nj = 10
saveListRealMocks(ni,nj)

'''
cov = numpy.load('/home/gpfs/manip/mnt0607/bao/hdumasde/Mock_JMLG/v1547/Results/xi_A_delta_delta_result_cov_1D.npy')
myTools.plot2D(cov)
myTools.plot2D(myTools.getCorrelationMatrix(cov))
myTools.plotCovar([cov],['a'])

cov = numpy.load('/home/gpfs/manip/mnt0607/bao/hdumasde/Mock_JMLG/v1547/Results/xi_A_delta_delta_result_cov_2D.npy')
myTools.plot2D(cov)
myTools.plot2D(myTools.getCorrelationMatrix(cov))
myTools.plotCovar([cov],['a'],50,50)
'''


#xi1D_, xi2D_, xiMu_, xiWe_ = loadData('/home/gpfs/manip/mnt0607/bao/hdumasde/Results/Txt/FitsFile_DR12_Guy_primery_correctedBadFit3/xi_A_delta_delta_Mu_LYA.txt','/home/gpfs/manip/mnt0607/bao/hdumasde/Results/Txt/FitsFile_DR12_Guy_primery_correctedBadFit3/xi_A_delta_delta_2D_LYA.txt')
#xi1D_, xi2D_, xiMu_, xiWe_ = loadData('/home/gpfs/manip/mnt0607/bao/hdumasde/Mock_JMLG/v1547/Box_000/Simu_000/Results/xi_A_delta_delta_Mu_LYA.txt','/home/gpfs/manip/mnt0607/bao/hdumasde/Mock_JMLG/v1547/Box_000/Simu_000/Results/xi_A_delta_delta_2D_LYA.txt')
Ejemplo n.º 9
0
plt.plot( x[cut]/1215.67-1., numpy.ones(x[cut].size)*0.133177484547 )
plt.show()


###
for i in range(5):
	y = corr[:,i]
	x = numpy.arange(y.size)
	cut = y!=0.
	plt.plot( x[cut], y[cut] )
plt.show()

###
#corr[ (numpy.abs(corr)>0.015)] = numpy.float('nan')
corr[ corr==0. ] = numpy.float('nan')
myTools.plot2D(corr)














Ejemplo n.º 10
0
def getACorrelation(nd,nr,nbRand,rawPath):
	'''

		Given a path to DD, DR, RR, return all the correlations.

		nd           : number of data
		nr           : number of random
		nbRand       : number of realisation of random
		rawPath : path to ASCII files

	'''

	### Which estimator
	LS = True
	### Plot or not
	plot = False

	print rawPath
	
	### Coef to normalize
	coefDD = nd*(nd-1.)/2.
	if (LS): coefDR = nd*nr
	coefRR = nr*(nr-1.)/2.

	### 2D: DD
	dd_2D = loadData2D(rawPath + 'xi_QSO_QSO_2D_QSO_DD.txt',coefDD)
	### Mu: DD
	dd_1D, dd_Mu, dd_We  = loadDataMu(rawPath + 'xi_QSO_QSO_Mu_QSO_DD.txt',coefDD)

	
	### 2D: RR,DR
	rr_2D = loadData2D(rawPath + 'xi_QSO_QSO_2D_QSO_RR_0.txt',coefRR)
	if (LS):
		dr_2D = loadData2D(rawPath + 'xi_QSO_QSO_2D_QSO_DR_0.txt',coefDR)
	### Mu: RR,DR
	rr_1D, rr_Mu, rr_We = loadDataMu(rawPath + 'xi_QSO_QSO_Mu_QSO_RR_0.txt',coefRR)
	if (LS):
		dr_1D, dr_Mu, dr_We = loadDataMu(rawPath + 'xi_QSO_QSO_Mu_QSO_DR_0.txt',coefDR)
	
	for i in range(1,nbRand):
	
		### 2D:
		rr_2D += loadData2D(rawPath + 'xi_QSO_QSO_2D_QSO_RR_'+str(i)+'.txt',coefRR)
	        if (LS):
			dr_2D +=  loadData2D(rawPath + 'xi_QSO_QSO_2D_QSO_DR_'+str(i)+'.txt',coefDR)
		### Mu:
		tmp_rr_1D, tmp_rr_Mu, tmp_rr_We = loadDataMu(rawPath + 'xi_QSO_QSO_Mu_QSO_RR_'+str(i)+'.txt',coefRR)
		rr_1D += tmp_rr_1D
		rr_Mu += tmp_rr_Mu
		rr_We += tmp_rr_We
		if (LS): 
			tmp_dr_1D, tmp_dr_Mu, tmp_dr_We = loadDataMu(rawPath + 'xi_QSO_QSO_Mu_QSO_DR_'+str(i)+'.txt',coefDR)
			dr_1D += tmp_dr_1D
			dr_Mu += tmp_dr_Mu
			dr_We += tmp_dr_We
		
	

	### 2D:
	rr_2D /= nbRand
	if (LS): dr_2D /= nbRand
	
	### Mu:
	rr_1D /= nbRand
	if (LS): dr_1D /= nbRand
	rr_Mu /= nbRand
	if (LS): dr_Mu /= nbRand
	rr_We /= nbRand
	if (LS): dr_We /= nbRand

	if (plot):
		### If plot
		plt.errorbar(rr_1D[:,0],rr_1D[:,1],fmt='o', label='RR')
		plt.errorbar(dr_1D[:,0],dr_1D[:,1],fmt='o', label='DR')
		plt.errorbar(dd_1D[:,0],dd_1D[:,1],fmt='o', label='DD')
		myTools.deal_with_plot(False,False,True)
		plt.show()

		### Plot 1D
		plt.errorbar(dd_1D[:,0], (dd_1D[:,0]-2.*dr_1D[:,0]+rr_1D[:,0])/dd_1D[:,0] )
		myTools.deal_with_plot(False,False,True)
		plt.show()

		### Plot 2D
		myTools.plot2D( (dd_2D[:,:,0]-2.*dr_2D[:,:,0]+rr_2D[:,:,0])/dd_2D[:,:,0] )

		### Plot 2D
		myTools.plot2D( (dd_Mu[:,:,0]-2.*dr_Mu[:,:,0]+rr_Mu[:,:,0])/dd_Mu[:,:,0] )

	### Get the Landy-Saley estimator
	if (LS): 
		### 1D:
		result_1D = numpy.array( dd_1D )
		result_1D[:,1] = (dd_1D[:,1]-2.*dr_1D[:,1]+rr_1D[:,1])/rr_1D[:,1]
		result_1D[:,2] = numpy.sqrt(dd_1D[:,1]*coefDD)/(coefDD*rr_1D[:,1])
		cut = (dd_1D[:,1]==0.)
		result_1D[:,1][cut] = 0.
		result_1D[:,2][cut] = 0.
	
		### 2D:
		result_2D = numpy.array( dd_2D )
		result_2D[:,:,1] = (dd_2D[:,:,1]-2.*dr_2D[:,:,1]+rr_2D[:,:,1])/rr_2D[:,:,1]
		cut = (dd_2D[:,:,1]==0.)
		result_2D[:,:,1][cut] = 0.
	
		### Mu:
		result_Mu = numpy.zeros(shape=(nbBin1D__,nbBinM__,3))
		result_Mu[:,:,0] = dd_Mu[:,:,0]
		result_Mu[:,:,1] = (dd_Mu[:,:,1] -2.*dr_Mu[:,:,1] + rr_Mu[:,:,1])/rr_Mu[:,:,1]
		result_Mu[:,:,2] = numpy.sqrt(dd_Mu[:,:,1]*coefDD)/(coefDD*rr_Mu[:,:,1])
		cut = (dd_Mu[:,:,1]==0.)
		result_Mu[:,:,2][cut] = 0.
		result_Mu[:,:,1][cut] = 0.
	
		### xiWe
		result_We = numpy.zeros(shape=(nbBin1D__,3,3))
		result_We[:,:,0] = dd_We[:,:,0]
		result_We[:,:,1] = (dd_We[:,:,1] -2.*dr_We[:,:,1] + rr_We[:,:,1])/rr_We[:,:,1]
		result_We[:,:,2] = numpy.sqrt(dd_We[:,:,1]*coefDD)/(coefDD*rr_We[:,:,1])
		cut = (dd_We[:,:,1]==0.)
		result_We[:,:,2][cut] = 0.
		result_We[:,:,1][cut] = 0.

	### Save
	numpy.save(rawPath+'xi_QSO_QSO_result_1D',result_1D)
	numpy.save(rawPath+'xi_QSO_QSO_result_2D',result_2D)
	numpy.save(rawPath+'xi_QSO_QSO_result_Mu',result_Mu)
	numpy.save(rawPath+'xi_QSO_QSO_result_We',result_We)

	result_Multipol = plotMultipol(result_Mu)
	numpy.save(rawPath+'xi_QSO_QSO_result_Multipol',result_Multipol)

	return result_1D, result_2D, result_Mu, result_We,result_Multipol