def __init__(self, whichSurvey, manifestf, noiseZones=False, redshiftSlices=False): self.whichSurvey = whichSurvey self.noiseZones = noiseZones self.redshiftSlices = redshiftSlices self.manifestf = manifestf self.manifest = numpy.genfromtxt(self.manifestf) # Extract selected z slices self.manifest = self.manifest[[s - 1 for s in whichRedshiftSlices], :] self.whichRedshiftSlices = whichRedshiftSlices if self.redshiftSlices: # self.datafiles=['%s/sdss_dr12s%i.txt'%(outdir,r) for r in self.whichRedshiftSlices] #(whichSurvey,r) self.datafiles = [ '%s/data_cos_s%i.txt' % (outdir, r) for r in self.whichRedshiftSlices ] #self.datafiles= ['sims/161101b/sim.txt'] self.datafile = self.datafiles[0] self.numRedshiftSlices = len( whichRedshiftSlices) #self.manifest.shape[0] self.redshifts = self.manifest[:, 3] self.redshifts_min = self.manifest[:, 1] self.redshifts_max = self.manifest[:, 2] self.sliceAreasTemp = self.manifest[:, 4] # Needs to be rejigged self.sliceNoisesTemp = self.manifest[:, 5] # Needs to be rejigged self.zsliceData = {} self.dls = {} self.dlds = {} self.Vmax = {} self.sliceAreas = {} self.sliceNoises = {} self.fmag = {} # Rejig z information for r in range(self.numRedshiftSlices): z = self.redshifts[r] z_min = self.redshifts_min[r] z_max = self.redshifts_max[r] dataf = self.datafiles[r] self.zsliceData[z] = self.loadData(dataf) self.dls[z] = cosmocalc(z, H0=Ho, WM=wm)['DCMR_Mpc'] self.fmag[z] = (numpy.log10(lumfuncUtils.get_Lbins(\ [self.zsliceData[z][1][-1]],z,self.dls[z])[0]) - \ numpy.log10(lumfuncUtils.get_Lbins([self.zsliceData[z][1][-2]],z,\ self.dls[z])[0]))/0.4 self.dlds[z] = lumfuncUtils.get_dlds(z, self.dls[z]) self.Vmax[z] = lumfuncUtils.get_Vmax(z_min, z_max) self.sliceAreas[z] = self.sliceAreasTemp[r] self.sliceNoises[z] = self.sliceNoisesTemp[r] elif self.noiseZones: pass return
def main(): """ """ print 'Settings file is %s' % setf # Import the settings variables set_module=importlib.import_module(setf) globals().update(set_module.__dict__) expt=countModel(modelFamily,nlaws,setf,[dataset],floatNoise) recon_expt=countModel(modelFamily,nlaws,setf,[dataset],floatNoise) #print expt.data #print expt.bins # Get MAP parameters print '\n'*5 print len(expt.parameters) ncols = len(expt.parameters) summf=os.path.join(outdir,'1-summary.txt') summary=numpy.genfromtxt(summf)[-1,:] drawmap=summary[-(ncols+2):-2] ana=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join(outdir,outstem)) drawmap=ana.get_best_fit()['parameters'] if dataset=='sdss': print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf)==20: num = dataf[-5] print num else: num = dataf[-6:-4] d=numpy.genfromtxt('%s/%s'%(outdir,datafiles[0][4:])) print datafiles[0][4:] elif dataset=='cosmos': print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf)==24: num = dataf[-5] print num else: num = dataf[-6:-4] d=numpy.genfromtxt('%s/%s'%(outdir,datafiles[0][8:])) print datafiles[0][8:] elif 'sim' in dataset: d=numpy.genfromtxt(os.path.join(outdir,'sim.txt')) #bins2 = numpy.arange(21.4,29.2,0.4) bins2 = numpy.arange(18.0,29.2,0.4) bins3 = numpy.arange(18.,29.2,0.1) print len(expt.parameters) print 'this is 1st num ', num #sys.exit() params = drawmap# [0] #for i in drawmap: # params.append(i) print params print expt.parameters #novak 2017 L_n =[21.77,22.15,22.46,22.77,23.09,23.34] rho_n =[-2.85,-2.88,-3.12,-3.55,-4.05,-4.63] L_ner_u =[0.23,0.18,0.19, 0.2, 0.21, 0.28] L_ner_d =[1.1, 0.15, 0.14, 0.12, 0.12, 0.048] rho_ner=[0.09, 0.03,0.0355,0.059,0.1,0.234] mcalpine=openlit('mcalpine-2013-tot.txt') padovani=openlit('Padovani_2015_RL_AGN')[1:] mcalpine_panels=[0,1,2,3,4,4,5,6,6] padovani_panels=[0,1,0,2,2,3,3,5,6,6] #print padovani print padovani[0][:,0],padovani[0][:,1],padovani[0][:,2],padovani[0][:,3] #sys.exit() #novak 2018 L_n2 =[[21.77,22.24,22.68,23.16,23.69,24.34, 24.74,25.56],\ [22.30,22.61,22.96,23.38,23.80,24.10, 24.55,25.14],\ [22.61,22.86,23.14,23.45,23.82,24.14, 24.40,24.71],\ [22.85,23.16,23.69,24.24,24.80,25.31, 25.96,26.69],\ [23.10,23.38,23.86,24.36,24.86,25.35, 25.94,26.36],\ [23.32,23.57,23.94,24.32,24.67,25.06, 25.47,25.96],\ [23.54,23.75,24.13,24.45,24.90,25.27, 25.74,26.10],\ [23.73,23.99,24.57,25.10,25.68,26.18, 26.83,27.51],\ [24.01,24.26,24.76,25.26,25.91,26.19, 27.45],\ [24.30,24.56,24.80,25.13,25.37,25.80, 25.97,26.49]] L_ner_u2 =[[0.23,0.27, 0.34, 0.37, 0.35, 0.21, 0.31, 0.03],\ [0.11,0.20, 0.26, 0.25, 0.24, 0.35, 0.31, 0.15],\ [0.08,0.15, 0.20, 0.22, 0.17, 0.18, 0.24, 0.28],\ [0.072,0.33,0.38, 0.40, 0.48, 0.42, 0.41, 0.28],\ [0.080,0.30,0.32, 0.32, 0.32, 0.33, 0.24, 0.34],\ [0.068,0.22,0.24, 0.25, 0.29, 0.30, 0.28, 0.21],\ [0.067,0.22,0.21, 0.26, 0.18, 0.17,0.075, 0.11],\ [0.093,0.36,0.31, 0.30, 0.25, 0.28, 0.16,0.028],\ [0.076,0.34,0.36, 0.38, 0.24, 0.47, 0.27],\ [0.097,0.14,0.20, 0.16, 0.23, 0.092,0.22,0.026]] L_ner_d2 =[[1.0, 0.24, 0.17, 0.14, 0.16, 0.30, 0.20, 0.50],\ [0.29, 0.21, 0.15, 0.16, 0.17, 0.06, 0.099,0.29],\ [0.24, 0.17, 0.12, 0.10, 0.15, 0.15, 0.08,0.074],\ [0.16, 0.24, 0.19, 0.17, 0.15, 0.09, 0.16, 0.33],\ [0.30, 0.19, 0.18, 0.18, 0.18, 0.17, 0.26, 0.18],\ [0.14, 0.18, 0.15, 0.14, 0.10, 0.095,0.11, 0.21],\ [0.19, 0.14, 0.15, 0.11, 0.19, 0.19, 0.29, 0.28],\ [0.40, 0.17, 0.21, 0.23, 0.27, 0.25, 0.37, 0.53],\ [0.20, 0.17, 0.16, 0.14, 0.27, 0.042, 0.27],\ [0.22, 0.16, 0.10, 0.14,0.072, 0.21, 0.08, 0.30]] rho_n2 =[[-2.84,-2.90,-3.34,-4.00,-4.92,-4.92, -5.22,-5.07],\ [-2.95,-3.17,-3.46,-4.24,-4.76,-5.41, -5.23,-5.44],\ [-2.95,-3.11,-3.44,-3.81,-4.37,-4.48, -4.90,-5.14],\ [-2.99,-3.24,-3.89,-4.54,-5.27,-5.33, -5.69,-5.89],\ [-3.32,-3.51,-4.06,-4.74,-5.28,-5.43, -6.08,-5.70],\ [-3.29,-3.54,-4.02,-4.45,-5.11,-5.56, -5.37,-6.07],\ [-3.43,-3.61,-4.19,-4.56,-5.09,-5.34, -5.70,-5.75],\ [-3.88,-3.98,-4.64,-5.33,-5.73,-6.27, -6.14,-6.77],\ [-3.85,-4.28,-5.05,-5.60,-5.68,-6.44, -6.59],\ [-4.43,-4.91,-5.46,-5.58,-5.89,-6.23, -6.26,-6.91]] rho_ner_u2=[[0.08,0.024,0.038,0.083,0.28,0.28 , 0.45, 0.34],\ [0.048,0.027,0.036,0.089,0.17,0.45, 0.34, 0.45],\ [0.062,0.024,0.032,0.048,0.096, 0.11,0.18,0.25],\ [0.042,0.018,0.035,0.073,0.180, 0.20,0.34,0.45],\ [0.045,0.019,0.033,0.072,0.15, 0.17,0.45,0.25],\ [0.040,0.022,0.033,0.055,0.13, 0.22,0.17,0.45],\ [0.061,0.020,0.035,0.055,0.099, 0.14,0.22,0.25],\ [0.044,0.022,0.044,0.11, 0.16, 0.34, 0.28,0.76],\ [0.048,0.025,0.058,0.13, 0.24, 0.34, 0.45],\ [0.084,0.058,0.11 ,0.24, 0.20, 0.28, 0.28,0.76]] rho_ner_d2=[[0.07,0.023,0.035,0.070,0.25,0.25 , 0.37, 0.30],\ [0.043,0.026,0.033,0.074,0.16,0.37, 0.30, 0.37],\ [0.054,0.023,0.030,0.043,0.079,0.086,0.17,0.22],\ [0.038,0.017,0.032,0.062,0.17,0.19, 0.30, 0.37],\ [0.041,0.019,0.031,0.062,0.11,0.16, 0.37, 0.22],\ [0.037,0.021,0.031,0.049,0.098,0.20,0.16, 0.37],\ [0.054,0.019,0.032,0.049,0.081,0.11,0.20, 0.22],\ [0.040,0.021,0.040,0.085,0.15, 0.30, 0.25,0.52],\ [0.043,0.024,0.051,0.10, 0.15, 0.30, 0.37],\ [0.070,0.051,0.087,0.16,0.19, 0.25, 0.25, 0.52]] fig = plt.figure() pre_chain='12' #pre_chain='01' chains=['12a','12b','12c','12d','12e','12f','12g','12h','12i']#chains_191062 chains=['22a','22b','22c','22d','22e','22f','22g','22h','22i'] chains=['32a','32b','32c','32d','32e','32f','32g','32h','32i'] chains=['42a','42b','42c','42d','42e','42f','42g','42h','42i'] chains=['62a_2','62b_2','62c_2','62d_2','62e_2','62f_2','62g_2','62h_2','62i_2'] #chains_191062 chains=['01a_3','01b_3','01c_3','01d_3','01e','01f_3','01g_3','01h_3','01i_3']#chains_191101 chains=['01a_4','01b_4','01c_4','01d_4','01e_4','01f_4','01g_4','01h_4','01i_4_2']#chains_191101 7x7 grid chains=['02a_4','02b_4','02c_4','02d_4','02e_4','02f_4','02g_5','02h_4','02i_4']#chains_191101 7x7 grid lognorm #chains=['01a_5','01b_5','01c_5','01d_5','01e_5','01f_5','01g_5','01h_5','01i_5']#chains_191101 3x3 grid scaled #chains=['01a_6','01b_6_3','01c_6','01d_6_2','01e_6_2','01f_6','01g_6_2','01h_6_2','01i_6_2']#chains_191101 11x11 grid #chains=['01a','01b','01c','01d','01e','01f','01g','01h','01i'] #chains_1912 #includeing maskregion chains=['01a_2_1','01b_2_1','01c_2_1','01d_2','01e_2','01f_2','01g_2','01h_2','01i_2'] #1912 exclding peterinclde match #chains=['01a_2','01b_2','01c_2_1','01d_2','01e_2','01f_2','01g_2','01h_2','01i_2'] #chains_1912 excluding peter #chains=['01a_3','01b_3','01c_3','01d_3','01e_3','01f_3_1','01g','01h','01i'] #chains_1912 including peter #chains=['01a_4_1','01b_4_1','01c_4','01d_4','01e_4','01f_4_1','01g_4','01h_4','01i_4'] #chains_1912 no mass selection chains=['02a','02b_2','02c','02d','02e','02f','02g','02h','02i'] #lgnorm #chains_1912 excluding peter chains=['01a_1','01b','01c','01d','01e','01f_1','01g','01h','01i'] #chains_2001 DR4 chains4=['01a_4','01b_2','01c_2','01d_2','01e_2','01f_2','01g','01h_2','01i_2'] #chains_2001 DR4 remove phi2 #chains=['01a_9','01b_9','01c_9','01d_9','01e_9','01f_9','01g_9','01h_9','01i_9','01j_9'] #chains_2001 DR4 dpl_dpl no mass selection chains=['01a_7','01b_7','01c_7','01d_7','01e_7','01f_7','01g_7','01h_7','01i_7','01j_7'] #chains_2001 DR4 dpl_dpl chains4=['01a_6','01b_6','01c_6','01d_6','01e_6_3','01f_6','01g_6','01h_6','01i_6','01j_6'] #chains_2001 DR4 dpl_dpl Lmin=15 #chains=['01a_6_3','01b_6_3','01c_6_3','01d_6_2','01e_6_2','01f_6_2','01g_6_2','01h_6_3','01i_6_3','01j_6_3'] #chains_2001 DR4 dpl_dpl Lmin=21 chains2=['02a_z_6x','02b_z_6x','02c_z_6x','02d_z_6x','02e_z_6x','02f_z_6x','02g_z_6x','02h_z_6x','02i_z_6x','02j_z_6x']#Novak individual model chains2=['02a_z_6x_1','02a_z_6x_2','02b_z_7x','02c_z_7x','02d_z_7x','02e_z_7x','02f_z_7x','02g_z_7x','02h_z_7x','02i_z_7x','02j_z_7x']#Novak individual model newz #chains=['02a_4','02b_3','02c_4','02d_4','02e_4','02f_4','02g_4','02h_4','02i_4','02j_3'] ##chains_2001 DR4 logn_dpl Lmin=19 #chains=['01a_9_2','01b_9_2','01c_9_2','01d_9_2','01e_9_2_1','01f_9_2','01g_9_2_2','01h_9_2','01i_9_2_1','01j_9_2_1'] #chains_2001 DR4 dpl_dpl no mass selection fixed zmean #chains=['01a_6_1','01a_8_2','01b_6_3','01c_6_3','01d_6_2','01e_6_2','01f_6_2','01g_6_2','01h_6_3','01i_6_3','01j_6_3'] #chains_2001 DR4 dpl_dpl Lmin=19 newz #chains=['02a_4','02b_4','02c_4','02d_4','02e_4','02f_4','02g_4','02h_4','02i_4','02j_3'] ##chains_2001 DR4 logn_dpl Lmin=21 newz #chains=['02a_z_6x','02b_z_7x','02c_z_7x','02d_z_7x','02e_z_7x','02f_z_7x','02g_z_7x','02h_z_7x','02i_z_7x','02j_z_7x']#Novak individual model newz chains=['01a_1','01b_1','01c_1','01d_1','01e_1','01f_1','01g_1','01h_1','01i_1','01j_1'] #95% mass sample chains=['02a_z_9x','02b_z_9x','02c_z_9x','02d_z_9x','02e_z_9x','02f_z_9x','02g_z_9x','02h_z_9x','02i_z_9x','02j_z_9x']#95 mass limit chains=['01a_2','01b_2','01c_2','01d_2','01e_2','01f_2','01g_2','01h_2','01i_2','01j_2'] #50% mass sample chains=['02a_z_9x_1','02b_z_9x_1','02c_z_9x_1','02d_z_9x_1','02e_z_9x_1','02f_z_9x_1','02g_z_9x_1','02h_z_9x_1','02i_z_9x_1','02j_z_9x_1']#50 mass limi1 chains2=['01a_5','01b_5','01c_5','01d_5','01e_5','01f_5','01g_5','01h_5','01i_5','01j_5'] #stellar mass>10.2 dpl chains2=['02a_5','02b_5','02c_5','02d_5','02e_5','02f_5','02g_5','02h_5','02i_5','02j_5'] #stellar mass>10.2 dpl chains=['02a_z_7x','02b_z_7x','02c_z_7x','02d_z_7x','02e_z_7x','02f_z_7x','02g_z_7x','02h_z_7x','02i_z_7x','02j_z_7x'] #stellar mass>10.2 chains=['01a_8','01b_8','01c_8','01d_8','01e_8','01f_8','01g_8','01h_8','01i_8','01j'] #stellar mass<10. dpl chains4=['02a_3','02b_3','02c_3','02d_3','02e_3','02f_3','02g_3','02h_3','02i_3','02j_3'] #stellar mass<10. logn chains3=['02a_z_5x','02b_z_5x','02c_z_5x','02d_z_5x','02e_z_5x','02f_z_5x','02g_z_5x','02h_z_5x','02i_z_5x','02j_z_5x']#stellar mass limit mass<10 #chains3=['02a_z_5f','02b_z_5f','02c_z_5f','02d_z_5f','02e_z_5f','02f_z_5f','02g_z_5f','02h_z_5f','02i_z_5f','02j_z_8x']#stellar mass limit mass<10 #chains=['01a','01b','01c','01d','01e','01f','01g','01h','01i','01j'] #dpl #chains_2001 DR4 newz new_area chains=['02a','02b','02c','02d','02e','02f','02g','02h','02i','02j'] #lgnorm #chains_2001 DR4 newz new_area chains=['02a_z_8x','02b_z_8x','02c_z_8x','02d_z_8x','02e_z_8x','02f_z_8x','02g_z_8x','02h_z_8x','02i_z_8x','02j_z_8x']#fixed model newz area chains=['02a_z_8x_6','02b_z_8x_6','02c_z_8x_6','02d_z_8x_6','02e_z_8x_6','02f_z_8x_6','02g_z_8x_6','02h_z_8x_6','02i_z_8x_6','02j_z_8x_6']#fixed cut data more bins _el lmin lose chains=['02a_z_8x_6_1','02b_z_8x_6_1','02c_z_8x_6_1','02d_z_8x_6_1','02e_z_8x_6_1','02f_z_8x_6_1','02g_z_8x_6_3','02h_z_8x_6_3','02i_z_8x_6_3','02j_z_8x_6_3']#fixed cut data more bins _el lmin lose #chains3='02z_31_3' #Novak evolution fit #chains3='02z_31_5' #Fixed evolution newz, area #chains3='02z_31_6' #Fixed evolution newz, area, 10.2 mass lim #z = [0, 0.5, 1 , 1.5, 2, 2.3, 2.6, 3, 3.5, 4] #old #z = [ 0.7, 1 , 1.35, 1.7, 2, 2.3, 2.6, 3, 3.5, 4]# older print expt.parameters n,m=3,3 #print xrecon #print yrecon #sys.exit() z_new=True Replot=False z_nov = [0.31, 0.5, 0.69, 0.9, 1.16, 1.44, 1.81, 2.18, 2.81, 3.71, 4.83] if z_new: z =[0.1,0.3,0.4,0.6,0.8,1.0,1.3,1.6,2.0,2.5,3.2,4.0] z=[0.1,0.4,0.6,0.8,1.0,1.3,1.6,2.0,2.5,3.2,4.0]#oldest ;) #chains=['11a','11b','11c_3','11d_3','11e_3','11f_3','11g_3','11h','11i','11j', '11k', '11l' ,'11m', '11n']#chains_201111 else: z=[0.1,0.4,0.6,0.8,1.0,1.3,1.6,2.0,2.5,3.2,4.0]#oldest ;) #ana3=pymultinest.analyse.Analyzer(ncols-1,\ # outputfiles_basename=os.path.join('chains_2002%s'%chains3,outstem)) #drawmap3=ana3.get_best_fit()['parameters'] #params3 = drawmap3 #parameters2= ['noise', 'A_SF', 'A_agn', 'LMIN', 'LMAX'] #parameters3= ['noise', 'A_agn', 'A_SF', 'B_agn', 'B_SF', 'LMIN', 'LMAX'] #parameters3= ['noise', 'A_agn', 'A_SF', 'B_agn', 'B_SF', 'LMIN_1', 'LMIN_2', 'LMIN_3', 'LMIN_4', 'LMIN_5', 'LMIN_6', 'LMIN_7', 'LMIN_8', 'LMIN_9', 'LMIN', 'LMAX'] #parameters4=['noise', 'LMIN', 'LMAX2', 'LMIN2', 'LMAX', 'LNORM', 'LSTAR', 'LSLOPE', 'LSLOPE2', 'LNORM_2', 'LSTAR_2', 'LSLOPE_2', 'LSLOPE2_2'] parameters2= ['noise', 'A_SF', 'A_agn', 'LMIN', 'LMAX'] parameters3= ['noise', 'LMIN', 'LMAX', 'LNORM_2', 'LSTAR_2', 'LSLOPE_2', 'LSLOPE2_2'] parameters4= ['noise', 'LMIN', 'LMAX', 'LNORM_2', 'LSTAR_2', 'LSLOPE_2', 'LSIGMA'] #lognorm parameters2=['noise', 'LMIN', 'LMAX2', 'LMIN2', 'LMAX', 'LNORM', 'LSTAR', 'LSLOPE', 'LSLOPE2', 'LNORM_2', 'LSTAR_2', 'LSLOPE_2', 'LSLOPE2_2'] parameters3= ['noise', 'A_SF', 'A_agn', 'LMIN', 'LMAX']#fixed parameters2=['noise', 'LMIN', 'LMAX2', 'LMIN2', 'LMAX', 'LNORM', 'LSTAR', 'LSLOPE', 'LSLOPE2', 'LNORM_2', 'LSTAR_2', 'LSLOPE_2', 'LSIGMA'] pass1=False for num in range(1,11): #num = 1. print num if num==2:pass1=False print 'new num ',num z_min,z_max, z_m = get_z(num) dl = get_dl(z_m) Vmax = get_Vmax(z_min,z_max) dsdl = get_dsdl(z_m,dl) #z_m = (z_min + z_max)/2 dl = get_dl(z_m) print z_min,z_max print expt.kind area = SURVEY_AREA*sqDeg2sr area1 = SURVEY_AREA*sqDeg2sr print SURVEY_AREA ana=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join('chains_20%s%s'%(pre_chain,chains[num-1]),outstem)) drawmap=ana.get_best_fit()['parameters'] drawmid=ana.get_stats()['marginals'] params = drawmap ana2=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join('chains_20%s%s'%('11',chains2[num-1]),outstem)) drawmap2=ana2.get_best_fit()['parameters'] params2 = drawmap2 ana3=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join('chains_20%s%s'%(pre_chain,chains3[num-1]),outstem)) drawmap3=ana3.get_best_fit()['parameters'] params3 = drawmap3 ana4=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join('chains_20%s%s'%('11',chains4[num-1]),outstem)) drawmap4=ana4.get_best_fit()['parameters'] params4 = drawmap4 settingf='chains_20%s%s/bayestack_settings.py'%(pre_chain,chains[num-1]) f = open(settingf, 'r') mod = f.readlines()[31].split()[0] print mod if 'logn' in mod: if 'dpl' in mod: model='LFlognorm_dpl' elif '_el' in mod: model='LFevol_logn_el' elif 'pl_' in mod: model='LFpl_lognorm' elif 'phi' in mod: model='LFevol_phi_logn_mat' elif 'mat' in mod: model='LFevol_logn_mat' else: model='LFlognorm' elif 'LFdpl' in mod or 'LFpl' in mod: if 'LFdpl_dpl' in mod: model='LFdpl_dpl' elif '_pl' in mod: model='LFdpl_pl' elif 'LFpl_' in mod: model='LFpl_dpl' elif 'LFpl' in mod: model='LFpl' else: model = 'LFdpl' with open('chains_20%s%s/params.tex'%(pre_chain,chains[num -1])) as f: parameters=[line.split(None,1)[0] for line in f] #model='LFdpl_pl' print parameters print model print 'LSIGMA' in parameters ''' if model in ['LFsch','LFdpl_pl','LFpl_dpl','LFdpl_dpl','LFlognorm_dpl','LFpl_lognorm']: Lnorm=params[parameters.index('LNORM')] Lstar=params[parameters.index('LSTAR')] Lslope=params[parameters.index('LSLOPE')] #Lzevol=params[parameters.index('LZEVOL')] if model in ['LFdpl_pl','LFpl_dpl','LFdpl_dpl','LFlognorm_dpl']: Lslope2=params[parameters.index('LSLOPE2')] if model in ['LFlognorm','LFpl', 'LFdpl', 'LFdpl_pl','LFpl_dpl', 'LFlognorm_dpl','LFpl_lognorm','LFdpl_dpl']: Lnorm_2=params[parameters.index('LNORM_2')] Lstar_2=params[parameters.index('LSTAR_2')] Lslope_2=params[parameters.index('LSLOPE_2')] if model in ['LFdpl_dpl','LFdpl']: Lslope2_2=params[parameters.index('LSLOPE2_2')] if model in ['LFlognorm','LFlognorm_dpl','LFpl_lognorm']: Lsigma = params[parameters.index('LSIGMA')] ''' Lmin=params[parameters.index('LMIN')] Lmax=params[parameters.index('LMAX')] #Lmin=params[expt.parameters.index('LMIN')] #Lmax=params[expt.parameters.index('LMAX')] SMIN = get_sbins(numpy.power(10,Lmin),z_m,dl)*1e6 SMAX = get_sbins(numpy.power(10,Lmax),z_m,dl)*1e6 sigma,fsigma,Lmin = numpy.log10(get_Lbins([SURVEY_NOISE,18.9, Lmin],z_m,dl,'muJy')*(1.4/3)**(-.7)) sigma2,fsigma2 = numpy.log10(get_Lbins([450,2400],z_m,dl,'muJy')) print z_m,dl, sigma,fsigma print SURVEY_NOISE,SURVEY_NOISE*5,SURVEY_AREA s=numpy.loadtxt('chains_20%s%s/recon_stats.txt'%(pre_chain,chains[num -1])) s2=numpy.loadtxt('chains_20%s%s/recon_stats.txt'%('11',chains2[num -1])) s3=numpy.loadtxt('chains_20%s%s/recon_stats.txt'%(pre_chain,chains3[num -1])) s4=numpy.loadtxt('chains_20%s%s/recon_stats.txt'%('11',chains4[num -1])) xrecon=s[:-1,0]; yrecon=s[:-1,1] yrecon_d=s[:-1,2]; yrecon_u=s[:-1,3] yrecon_rms = s[:-1,4] yrecon_avr = s[:-1,5] yrecon_rms_down = yrecon_rms xreco = get_Lbins(xrecon,z_m,dl,'muJy')#*(1.4/3)**(-.7) yreco = yrecon lin_yrecon = numpy.log10(yreco) lin_xrecon = numpy.log10(xreco) xrecon2=s2[:-1,0]; yrecon2=s2[:-1,1] yrecon_d2=s2[:-1,2]; yrecon_u2=s2[:-1,3] lin_xrecon2 = numpy.log10(get_Lbins(xrecon2,z_m,dl,'muJy')) xrecon3=s3[:-1,0]; yrecon3=s3[:-1,1] yrecon_d3=s3[:-1,2]; yrecon_u3=s3[:-1,3] lin_xrecon3 = numpy.log10(get_Lbins(xrecon3,z_m,dl,'muJy')) xrecon4=s4[:-1,0]; yrecon4=s4[:-1,1] yrecon_d4=s4[:-1,2]; yrecon_u4=s4[:-1,3] lin_xrecon4 = numpy.log10(get_Lbins(xrecon4,z_m,dl,'muJy')) bins2 = numpy.arange(15.,25.,0.4) bins = numpy.arange(fsigma-0.4,29.2,0.4)#bin +0.2 if not os.path.isfile('cos_data/cos_s%s_LF.el'%num) and z_new or not os.path.isfile('cos_data/cos_s%s_LF.el'%num) and not z_new or Replot: print 'doing all calculations' #l,z_l = open_anytype('cos_data/cosmos_d1_0_8arc.txt',(12,21), F='uJy',L=True,getz=True) #l2,z_l2 = open_anytype('cos_data/cosmos_d1_0_8arc.txt',(12,24), F='uJy',L=True,getz=True) if z_new: L,z_L = open_anytype('cos_data/cos_s%s.txt'%num,(2,3), F='uJy',L=True,getz=True,band='S') print 'this is the new z bins (please check if lumfuncUtils and cos_manifest are using the right z)' else: L,z_L = open_anytype('cos_data/cos_s%s.txt'%num,(2,3), F='uJy',L=True,getz=True,band='S') print 'this is the old z binning style. (please check if lumfuncUtils and cos_manifest are using the right z)' L_c,z_c=open_anytype('cosmos_counter_parts_II.txt',(3,4),[z_min,z_max], F='uJy',L=True,getz=True, band='S') z_c2,S_c2,L_c2 =numpy.loadtxt('cosmos_counter_parts_II.txt',unpack=True, usecols=(3,4,5)) L_c2,z_c2=open_anytype('cosmos_comp_vla.el',(2,3),[z_min,z_max], F='uJy',L=True,getz=True, band='S') L_c3,z_c3=open_anytype('cosmos_vla.el',(2,3),[z_min,z_max], F='uJy',L=True,getz=True, band='S') L_c4,z_c4=open_anytype('/home/eliab/Documents/OC/Project/cosmos/Cosmos/dr4_cos2015_vla.tx',(-4,-1),[z_min,z_max], F='uJy',L=True,getz=True, band='S') L_c5,z_c5=open_anytype('/home/eliab/Documents/OC/Project/cosmos/Cosmos/dr4_cos2015_vla.tx',(3,-1),[z_min,z_max], F='uJy',L=True,getz=True, band='S') #L_c2=L_c2[(z_c2<z_max)&(z_c2 >z_min)] #S_c2=S_c2[(z_c2<z_max)&(z_c2 >z_min)] #z_c2=z_c2[(z_c2<z_max)&(z_c2 >z_min)] #rho_1,er1 = calc_Vmax(calcu_zeff(z_l,l,11.5e-32),l,bins,z_max,z_min,area) #rho_2,er2 = calc_Vmax(calcu_zeff(z_l2,l2,11.5e-32),l2,bins,z_max,z_min,area) rho_3,er3,b3,n3 = calc_Vmax(calcu_zeff(z_L,L,1.15e-31),L,bins,z_max,z_min,area,table=True) #rho_4,er4 = calc_Vmax(99.,L,bins2,z_max,z_min,area) print 'COS15 VLA' rho_5,er5,b5,n5 = calc_Vmax(calcu_zeff(z_c,L_c,1.15e-31),L_c,bins,z_max,z_min,1.77*sqDeg2sr,table=True) print 'mass lim DR4-vla' rho_6,er6,b6,n6 = calc_Vmax(calcu_zeff(z_c2,L_c2,1.15e-31),L_c2,bins,z_max,z_min,1.5*sqDeg2sr,table=True) print 'DR4-vla' rho_7,er7,b7,n7 = calc_Vmax(calcu_zeff(z_c3,L_c3,1.15e-31),L_c3,bins,z_max,z_min,1.5*sqDeg2sr,table=True) print 'cos-DR4-vla DR4 photo-z' rho_8,er8,b8,n8 = calc_Vmax(calcu_zeff(z_c4,L_c4,1.15e-31),L_c4,bins,z_max,z_min,1.5*sqDeg2sr,table=True) print 'cos-DR4-vla COS15 photo-z' rho_9,er9,b9,n9 = calc_Vmax(calcu_zeff(z_c5,L_c5,1.15e-31),L_c5,bins,z_max,z_min,1.5*sqDeg2sr,table=True) for i in range(len(b5)): print '%5.2f %7d %10d %13d %17d %11d'%(b5[i],n3[i],n7[i],n8[i],n9[i],n5[i]) if z_new: f = open('cos_data/cos_s%s_LF_4.el'%num,'w') #I used LF_2 for the final results, _5 for stellar-mass 10.2 print 'saving data for future use in cos_data/cos_s%s_LF_4.el'%num else: f = open('cos_data/cos_s%s_LF_old.el'%num,'w') print 'saving data for future use in cos_data/cos_s%s_LF.el'%num for i in range(len(bins)): f.write('%5.1f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f\n'%(bins[i], rho_3[i],er3[i],rho_5[i],er5[i],rho_6[i],er6[i],rho_7[i],er7[i],rho_8[i],er8[i],rho_9[i],er9[i]) ) f.close() dl_c=get_dl(z_c2) L_c3=numpy.log10(get_Lbins(S_c2,z_c2,numpy.array(dl_c),'muJy')*(1.4/3.)**(-.7)) else: if z_new: bins,rho_3,er3,rho_5,er5,rho_6,er6 ,rho_7,er7 ,rho_8,er8 ,rho_9,er9 = numpy.loadtxt('cos_data/cos_s%s_LF_2.el'%num, unpack=True) print 'Using stored RLF for the new z (The one with more z bins). If you want to calculate the plot the set "Replot=True"' else: bins,rho_3,er3,rho_5,er5,rho_6,er6 = numpy.loadtxt('cos_data/cos_s%s_LF_old.el'%num, unpack=True) print 'Using stored RLF for the is old z bins. If you want to calculate the plot the set "Replot=True"' #ssd = numpy.loadtxt('%s/data_cos_s%s.txt'%(outdir,num)) ssd = numpy.loadtxt('cos_data/cos_s%s.txt'%(num), unpack=True, usecols=(-1,2)) ssbin2 = ssd[:,0] #2 ssbin1 = ssd[:,2] #0 Nbin2 = ssd[:,3] zbin3 = ssd[:,-1] dl1 = get_dl(z_min) dl2 = get_dl(z_max) #dl3 = get_dl(zbin3) Ncount = sum(Nbin2[fsigma>ssbin1]) Llmin = numpy.log10(get_Lbins([fsigma/numpy.sqrt(Ncount)],z_min,get_dl(z_min),'muJy'))[0] Llmin*=(1.4/3.)**(-.7) print Llmin #sys.exit() if z_new: try:pos=get_changed_multiplot(n,m,num) except:print 'changed pos doesnt work for ',num if num==4: pos = 10 elif num==8: pos=11 elif num==10: pos=11 elif num==11: pos=11 if num>4 and num!=8: n_s = 1 if num>8: n_s+=1 pos=get_changed_multiplot(n,m,num-n_s) ax=fig.add_subplot(n+1,m,pos) print 'plot change', n, m ,pos else: ax=fig.add_subplot(n,m,get_changed_multiplot(n,m,num)) plt.rc('lines', linewidth=2) #plt.errorbar(bins,rho_1 ,yerr=er1,fmt='*r',label='detected extracted',markersize=11) #bin ''' if model in ['LFdpl','LFdpl_dpl']: faint =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3), Lstar_2,Lslope_2,Lslope2_2,Lnorm_2) elif model in ['LFpl','LFdpl_pl']: faint =lumfuncUtils.powerlaw(numpy.power(10,bins3), Lstar_2,Lslope_2,Lnorm_2) elif model in ['LFpl_dpl']: faint =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3),Lstar,Lslope,Lslope2,Lnorm) elif model =='LFevol_logn_mat': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=parameters,\ family='LFevol_logn_mat',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] else: faint = lumfuncUtils.lognormpl(numpy.power(10,bins3), Lstar_2,Lslope_2,Lsigma,Lnorm_2) #phi_dpl =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3),Lstar ,Lslope,Lslope2,Lnorm) ''' #phi_dpl #dpl = dm =0.4#05 hm=0. #if num==1:hm=-0.25 ##if num>1:num-=1 L_1 = numpy.power(10,bins3)/(1 + z_m)**(2.86-z_m*0.7) L_2 = numpy.power(10,bins3)/(1 + z_m)**(2.95-z_m*0.29) print z_m, z_nov[num-1] Novak17=lumfuncUtils.lognormpl(L_2, numpy.log10(1.85e21),1.22,0.63, numpy.log10(3.55e-3/2.5)) Novak17_2=lumfuncUtils.lognormpl(numpy.power(10,bins3)/(1 + z_nov[num-1])**(3.16-z_nov[num-1]*0.32),\ numpy.log10(1.85e21),1.22,0.63, numpy.log10(3.55e-3/2.5)) phi_agn_n=lumfuncUtils.doublepowerlaw(L_1,24.59,1.27,0.49,numpy.log10(10**(-5.5))) phi_tot_n = phi_agn_n+Novak17 phi_tot_n2 = phi_agn_n+Novak17_2 #phi_2 =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params2,paramsList=parameters2,\ # family='LFdpl_dpl',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True) for lL in bins3] #phi_3 =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params3,paramsList=parameters3,\ # family='LFlognorm',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True) for lL in bins3] phi = [lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=parameters,\ family=model,inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True) for lL in bins3] #phi_2 =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params2,paramsList=parameters2,\ # family='LFlognorm_dpl',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True) for lL in bins3] phi_3 =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params3,paramsList=parameters3,\ family='LFevol_logn_mat',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True) for lL in bins3] #faint_3 =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params3,paramsList=parameters3,\ # family='LFevol_logn',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] phi_4 =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params4,paramsList=parameters4,\ family='LFlognorm',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0) for lL in bins3] #sys.exit() ##plt.plot(bins3+hm,numpy.log10(faint)-dm,'--k',linewidth=4 ,label='SF MAP Indiv. Novak 2018 fit') #plt.plot(numpy.log10(10**bins3),numpy.log10(phi_dpl)-dm,'--c', label='agn') #plt.plot(numpy.log10(10**bins3 *(1.4/3)**(-.7))+hm,numpy.log10(faint)-dm,'--b' ,label='faint-end') #plt.errorbar(lin_xrecon+hm,lin_yrecon-dm ,fmt='-b', label='MAP No mass-limit',linewidth=1.8) plt.errorbar(bins[2:],rho_3[2:] ,yerr=er3[2:],fmt='hb', fillstyle= 'none', markeredgewidth=3 ,label=r'$\rm{1/V_{max}}$',markersize=12) #bin #plt.errorbar(lin_xrecon+hm,lin_yrecon-dm ,fmt='-b', label='MAP Model A $M/M_\odot > 10$',linewidth=1.8) #plt.errorbar(lin_xrecon+hm,lin_yrecon-dm ,fmt='-b', label='MAP $\rm{Model}$ $\rm{C}$ Individual',linewidth=1.8) #plt.errorbar(lin_xrecon+hm,lin_yrecon-dm ,fmt='-b', label='MAP $\rm{Model}$ $\rm{C}$ 50% mass limit',linewidth=1.8) ##plt.errorbar(lin_xrecon+hm,lin_yrecon-dm ,fmt='-k', label='MAP Fixed Individual fit',linewidth=2.) ##plt.errorbar(lin_xrecon+hm,lin_yrecon-dm ,fmt='-k', label=r'$\rm{Total}$ $\rm{MAP}$ $\rm{Model}$ $\rm{C}$',linewidth=3) #plt.errorbar(numpy.log10(10**bins3), numpy.log10(phi) -0.4 ,fmt='-k', label=r'$\rm{Total}$ $\rm{MAP}$ $\rm{Model}$ $\rm{C}$',linewidth=3) #plt.plot(bins3+hm,numpy.log10(faint)-dm,'-.b' ,label='SF MAP $\rm{Model}$ $\rm{C}$ Individual $M > 10 M/M_\odot$') #plt.plot(bins3+hm,numpy.log10(faint_3)-dm,'-g' ,label='SF MAP $\rm{Model}$ $\rm{C}$ PLE $M > 10 M/M_\odot$') #plt.plot(bins3+hm,numpy.log10(faint)-dm,'-.b' ,label='SF MAP $\rm{Model}$ $\rm{B}$') #if num!=10:plt.errorbar(numpy.log10(10**bins3), numpy.log10(phi_4) -0.4,fmt='--',color='orange',linewidth=3,label=r'$8.5<\log_{10}(M/M_\odot) <10$ $\rm{MAP}$ $\rm{Model}$ $\rm{B}$ ') #if num!=10:plt.errorbar(numpy.log10(10**bins3), numpy.log10(phi_3) -0.4,fmt='.',color='purple',linewidth=3,label=r'$8.5<\log_{10}(M/M_\odot) <10$ $\rm{MAP}$ $\rm{Model}$ $\rm{C}$ ') #plt.errorbar(numpy.log10(10**bins3), numpy.log10(phi_2) -0.4,fmt='-.r',linewidth=5.,label=r'$\log_{10}(M/M_\odot) > 10$ $\rm{Model}$ $\rm{B}$') #phi_5=numpy.array(phi_2)+numpy.array(phi_3) #plt.errorbar(numpy.log10(10**bins3), numpy.log10(phi_5) -0.4,fmt='-.b',linewidth=3.,label=r'$\rm{Total}$ $\rm{Model C+B}$') #if num!=10:plt.errorbar(numpy.log10(10**bins3), numpy.log10(phi_4) -0.4,fmt='--',color='orange',linewidth=3,label=r'$10^{8.5} M_\odot<M <10^{10} M_\odot$ $\rm{MAP}$ $\rm{Model}$ $\rm{B}$ ') #if num!=10:plt.errorbar(numpy.log10(10**bins3), numpy.log10(phi_3) -0.4,fmt='.',color='purple',linewidth=3,label=r'$10^{8.5} M_\odot<M <10^{10} M_\odot$ $\rm{MAP}$ $\rm{Model}$ $\rm{C}$ ') #plt.errorbar(numpy.log10(10**bins3), numpy.log10(phi_2) -0.4,fmt='-.r',linewidth=5.,label=r'$M > 10^{10} M_\odot$ $\rm{Model}$ $\rm{B}$') #plt.errorbar(lin_xrecon+hm,numpy.log10(yrecon_avr)-dm,fmt='-c', label = 'Average') #plt.errorbar(numpy.log10(10**bins3), numpy.log10(phi_4) -0.4,fmt='--k',linewidth=3,label='MAP with mass limit') ##plt.errorbar(bins,rho_5 ,yerr=er5,fmt='^k',label='VLA-COSMOS2015',markersize=10) #bin ##plt.errorbar(bins,rho_8 ,yerr=er8,fmt='sc',label='VLA-COSMOS2015 in DR4 using DR4 z',markersize=10) #bin ##plt.errorbar(bins,rho_9 ,yerr=er9,fmt='*m',label='VLA-COSMOS2015 in DR4 using COS15z',markersize=14) #bin ##plt.errorbar(bins,rho_6 ,yerr=er6,fmt='ok',label='DR4 detected',fillstyle='none',markersize=14) #bin ##plt.errorbar(bins,rho_7 ,yerr=er6,fmt='dg',label='DR4 detected - Full NIR sample',markersize=12) #bin #if not pass1:plt.errorbar(numpy.array(L_n2[num-1]),numpy.array(rho_n2[num-1]) -0.4,xerr=[L_ner_d2[num-1],L_ner_u2[num-1]],yerr=[rho_ner_d2[num-1],rho_ner_u2[num-1]], fmt='sr',fillstyle='none',ecolor='k',markeredgewidth=1.5, label='Total Novak+2018') #plt.errorbar(numpy.log10(10**bins3), numpy.log10(phi_tot_n),fmt='--k',linewidth=3,label='Total Novak+2018') #plt.errorbar(bins3, numpy.log10(Novak17_2),fmt='.r',linewidth=0.4,label='SF Novak + 2017') #if num <9: #plt.errorbar(mcalpine[mcalpine_panels[num] -1][:,0] ,mcalpine[mcalpine_panels[num] -1][:,1]-0.4 ,yerr=mcalpine[mcalpine_panels[num] -1][:,2],fmt='>c', fillstyle= 'none', markeredgewidth=2 ,label='Total McAlpine+2013',markersize=12) #print padovani[num-1] #if num <9 and num!=2: #plt.errorbar(padovani[padovani_panels[num] -1][:,0],padovani[padovani_panels[num] -1][:,1] -(9-numpy.log10(10)),fmt='dk', fillstyle= 'none', markeredgewidth=1 ,label='padovani+2015 RL AGN',markersize=13) #plt.errorbar(bins3, numpy.log10(Novak17)-0.4,fmt='--b',label='SF galaxies Novak + 2017') #plt.plot(bins3,numpy.log10(phi_agn_n),'--g', label='local agn nov') ##if num>1:num+=1 #plt.plot(L_s, numpy.log10(rho_1), '*m',label='bins LF',markersize=8) #plt.errorbar(bins,rho_5 ,yerr=er5,fmt='*r',label='Total',markersize=10) #bin #plt.errorbar(bins,rho_6 ,yerr=er6,fmt='>g',label='Total LF',markersize=10) #bin #plt.fill_between(lin_xrecon+hm,numpy.log10((yrecon_d))-dm,numpy.log10(yrecon_u) -dm, color='k',label='95% Model C Individaul' ,alpha=0.2) #plt.fill_between(lin_xrecon+hm,numpy.log10((yrecon_d))-dm,numpy.log10(yrecon_u) -dm, color='k',label='95% Model A $M/M_\odot > 10$' ,alpha=0.2) plt.fill_between(lin_xrecon+hm,numpy.log10((yrecon_d))-dm,numpy.log10(yrecon_u) -dm, color='k',label=r'$\rm{95%}$ $\rm{Total}$ $\rm{Model}$ $\rm{C}$' ,alpha=0.5) plt.fill_between(lin_xrecon2+hm,numpy.log10((yrecon_d2))-dm,numpy.log10(yrecon_u2) -dm, color='r',label=r'$\rm{95%}$ $\log_{10}(M/M_\odot) > 10$ $\rm{Model}$ $\rm{B}$' ,alpha=0.5) plt.fill_between(lin_xrecon4+hm,numpy.log10((yrecon_d4))-dm,numpy.log10(yrecon_u4) -dm, color='orange',label=r'$\rm{95%}$ $8.5<\log_{10}(M/M_\odot) <10$ $\rm{Model}$ $\rm{B}$ ' ,alpha=0.7) plt.fill_between(lin_xrecon3+hm,numpy.log10((yrecon_d3))-dm,numpy.log10(yrecon_u3) -dm, color='purple',label=r'$\rm{95%}$ $8.5<\log_{10}(M/M_\odot) <10$ $\rm{Model}$ $\rm{C}$ ' ,alpha=0.7) #plt.errorbar(bins[1:],rho_3[1:] ,yerr=er3[1:],fmt='h', fillstyle= 'none', markeredgewidth=3 ,label='extracted fluxes (No mass limit)',markersize=12) #bin #plt.fill_between(lin_xrecon2+hm,numpy.log10((yrecon_d2))-dm,numpy.log10(yrecon_u2) -dm, color='r',label=r'$\rm{95%}$ $M > 10^{10} M_\odot$ $\rm{Model}$ $\rm{B}$' ,alpha=0.5) #if num!=10:plt.fill_between(lin_xrecon4+hm,numpy.log10((yrecon_d4))-dm,numpy.log10(yrecon_u4) -dm, color='orange',label=r'$\rm{95%}$ $10^{8.5} M_\odot<M <10^{10} M_\odot$ $\rm{Model}$ $\rm{B}$ ' ,alpha=0.7) #if num!=10:plt.fill_between(lin_xrecon3+hm,numpy.log10((yrecon_d3))-dm,numpy.log10(yrecon_u3) -dm, color='purple',label=r'$\rm{95%}$ $10^{8.5} M_\odot<M <10^{10} M_\odot$ $\rm{Model}$ $\rm{C}$ ' ,alpha=0.7) plt.ylim(-8.,-1.6) plt.axvline(fsigma,color='g',linestyle='dashed',label=r'$\rm{5\sigma}$') #plt.axvline(sigma,color='g') #plt.axvline(Lmin,color='r',linewidth=2) ##z_new=True if num<2 or num<6 and num>3 or num>6 and num<9: plt.xticks( visible=False) plt.ylim(-8.,-1.6) if num<5: plt.xlim(18.6,25.7) plt.text(18.8,-7.,r'$\rm{%.1f < z < %.1f}$ %s$\rm{z_{MED} = %.2f}$'%(z_min,z_max,'\n',z_m),fontsize = 28 ) # \n $M_i$ < -22 elif num<9: plt.xlim(20.,27.2) plt.text(20.2,-7.,r'$\rm{%.1f < z < %.1f}$ %s$\rm{z_{MED} = %.2f}$'%(z_min,z_max,'\n',z_m),fontsize = 28 ) # \n $M_i$ < -22 else: plt.xlim(20.6,27.8) plt.text(21.,-7.,r'$\rm{%.1f < z < %.1f}$ %s$\rm{z_{MED} = %.2f}$'%(z_min,z_max,'\n',z_m),fontsize = 28 ) # \n $M_i$ < -22 plt.tick_params(axis='both',which = 'minor',width=1) plt.tick_params(axis='both',which = 'major', width=1.5) ax.xaxis.set_minor_locator(AutoMinorLocator()) #ax.yaxis.set_minor_locator(AutoMinorLocator()) #plt.axes().xaxis.set_minor_locator(AutoMinorLocator()) #plt.axes().yaxis.set_minor_locator(AutoMinorLocator()) #plt.minorticks_on() if num==4: plt.xticks([19,20,21,22,23,24,25],fontsize=30) plt.xticks( visible=True) handles,labels=plt.gca().get_legend_handles_labels() print labels print len(labels) #order=[0, 5, 6,1, 2 ,3 ,4, 7, 8, 9]#model_C order=[0,5,1,4,2,3] #plt.legend(frameon=False).draggable() plt.legend([handles[idx] for idx in order],[labels[idx] for idx in order],frameon=False).draggable() if num==8: plt.xticks([21,22,23,24,25,26,27],fontsize=30) plt.xticks( visible=True) if num == 10: plt.xticks([21,22,23,24,25,26,27],fontsize=30) plt.xticks( visible=True) if num==1 or num ==2 or num==3 or num==4: plt.yticks([-2.,-3,-4,-5, -6, -7], fontsize=30) if num==4: plt.yticks([-2.,-3,-4,-5, -6, -7, -8], fontsize=30) continue plt.yticks(visible=False) '''#z_new=False print 'Is this still num ',num if num<2 or num<6 and num>3 or num>6 and num<9: plt.xticks( visible=False) plt.ylim(-7.6,-1.6) if num<4: plt.xlim(19,25.8) plt.text(19.2,-7.,r'$\rm{%.1f < z < %.1f}$'%(z_min,z_max),fontsize = 32 ) # \n $M_i$ < -22 elif num<7: plt.xlim(20.8,27.2) plt.text(21.,-7.,r'$\rm{%.1f < z < %.1f}$'%(z_min,z_max),fontsize = 33 ) # \n $M_i$ < -22 else: plt.xlim(21.3,27.8) plt.text(21.5,-7.,r'$\rm{%.1f < z < %.1f}$'%(z_min,z_max),fontsize = 32 ) # \n $M_i$ < -22 if num==3: plt.xticks([19,20,21,22,23,24,25],fontsize=22) if num==6: plt.xticks([21,22,23,24,25,26,27],fontsize=22) if num == 9: plt.xticks([22,23,24,25,26,27],fontsize=22) plt.legend(frameon=False).draggable() if num==1 or num ==2 or num==3 or num==10: plt.yticks([-2.,-3,-4,-5, -6], fontsize=22) if num==3: plt.yticks([-2.,-3,-4,-5, -6, -7], fontsize=22) continue plt.yticks(visible=False) ''' fig.text(0.06,0.5,r'$\rm{log_{10}[\Phi /(Mpc^{-3}mag^{-1})]}$',fontsize=32, ha='center',va='center', rotation='vertical') fig.text(0.5,0.04,r'$\rm{log_{10}[L_{1.4}/(W}$ $\rm{Hz^{-1})]}$',fontsize = 32, ha='center',va='center') #plt.text(23.9,-9.7,'%s'%outdir,fontsize = 16 ) # \n $M_i$ < -22 #plt.tick_params(axis='both',which = 'major', labelsize=20,width =2) #plt.tick_params(axis='both',which = 'minor', labelsize=10, width=2) plt.subplots_adjust(hspace=0,wspace=0) #plt.xtick(fontsize=15) #plt.ytick(fontsize=15) #plt.ylim(-10.2,-5.8) #plt.ylim(-11,-5.5) #ax.xaxis.set_minor_locator(AutoMinorLocator()) #ax.yaxis.set_minor_locator(AutoMinorLocator()) #print truth['LMIN'] plotf='%s/LF_recon_s1.pdf' % (outdir) plt.show() return 0
def simulate(family,params,paramsList,bins,\ seed=None,N=None,noise=None,output=None,\ dump=None,version=2,verbose=False,area=None,\ skadsf=None,pole_posns=None,simarrayf=None,\ simdocatnoise=True): """ Based on lumfunc.simtable() Specify family + parameters Specify number of sources Build CDF (or set up function) Draw deviates Sample CDF given deviates Add noise (None or some value) Bin Write out Return Look at simulate.ipynb for an example run Need to add normalization capability Families: ======== skads: ----- r=countUtils.simulate('skads',[0.01,85.0],['S0','S1'],numpy.linspace(-60.0,100.0,26),seed=1234,N=40000,noise=17.0,dump='R.txt',output='dummy.txt',verbose=True) ppl: --- r=countUtils.simulate('ppl',[1000.0,5.0,75.0,-1.6],['C','S0','S1','a0'],numpy.linspace(-20.0,100.0,22),seed=1234,N=40000,noise=17.0,dump='R.txt',output='dummy.txt',verbose=True) r=countUtils.simulate('ppl',[1000.0,5.0,25.0,75.0,-1.6,-2.5],['C','S0','S1','S2','a0','a1'],numpy.linspace(-20.0,100.0,22),seed=1234,N=40000,noise=17.0,dump='R.txt',output='dummy.txt',verbose=True) r=countUtils.simulate('ppl',[1000.0,5.0,25.0,40.0,75.0,-1.6,-2.5,-1.0],['C','S0','S1','S2','S3','a0','a1','a2'],numpy.linspace(-20.0,100.0,22),seed=1234,N=40000,noise=17.0,dump='R.txt',output='dummy.txt',verbose=True) r=countUtils.simulate('ppl',[1000.0,5.0,25.0,40.0,75.0,90.0,-1.6,-2.5,-1.0,2.0],['C','S0','S1','S2','S3','S4','a0','a1','a2','a3'],numpy.linspace(-20.0,100.0,22),seed=1234,N=40000,noise=17.0,dump='R.txt',output='dummy.txt',verbose=True) poly: ---- r=countUtils.simulate('poly',[5.0,75.0,1.0],['S0','S1','p0'],numpy.linspace(-20.0,100.0,22),seed=1234,N=40000,noise=17.0,dump='R.txt',output='dummy.txt',verbose=True) r=countUtils.simulate('poly',[5.0,75.0,1.0,-1.0],['S0','S1','p0','p1'],numpy.linspace(-20.0,100.0,22),seed=1234,N=40000,noise=17.0,dump='R.txt',output='dummy.txt',verbose=True) r=countUtils.simulate('poly',[5.0,75.0,1.0,-1.0,5.0],['S0','S1','p0','p1','p2'],numpy.linspace(-20.0,100.0,22),seed=1234,N=40000,noise=17.0,dump='R.txt',output='dummy.txt',verbose=True) bins: ---- test: ---- array: ----- """ # Initialize seed for variates AND any noise if seed is not None: numpy.random.seed(seed=SEED_SIM) if family == 'ppl': C = alpha = Smin = Smax = beta = S0 = gamma = S1 = delta = S2 = -99.0 nlaws = int(0.5 * len(paramsList) - 1) C = params[paramsList.index('C')] Smin = params[paramsList.index('S0')] alpha = params[paramsList.index('a0')] if nlaws > 1: beta = params[paramsList.index('a1')] S0 = params[paramsList.index('S1')] if nlaws > 2: gamma = params[paramsList.index('a2')] S1 = params[paramsList.index('S2')] if nlaws > 3: delta = params[paramsList.index('a3')] S2 = params[paramsList.index('S3')] iSmax = int([i for i in paramsList if i.startswith('S')][-1][-1]) Smax = params[paramsList.index('S%i' % iSmax)] function = lambda S:powerLawFuncWrap(nlaws,S,C,alpha,-99.0,beta,\ Smin/1e6,Smax/1e6,S0/1e6,gamma,S1/1e6,delta,S2/1e6,1.0) elif family == 'test': Smin = params[paramsList.index('S0')] Smax = params[paramsList.index('S1')] function = lambda S: S**2 elif family == 'poly': Smin = params[paramsList.index('S0')] Smax = params[paramsList.index('S1')] coeffs = [ params[paramsList.index(p)] for p in paramsList if p.startswith('p') ] S_1 = 1.0 function = lambda S: polyFunc(S, S_1, Smin, Smax, coeffs) elif family == 'bins': Smin = params[paramsList.index('S0')] Smax = params[paramsList.index('S1')] coeffs = [ params[paramsList.index(p)] for p in paramsList if p.startswith('b') ] if pole_posns is None: pole_posns = numpy.logspace(numpy.log10(Smin), numpy.log10(Smax), len(coeffs) + 1) assert (len(coeffs) == len(pole_posns) - 1), '***Mismatch in number of poles!!' Smin = pole_posns[0] Smax = pole_posns[-1] function = lambda S: polesFunc(S, pole_posns, Smin, Smax, coeffs) elif family == 'array': Smin = params[paramsList.index('S0')] Smax = params[paramsList.index('S1')] assert (simarrayf is not None), '***Need to specify an input simulation!' print 'Reading %s...' % simarrayf dataMatrix = numpy.genfromtxt(simarrayf) dndsInArr = dataMatrix[:, 4] binsDogleg = numpy.concatenate((dataMatrix[:, 0], [dataMatrix[-1, 1]])) binsMedian = dataMatrix[:, 2] assert (( medianArray(binsDogleg) == binsMedian).all()), '***bin mismatch!' Smin = binsDogleg[0] Smax = binsDogleg[-1] if not simdocatnoise: Smin = -5.01 #-2.01 # binsMedian[0] print dndsInArr function = lambda S: arrayFunc(S, binsMedian, dndsInArr, Smin, Smax) #function2=lambda S:arrayFunc(S,binsMedian,dndsInArr,Smin,Smax) #for x in numpy.linspace(-10.0,100.0,500): # print x,function(x),function2(x) #sys.exit(0) elif family == 'skads': Smin = params[paramsList.index('S0')] Smax = params[paramsList.index('S1')] function = None assert (skadsf is not None), '***Need to specify input SKADS file!' print 'Reading %s...' % skadsf R = Jy2muJy * 10**numpy.genfromtxt(skadsf) numpy.ndarray.sort(R) iRmin, Rmin = find_nearest(R, Smin) iRmax, Rmax = find_nearest(R, Smax) F = R[iRmin:iRmax] print '%i/%i sources ingested after Smin/Smax cuts' % (len(F), len(R)) if N is not None: F = numpy.random.choice(F, size=N, replace=False) N = len(F) print 'NSKADS = %i' % N elif family == 'Lrad': Smin = params[paramsList.index('LoptMIN')] Smax = params[paramsList.index('LoptMAX')] A = params[paramsList.index('A')] B = params[paramsList.index('B')] sigma_Lrad = params[paramsList.index('sigma_Lrad')] #print Loptmin,Loptmax print 'Doing LF simulation' inta = None #intg = integrate.quad(lambda Lopt:Lopt2Lrad(Lopt,A=A,B=B,flux=False),Loptmin,Loptmax,epsabs=0.)[0] function = lambda Lopt: Lopt2Lrad(Lopt, A=A, B=B, flux=False) elif family in ['LFsch', 'LFdpl']: redshift = 0.325 z_min = 0.2 z_max = 0.45 Lmin = params[paramsList.index('LMIN')] Lmax = params[paramsList.index('LMAX')] [Smin, Smax] = SMIN_SIM, SMAX_SIM print Smin, Smax [Smin, Smax] = get_sbins([10**Lmin, 10**Lmax], redshift, dl) * 1e6 print Smin, Smax, Lmin, Lmax print 'Doing LF simulation' Vmax = get_Vmax(z_min, z_max) dsdl = get_dsdl(redshift, dl) inta = None intg = integrate.quad(lambda S:LF(S,redshift,dsdl,Vmax,dl,params=params,paramsList=paramsList,\ inta=inta,area=area,family=family),Smin*1e-6,Smax*1e-6,epsabs=0.)[0] print intg * Vmax print Vmax area = N / (Vmax * intg) area1 = area print N, area function = lambda S:dNdS_LF(S,z_min,redshift,z_max,dl,params=params,paramsList=paramsList,\ area=area,family=family) if family != 'skads': # Set up the 'rough' array gridlength = 10000 # Good enough to prevent bleeding at the edges Ss = numpy.linspace(Smin, Smax, gridlength) print Smin, Smax print 'checking for one sample' kl = function(20 / 1e6) print kl #sys.exit() values = numpy.array([function(ix / 1e6) for ix in Ss]) print values[:10] # Build the CDF CDF = buildCDF(values) plt.plot(CDF, Ss) #plt.xscale('log') #plt.yscale('log') plt.ylabel('Flux') plt.xlabel('CDF') plt.show() print CDF.max() # Create the interpolant object sampler = interp1d(CDF, Ss) plt.plot(Ss, values, '.') plt.xscale('log') plt.yscale('log') plt.xlabel('Flux') plt.ylabel('LF') plt.show() x = numpy.linspace(0., 1., 10000) z = numpy.logspace(0, 1, 1000) / 10. f = sampler(z) y = sampler(x) plt.yscale('log') #plt.xscale('log') plt.axhline(Smin) plt.axhline(Smax) plt.xlabel('R') plt.ylabel('Sampler(R) [flux]') #plt.plot(x,y) plt.plot(z, f) plt.show() #sys.exit() # Test that the sampler extrema match print Smin, sampler(0.0), 'you know wa mean' print Smax, sampler(0.99999) # assert(numpy.isclose(sampler(0.0),Smin)[0]) # assert(numpy.isclose(sampler(0.99999),Smax,atol=1.0e-3)[0]) # Draw the random deviates R = numpy.random.rand(N) print len(R) F = sampler(R) Nt = 0. for f in F: if f < 1.: Nt += 1. F = F[F > 1.] print N, Nt print len(F) Nt = len(F) #sys.exit() # Normalize here - this is N2C # EITHER N is specified explicitly # BOTH N2C and C2N are useful # Integrate the original function #intg = integrate.quad(lambda S:LF(S,redshift,dsdl,Vmax,dl,params=params,paramsList=paramsList,\ # inta=inta,area=area,family=family),Smin*1e-6,Smax*1e-6,epsabs=0.)[0] #print intg*Vmax #print Vmax #area = Nt/(Vmax*intg) #print N,area,area1 #plt.show() #sys.exit() A = integrate.quad(function, Smin, Smax)[0] # print A,N # Bin the random samples bbins = numpy.linspace(Smin, Smax, 100) E = numpy.histogram(F, bins=bbins)[0] # And calculate their area G = integrate.trapz(E, x=medianArray(bbins)) # print G # print G/A # Gunpowder, treason and.... if False: plt.xlim(0.0, 100.0) plt.xlabel('S / $\mu$Jy') plt.hist(F, bins=bbins) plt.plot(Ss, values * G / A, 'r') plt.savefig('N2C.pdf') plt.close() # Want: C given N, to compare to original C numbins = 1000 if family == 'ppl': C_calc = N / N2C(function, F, Smin, Smax, numbins) #print N2C(function,F,Smin,Smax,numbins),C print 'For %i sources, C is %e (should be %e)' % (N, C_calc, C) elif family == 'poly': C_calc = log10(N / N2C(function, F, Smin, Smax, numbins)) print 'For %i sources, C is %e (should be %e)' % (N, C_calc, coeffs[0]) # Dump noiseless fluxes to file puredumpf = dump idl_style = False numpy.savetxt(puredumpf, F) print 'Draws (noiseless) are in %s' % puredumpf writeCountsFile(output[1], bins, F, area, idl_style=idl_style, verbose=verbose) print output[1] # Now add noise if requested if simdocatnoise: numpy.random.seed(seed=SEED_SIM) poln = False if poln: F += rice.rvs(F / noise, size=N) else: F += numpy.random.normal(0.0, noise, Nt) # Dump noisy fluxes to file if dump is not None: noisydumpf = '%s_noisy.txt' % puredumpf.split('.')[0] numpy.savetxt(noisydumpf, F) print 'Draws (noisy) are in %s' % noisydumpf print 'Minimum flux in catalogue = %f' % F.min() print 'Maximum flux in catalogue = %f' % F.max() # Write counts file print output[0] writeCountsFile(output[0], bins, F, area, idl_style=idl_style, verbose=verbose) print N, area #,area1 return F
def main(): """ """ print 'Settings file is %s' % setf # Import the settings variables set_module = importlib.import_module(setf) globals().update(set_module.__dict__) expt = countModel(modelFamily, nlaws, setf, [dataset], floatNoise, doRedshiftSlices=True) #recon_expt=countModel(modelFamily,nlaws,setf,[dataset],floatNoise) #print expt.data #print expt.bins # Get MAP parameters print '\n' * 5 print len(expt.parameters) ncols = len(expt.parameters) summf = os.path.join(outdir, '1-summary.txt') summary = numpy.genfromtxt(summf)[-1, :] drawmap = summary[-(ncols + 2):-2] ana=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join(outdir,outstem)) drawmap = ana.get_best_fit()['parameters'] if dataset == 'sdss': print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf) == 20: num = dataf[-5] print num else: num = dataf[-6:-4] d = numpy.genfromtxt('%s/%s' % (outdir, datafiles[0][4:])) print datafiles[0][4:] elif dataset == 'cosmos': print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf) == 24: num = dataf[-5] print num else: num = dataf[-6:-4] d = numpy.genfromtxt('%s/%s' % (outdir, datafiles[0][8:])) print datafiles[0][8:] elif 'sim' in dataset: d = numpy.genfromtxt(os.path.join(outdir, 'sim.txt')) #bins2 = numpy.arange(21.4,29.2,0.4) bins2 = numpy.arange(18.0, 29.2, 0.4) bins3 = numpy.arange(18., 29.2, 0.01) print len(expt.parameters) print 'this is 1st num ', num #sys.exit() params = drawmap # [0] #for i in drawmap: # params.append(i) print params print expt.parameters #novak 2017 L_n = [21.77, 22.15, 22.46, 22.77, 23.09, 23.34] rho_n = [-2.85, -2.88, -3.12, -3.55, -4.05, -4.63] L_ner_u = [0.23, 0.18, 0.19, 0.2, 0.21, 0.28] L_ner_d = [1.1, 0.15, 0.14, 0.12, 0.12, 0.048] rho_ner = [0.09, 0.03, 0.0355, 0.059, 0.1, 0.234] #novak 2018 L_n2 =[[21.77,22.24,22.68,23.16,23.69,24.34, 24.74,25.56],\ [22.30,22.61,22.96,23.38,23.80,24.10, 24.55,25.14],\ [22.61,22.86,23.14,23.45,23.82,24.14, 24.40,24.71],\ [22.85,23.16,23.69,24.24,24.80,25.31, 25.96,26.69],\ [23.10,23.38,23.86,24.36,24.86,25.35, 25.94,26.36],\ [23.32,23.57,23.94,24.32,24.67,25.06, 25.47,25.96],\ [23.54,23.75,24.13,24.45,24.90,25.27, 25.74,26.10],\ [23.73,23.99,24.57,25.10,25.68,26.18, 26.83,27.51],\ [24.01,24.26,24.76,25.26,25.91,26.19, 27.45],\ [24.30,24.56,24.80,25.13,25.37,25.80, 25.97,26.49]] L_ner_u2 =[[0.23,0.27, 0.34, 0.37, 0.35, 0.21, 0.31, 0.03],\ [0.11,0.20, 0.26, 0.25, 0.24, 0.35, 0.31, 0.15],\ [0.08,0.15, 0.20, 0.22, 0.17, 0.18, 0.24, 0.28],\ [0.072,0.33,0.38, 0.40, 0.48, 0.42, 0.41, 0.28],\ [0.080,0.30,0.32, 0.32, 0.32, 0.33, 0.24, 0.34],\ [0.068,0.22,0.24, 0.25, 0.29, 0.30, 0.28, 0.21],\ [0.067,0.22,0.21, 0.26, 0.18, 0.17,0.075, 0.11],\ [0.093,0.36,0.31, 0.30, 0.25, 0.28, 0.16,0.028],\ [0.076,0.34,0.36, 0.38, 0.24, 0.47, 0.27],\ [0.097,0.14,0.20, 0.16, 0.23, 0.092,0.22,0.026]] L_ner_d2 =[[1.0, 0.24, 0.17, 0.14, 0.16, 0.30, 0.20, 0.50],\ [0.29, 0.21, 0.15, 0.16, 0.17, 0.06, 0.099,0.29],\ [0.24, 0.17, 0.12, 0.10, 0.15, 0.15, 0.08,0.074],\ [0.16, 0.24, 0.19, 0.17, 0.15, 0.09, 0.16, 0.33],\ [0.30, 0.19, 0.18, 0.18, 0.18, 0.17, 0.26, 0.18],\ [0.14, 0.18, 0.15, 0.14, 0.10, 0.095,0.11, 0.21],\ [0.19, 0.14, 0.15, 0.11, 0.19, 0.19, 0.29, 0.28],\ [0.40, 0.17, 0.21, 0.23, 0.27, 0.25, 0.37, 0.53],\ [0.20, 0.17, 0.16, 0.14, 0.27, 0.042, 0.27],\ [0.22, 0.16, 0.10, 0.14,0.072, 0.21, 0.08, 0.30]] rho_n2 =[[-2.84,-2.90,-3.34,-4.00,-4.92,-4.92, -5.22,-5.07],\ [-2.95,-3.17,-3.46,-4.24,-4.76,-5.41, -5.23,-5.44],\ [-2.95,-3.11,-3.44,-3.81,-4.37,-4.48, -4.90,-5.14],\ [-2.99,-3.24,-3.89,-4.54,-5.27,-5.33, -5.69,-5.89],\ [-3.32,-3.51,-4.06,-4.74,-5.28,-5.43, -6.08,-5.70],\ [-3.29,-3.54,-4.02,-4.45,-5.11,-5.56, -5.37,-6.07],\ [-3.43,-3.61,-4.19,-4.56,-5.09,-5.34, -5.70,-5.75],\ [-3.88,-3.98,-4.64,-5.33,-5.73,-6.27, -6.14,-6.77],\ [-3.85,-4.28,-5.05,-5.60,-5.68,-6.44, -6.59],\ [-4.43,-4.91,-5.46,-5.58,-5.89,-6.23, -6.26,-6.91]] rho_ner_u2=[[0.08,0.024,0.038,0.083,0.28,0.28 , 0.45, 0.34],\ [0.048,0.027,0.036,0.089,0.17,0.45, 0.34, 0.45],\ [0.062,0.024,0.032,0.048,0.096, 0.11,0.18,0.25],\ [0.042,0.018,0.035,0.073,0.180, 0.20,0.34,0.45],\ [0.045,0.019,0.033,0.072,0.15, 0.17,0.45,0.25],\ [0.040,0.022,0.033,0.055,0.13, 0.22,0.17,0.45],\ [0.061,0.020,0.035,0.055,0.099, 0.14,0.22,0.25],\ [0.044,0.022,0.044,0.11, 0.16, 0.34, 0.28,0.76],\ [0.048,0.025,0.058,0.13, 0.24, 0.34, 0.45],\ [0.084,0.058,0.11 ,0.24, 0.20, 0.28, 0.28,0.76]] rho_ner_d2=[[0.07,0.023,0.035,0.070,0.25,0.25 , 0.37, 0.30],\ [0.043,0.026,0.033,0.074,0.16,0.37, 0.30, 0.37],\ [0.054,0.023,0.030,0.043,0.079,0.086,0.17,0.22],\ [0.038,0.017,0.032,0.062,0.17,0.19, 0.30, 0.37],\ [0.041,0.019,0.031,0.062,0.11,0.16, 0.37, 0.22],\ [0.037,0.021,0.031,0.049,0.098,0.20,0.16, 0.37],\ [0.054,0.019,0.032,0.049,0.081,0.11,0.20, 0.22],\ [0.040,0.021,0.040,0.085,0.15, 0.30, 0.25,0.52],\ [0.043,0.024,0.051,0.10, 0.15, 0.30, 0.37],\ [0.070,0.051,0.087,0.16,0.19, 0.25, 0.25, 0.52]] fig = plt.figure() pre_chain = 12 pre_chain = '02' chains = [ '01a_1', '01b', '01c', '01d', '01e', '01f_1', '01g', '01h', '01i' ] #chains_2001 DR4 chains = [ '01a_4', '01b_2', '01c_2', '01d_2', '01e_2', '01f_2', '01g', '01h_2', '01i_2' ] #chains_2001 DR4 remove phi2 chains = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'] #z = [0, 0.5, 1 , 1.5, 2, 2.3, 2.6, 3, 3.5, 4] #old #z = [ 0.7, 1 , 1.35, 1.7, 2, 2.3, 2.6, 3, 3.5, 4]# older print expt.parameters n, m = 3, 3 z_new = True Replot = False z_nov = [0.31, 0.5, 0.69, 0.9, 1.16, 1.44, 1.81, 2.18, 2.81, 3.71, 4.83] if z_new: z = [0.1, 0.3, 0.4, 0.6, 0.8, 1.0, 1.3, 1.6, 2.0, 2.5, 3.2, 4.0] z = [0.1, 0.4, 0.6, 0.8, 1.0, 1.3, 1.6, 2.0, 2.5, 3.2, 4.0] #chains=['11a','11b','11c_3','11d_3','11e_3','11f_3','11g_3','11h','11i','11j', '11k', '11l' ,'11m', '11n']#chains_201111 else: z = [0.1, 0.4, 0.6, 0.8, 1.0, 1.3, 1.6, 2.0, 2.5, 3.2, 4.0] #oldest ;) model = modelFamily if model in [ 'LFsch', 'LFdpl_pl', 'LFpl_dpl', 'LFdpl_dpl', 'LFdpl_dpl_z', 'LFlognorm_dpl', 'LFpl_lognorm' ]: Lnorm = params[expt.parameters.index('LNORM')] Lstar = params[expt.parameters.index('LSTAR')] Lslope = params[expt.parameters.index('LSLOPE')] #Lzevol=params[expt.parameters.index('LZEVOL')] if model in [ 'LFdpl_pl', 'LFpl_dpl', 'LFdpl_dpl', 'LFdpl_dpl_z', 'LFlognorm_dpl' ]: Lslope2 = params[expt.parameters.index('LSLOPE2')] if model in [ 'LFlognorm', 'LFpl', 'LFdpl', 'LFdpl_pl', 'LFpl_dpl', 'LFlognorm_dpl', 'LFpl_lognorm', 'LFdpl_dpl', 'LFdpl_dpl_z' ]: Lnorm_2 = params[expt.parameters.index('LNORM_2')] Lstar_2 = params[expt.parameters.index('LSTAR_2')] Lslope_2 = params[expt.parameters.index('LSLOPE_2')] if model in ['LFdpl_dpl', 'LFdpl', 'LFdpl_dpl_z']: Lslope2_2 = params[expt.parameters.index('LSLOPE2_2')] if model in ['LFlognorm', 'LFlognorm_dpl', 'LFpl_lognorm']: Lsigma = params[expt.parameters.index('LSIGMA')] if modelFamily in [ 'LFdpl_dpl_z', 'LFevol', 'LFevol_dpl', 'LFevol_logn', 'LFevol_logn_L' ]: alpha_agn = params[expt.parameters.index('A_agn')] alpha_SF = params[expt.parameters.index('A_SF')] beta_agn = params[expt.parameters.index('B_agn')] beta_SF = params[expt.parameters.index('B_SF')] if modelFamily in ['LFevol_dpl_s', 'LFevol_logn_s']: alpha_SF = params[expt.parameters.index('A_SF')] beta_SF = params[expt.parameters.index('B_SF')] if modelFamily in ['LFevol_dpl_a', 'LFevol_logn_a']: alpha_agn = params[expt.parameters.index('A_agn')] beta_agn = params[expt.parameters.index('B_agn')] Lmin = params[expt.parameters.index('LMIN')] LMIN = params[expt.parameters.index('LMIN')] Lmax = params[expt.parameters.index('LMAX')] loglike = 0. loglike_nov = 0. print model bins3 = numpy.arange(15., 30.2, 0.2) #xbins = numpy.arange(fsigma,26.2,0.4)#bin +0.2 sbin4 = get_sbins(10**bins3, z[0], get_dl(z[0])) * 1e6 expt2 = countModel(modelFamily, nlaws, setf, [dataset], floatNoise, doRedshiftSlices=True, mybins=sbin4) sbin5 = medianArray(sbin4) phi_tot3 = expt2.evaluate(params) #print phi_tot3 #print len(phi_tot3[0]), len(bins3) for num in range(1, 10): #num = 1. print num print 'new num ', num z_min, z_max, z_m = get_z(num, False) dl = get_dl(z_m) Vmax = get_Vmax(z_min, z_max) dsdl = get_dsdl(z_m, dl) #z_m = (z_min + z_max)/2 dl = get_dl(z_m) print z_min, z_max, 'lmin ', SMIN = get_sbins(numpy.power(10, Lmin), z_m, dl) * 1e6 SMAX = get_sbins(numpy.power(10, Lmax), z_m, dl) * 1e6 sigma, fsigma, Lmin = numpy.log10( get_Lbins([SURVEY_NOISE, SURVEY_NOISE * 5, LMIN], z_m, dl, 'muJy') * (1.4 / 3)**(-.7)) sigma2, fsigma2 = numpy.log10(get_Lbins([450, 2400], z_m, dl, 'muJy')) print Lmin print SURVEY_NOISE, SURVEY_NOISE * 5, SURVEY_AREA print num, '%s/recon_stats_%s.txt' % (outdir, chains[num - 1]) s = numpy.loadtxt('%s/recon_stats_%s.txt' % (outdir, chains[num - 1])) print chains[num - 1] xrecon = s[:-1, 0] yrecon = s[:-1, 1] yrecon_d = s[:-1, 2] yrecon_u = s[:-1, 3] yrecon_rms = s[:-1, 4] yrecon_avr = s[:-1, 5] yrecon_rms_down = yrecon_rms #area = 6672*sqDeg2sr #143165.15 49996.49 59876.8861135 sbin3 = get_sbins(10**bins2, z_m, dl) * 1e6 #sbin4 = get_sbins(10**bins3,z_m,dl)*1e6 xreco = get_Lbins(xrecon, z_m, dl, 'muJy') #*(1.4/3)**(-.7) yreco = yrecon print SMIN, SMAX #sys.exit() lin_yrecon = numpy.log10(yreco) #print xrecon lin_xrecon = numpy.log10(xreco) #bins3 = numpy.arange(15.,30.,0.4) bins3 = numpy.log10(get_Lbins(sbin4, z_m, dl, 'muJy')) #*(1.4/3)**(-.7)) #bins = numpy.arange(fsigma,26.2,0.4)#bin +0.2 #sbin4 = get_sbins(10**bins3,z_m,dl)*1e6 if not os.path.isfile('cos_data/cos_s%s_LF.el' % num) and z_new or not os.path.isfile( 'cos_data/cos_s%s_LF_old.el' % num) and not z_new or Replot: print 'doing all calculations' #l,z_l = open_anytype('cos_data/cosmos_d1_0_8arc.txt',(12,21), F='uJy',L=True,getz=True) #l2,z_l2 = open_anytype('cos_data/cosmos_d1_0_8arc.txt',(12,24), F='uJy',L=True,getz=True) if z_new: L, z_L = open_anytype('cos_data/cos_s%s.txt' % num, (2, 3), F='uJy', L=True, getz=True, band='S') print 'this is the new z bins (please check if lumfuncUtils and cos_manifest are using the right z)' else: L, z_L = open_anytype('cos_data/cos_s%s_old.txt' % num, (2, 3), F='uJy', L=True, getz=True, band='S') print 'this is the old z binning style. (please check if lumfuncUtils and cos_manifest are using the right z)' L_c, z_c = open_anytype('cosmos_counter_parts_II.txt', (3, 4), [z_min, z_max], F='uJy', L=True, getz=True, band='S') z_c2, S_c2, L_c2 = numpy.loadtxt('cosmos_counter_parts_II.txt', unpack=True, usecols=(3, 4, 5)) L_c2 = L_c2[(z_c2 < z_max) & (z_c2 > z_min)] S_c2 = S_c2[(z_c2 < z_max) & (z_c2 > z_min)] z_c2 = z_c2[(z_c2 < z_max) & (z_c2 > z_min)] #rho_1,er1 = calc_Vmax(calcu_zeff(z_l,l,11.5e-32),l,bins,z_max,z_min,area) #rho_2,er2 = calc_Vmax(calcu_zeff(z_l2,l2,11.5e-32),l2,bins,z_max,z_min,area) rho_3, er3 = calc_Vmax(calcu_zeff(z_L, L, 1.15e-31), L, bins, z_max, z_min, area) #rho_4,er4 = calc_Vmax(99.,L,bins2,z_max,z_min,area) rho_5, er5 = calc_Vmax(calcu_zeff(z_c, L_c, 1.15e-31), L_c, bins, z_max, z_min, area) rho_6, er6 = calc_Vmax(calcu_zeff(z_c2, 10**L_c2, 1.15e-31), 10**L_c2, bins, z_max, z_min, area) if z_new: f = open('cos_data/cos_s%s_LF.el' % num, 'w') else: f = open('cos_data/cos_s%s_LF_old.el' % num, 'w') for i in range(len(bins)): f.write('%5.1f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f\n' % (bins[i], rho_3[i], er3[i], rho_5[i], er5[i], rho_6[i], er6[i])) f.close() dl_c = get_dl(z_c2) L_c3 = numpy.log10( get_Lbins(S_c2, z_c2, numpy.array(dl_c), 'muJy') * (1.4 / 3.)**(-.7)) else: if z_new: #bins,rho_3,er3,rho_5,er5,rho_6,er6 = numpy.loadtxt('cos_data/cos_s%s_LF.el'%num, unpack=True) bins, rho_3, er3, rho_5, er5, rho_6, er6, rho_7, er7, rho_8, er8, rho_9, er9 = numpy.loadtxt( 'cos_data/cos_s%s_LF_2.el' % num, unpack=True) print 'Using stored RLF for the new z (The one with more z bins). If you want to calculate the plot the set "Replot=True"' else: bins, rho_3, er3, rho_5, er5, rho_6, er6 = numpy.loadtxt( 'cos_data/cos_s%s_LF_old.el' % num, unpack=True) print 'Using stored RLF for the is old z bins. If you want to calculate the plot the set "Replot=True"' ssd = numpy.loadtxt('%s/data_cos_s%s.txt' % (outdir, num)) #ssd = numpy.loadtxt('cos_data/data_cos_s%s.txt'%(num)) ssbin2 = ssd[:, 0] #2 ssbin1 = ssd[:, 2] #0 Nbin2 = ssd[:, 3] zbin3 = ssd[:, -1] dl1 = get_dl(z_min) dl2 = get_dl(z_max) #dl3 = get_dl(zbin3) Ncount = sum(Nbin2[fsigma > ssbin1]) Llmin = numpy.log10( get_Lbins([fsigma / numpy.sqrt(Ncount)], z_min, get_dl(z_min), 'muJy'))[0] Llmin *= (1.4 / 3.)**(-.7) print Llmin dn = expt.realise(params) nov_real = expt.realise([2.3, 2.95, 2.86, -0.29, -0.7, 19.5, 26.0]) #sys.exit() fig.add_subplot(n, m, get_changed_multiplot(n, m, num)) plt.rc('lines', linewidth=2) #plt.errorbar(bins,rho_1 ,yerr=er1,fmt='*r',label='detected extracted',markersize=11) #bin plt.errorbar(bins[1:], rho_3[1:], yerr=er3[1:], fmt='ob', label='extracted', markersize=8) #bin ''' if model in ['LFdpl','LFdpl_dpl']: faint =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3), Lstar_2,Lslope_2,Lslope2_2,Lnorm_2) elif model in ['LFpl','LFdpl_pl']: faint =lumfuncUtils.powerlaw(numpy.power(10,bins3), Lstar_2,Lslope_2,Lnorm_2) elif model in ['LFpl_dpl']: faint =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3),Lstar,Lslope,Lslope2,Lnorm) elif model in ['LFdpl_dpl_z']: faint =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3),Lstar,Lslope,Lslope2,Lnorm) else: faint = lumfuncUtils.lognormpl(numpy.power(10,bins3), Lstar_2,Lslope_2,Lsigma,Lnorm_2) ''' #phi_dpl =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3),Lstar ,Lslope,Lslope2,Lnorm) #phi_dpl #dpl = dm = 0.4 #05 hm = 0. Novak17 = lumfuncUtils.lognormpl( numpy.power(10, bins3) / (1 + z_nov[num - 1])**(3.16 - z_nov[num - 1] * 0.32), numpy.log10(1.85e21), 1.22, 0.63, numpy.log10(3.55e-3)) Novak18=[lumfuncUtils.LF(S,z_m,0,0,dl,[2.3,2.86, 2.95, -0.70, -0.29,0.01,28.],\ ['noise','A_agn','A_SF','B_agn','B_SF','LMIN','LMAX'],area=SURVEY_AREA,\ family='LFevol_logn') for S in sbin4/1.0e6] phi_tot2 = [lumfuncUtils.LF(S,z_m,0,0,dl,params,expt.parameters,area=expt.survey.SURVEY_AREA,\ family=modelFamily) for S in sbin5/1.0e6] L_1 = numpy.power(10, bins3) / (1 + z_m)**(2.86 - z_m * 0.7) L_2 = numpy.power(10, bins3) / (1 + z_m)**(2.95 - z_m * 0.29) L_4 = numpy.power(10, bins3) / (1 + z_m)**(alpha_SF + z_m * beta_SF) #L_3 = numpy.power(10,bins3)/(1 + z_m)**(alpha_agn+z_m*beta_agn) print z_m #print L_4 #print L_3 #sys.exit() phi_agn_n = lumfuncUtils.doublepowerlaw(L_1, 24.59, 1.27, 0.49, numpy.log10(10**(-5.5))) phi_sf_n = lumfuncUtils.lognormpl(L_2, numpy.log10(1.85e21), 1.22, 0.63, numpy.log10(3.55e-3)) phi_exp =[lumfuncUtils.LF(S,z_m,0,0,dl,[2.3,3, 5.58, -0.9, -1.99,0.01,28.],\ ['noise','A_agn','A_SF','B_agn','B_SF','LMIN','LMAX'],area=SURVEY_AREA,\ family='LFevol_logn') for S in sbin4/1.0e6] #Novak18= phi_agn_n+phi_sf_n #print 'this is Lminz', numpy.log10(10**18/(1 + z_m)**(alpha_SF+z_m*beta_SF)) #phi_agn=lumfuncUtils.doublepowerlaw(L_3,24.59,1.27,0.49,numpy.log10(2.5*10**(-5.5))) phi_agn = 0 phi_sf = lumfuncUtils.doublepowerlaw(L_4, 22.41, 2.4, 0.43, -3.50) #0.33 2.97 phi_sf = lumfuncUtils.lognormpl(L_4, numpy.log10(1.85e21), 1.22, 0.63, numpy.log10(3.55e-3)) phi_tot = phi_agn + phi_sf #for k in range(len(phi_sf)): # print bins3[k],numpy.power(10,bins3[k]), numpy.log10(L_4[k]), numpy.log10(L_3[k]), numpy.log10(phi_sf[k]), numpy.log10(phi_agn[k]),numpy.log10(phi_tot[k]) #sys.ek #phi_sf =lumfuncUtils.lognormpl(L_4,numpy.log10(1.85e21),1.22,0.63, numpy.log10(3.55e-3)) #plt.plot(bins3+hm,numpy.log10(faint)-dm,'--b' ,label='faint-end') #plt.plot(numpy.log10(10**bins3 *(1.4/3)**(-.7))+hm,numpy.log10(faint)-dm,'--b' ,label='faint-end') #plt.plot(numpy.log10(10**bins3),numpy.log10(phi_sf)-dm,'--c', label=' SF') #plt.plot(bins3,numpy.log10(phi_agn)-dm,'--r', label='AGN') #plt.plot(numpy.log10(10**bins3),numpy.log10(phi_tot)-dm,'--g',linewidth=3, label='Tot') #plt.plot(numpy.log10(10**bins3[:-1]),numpy.log10(phi_tot2)-dm,'-k',linewidth=4, label='Tot2') #plt.plot(numpy.log10(10**bins3 *(1.4/3)**(-.7)),numpy.log10(phi_exp)-dm,'-k',linewidth=4, label='Expected') plt.errorbar(lin_xrecon + hm, lin_yrecon - 0.4, fmt='-b', label='MAP', linewidth=3) #plt.plot(numpy.log10(10**bins3[:-1] *(1.4/3)**(-.7)),numpy.log10(phi_tot3[num-1])-dm,'-r',linewidth=3, label='Tot3') plt.errorbar(lin_xrecon + hm, numpy.log10(yrecon_avr) - dm, fmt='-c', label='Average') plt.errorbar(numpy.array(L_n2[num - 1]), numpy.array(rho_n2[num - 1]) - 0.4, xerr=[L_ner_d2[num - 1], L_ner_u2[num - 1]], yerr=[rho_ner_d2[num - 1], rho_ner_u2[num - 1]], fmt='sk', label='Total RLF Novak et al 2018') #plt.errorbar(bins3, numpy.log10(Novak17)-0.4,fmt='--b',label='Local SF Novak et al 2017') #plt.plot(bins3,numpy.log10(phi_agn_n),'--g', label='Local AGN Smolcic et al. 2017') plt.errorbar(numpy.log10(10**bins3), numpy.log10(Novak18) - 0.4, fmt='--k', label='Total RLF Novak et al 2018') #plt.plot(L_s, numpy.log10(rho_1), '*m',label='bins LF',markersize=8) #plt.errorbar(bins,rho_5 ,yerr=er5,fmt='*r',label='Total',markersize=10) #bin #plt.errorbar(bins,rho_6 ,yerr=er6,fmt='>g',label='Total LF',markersize=10) #bin plt.fill_between(lin_xrecon + hm, numpy.log10((yrecon_d)) - dm, numpy.log10(yrecon_u) - dm, color='k', alpha=0.2) #plt.axvline(Lmin,color='r') print 'This is the dn' print z_m #print dn.keys() ''' for key in dn.keys(): if round(key,2)==round(z_m,2):z_m=key dn=dn[z_m] nov_real=nov_real[z_m] #print nov_real #dn=dn[round(z_m,2)] for i in range(len(ssbin1)): loglike_i= Nbin2[i]*numpy.log(dn[i]) + Nbin2[i] - (Nbin2[i] + 0.5)*numpy.log(Nbin2[i]) - 0.5*numpy.log(2*numpy.pi) - dn[i] loglike_nov_i= Nbin2[i]*numpy.log(nov_real[i]) + Nbin2[i] - (Nbin2[i] + 0.5)*numpy.log(Nbin2[i]) - 0.5*numpy.log(2*numpy.pi) - nov_real[i] if nov_real[i]>0:loglike_nov+=loglike_nov_i if dn[i]>0:loglike+=loglike_i print '%10.5f %8.2d %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f'%(ssbin1[i], Nbin2[i], dn[i],nov_real[i],loglike_i,loglike_nov_i,loglike, loglike_nov) ''' plt.ylim(-7.6, -1.6) plt.axvline(fsigma, color='k', linestyle='dashed') plt.axvline(sigma, color='g') #plt.axvline(Llmin,color='r',linewidth=5) print 'Is this still num ', num if num < 2 or num < 6 and num > 3 or num > 6 and num < 9: plt.xticks(visible=False) plt.ylim(-7.6, -1.6) if num < 4: plt.xlim(19, 25.8) plt.text(19.2, -7., '%.1f < z < %.1f' % (z_min, z_max), fontsize=19) # \n $M_i$ < -22 elif num < 7: plt.xlim(20.8, 27.2) plt.text(21., -7., '%.1f < z < %.1f' % (z_min, z_max), fontsize=19) # \n $M_i$ < -22 else: plt.xlim(21.3, 27.8) plt.text(21.5, -7., '%.1f < z < %.1f' % (z_min, z_max), fontsize=19) # \n $M_i$ < -22 if num == 3: plt.xticks([19, 20, 21, 22, 23, 24, 25], fontsize=22) if num == 6: plt.xticks([21, 22, 23, 24, 25, 26, 27], fontsize=22) if num == 9: plt.xticks([22, 23, 24, 25, 26, 27], fontsize=22) plt.legend(frameon=False).draggable() if num == 1 or num == 2 or num == 3 or num == 10: plt.yticks([-2., -3, -4, -5, -6], fontsize=22) if num == 3: plt.yticks([-2., -3, -4, -5, -6, -7], fontsize=22) continue plt.yticks(visible=False) fig.text(0.06, 0.5, r'$\rm{log_{10}[\Phi /(Mpc^{-3}mag^{-1})]}$', fontsize=30, ha='center', va='center', rotation='vertical') fig.text(0.5, 0.04, r'$\rm{log_{10}[L_{1.4}/(W}$ $\rm{Hz^{-1})]}$', fontsize=30, ha='center', va='center') #plt.text(23.9,-9.7,'%s'%outdir,fontsize = 16 ) # \n $M_i$ < -22 plt.tick_params(axis='both', which='major', labelsize=20, width=3) plt.tick_params(axis='both', which='minor', labelsize=10, width=2) plt.subplots_adjust(hspace=0, wspace=0) #plt.xtick(fontsize=15) #plt.ytick(fontsize=15) #plt.ylim(-10.2,-5.8) #plt.ylim(-11,-5.5) #ax.xaxis.set_minor_locator(AutoMinorLocator()) #ax.yaxis.set_minor_locator(AutoMinorLocator()) #print truth['LMIN'] plotf = '%s/LF_recon_s1.pdf' % (outdir) plt.show() return 0
def main(): """ """ print 'Settings file is %s' % setf # Import the settings variables set_module=importlib.import_module(setf) globals().update(set_module.__dict__) expt=countModel(modelFamily,nlaws,setf,[dataset],floatNoise) recon_expt=countModel(modelFamily,nlaws,setf,[dataset],floatNoise) #print expt.data #print expt.bins # Get MAP parameters print '\n'*5 print len(expt.parameters) ncols = len(expt.parameters) summf=os.path.join(outdir,'1-summary.txt') summary=numpy.genfromtxt(summf)[-1,:] drawmap=summary[-(ncols+2):-2] ana=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join(outdir,outstem)) drawmap=ana.get_best_fit()['parameters'] if dataset=='sdss': print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf)==20: num = dataf[-5] print num else: num = dataf[-6:-4] d=numpy.genfromtxt('%s/%s'%(outdir,datafiles[0][4:])) print datafiles[0][4:] elif dataset=='cosmos': print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf)==24: num = dataf[-5] print num else: num = dataf[-6:-4] d=numpy.genfromtxt('%s/%s'%(outdir,datafiles[0][8:])) print datafiles[0][8:] elif 'sim' in dataset: d=numpy.genfromtxt(os.path.join(outdir,'sim.txt')) #bins2 = numpy.arange(21.4,29.2,0.4) bins2 = numpy.arange(18.0,29.2,0.4) bins3 = numpy.arange(18.,29.2,0.01) print len(expt.parameters) print 'this is 1st num ', num #sys.exit() params = drawmap# [0] #for i in drawmap: # params.append(i) print params print expt.parameters #novak 2017 L_n =[21.77,22.15,22.46,22.77,23.09,23.34] rho_n =[-2.85,-2.88,-3.12,-3.55,-4.05,-4.63] L_ner_u =[0.23,0.18,0.19, 0.2, 0.21, 0.28] L_ner_d =[1.1, 0.15, 0.14, 0.12, 0.12, 0.048] rho_ner=[0.09, 0.03,0.0355,0.059,0.1,0.234] #novak 2018 nov_z,nov_z_u, nov_z_l, nov_sfrd, nov_sfrd_u, nov_sfrd_l, Lower, lw_up, lw_lw, nov_phi_L, nov_phi_L2 = numpy.loadtxt('novak_2017.txt',usecols=(0,1,2, 3,4,5, 6,7,8,-2,-1),unpack=True) #fig,ax = subplots() pre_chain='12' chains=['01a_4','01b_4','01c_4','01d_4','01e_4','01f_4','01g_4','01h_4','01i_4_2', '01j_4_2']#chains_191101 7x7 grid chains=['02a_4','02b_4','02c_4','02d_4','02e_4','02f_4','02g_5','02h_4','02i_4','02j_4']#chains_191101 7x7 grid lognorm #chains=['01a_5','01b_5','01c_5','01d_5','01e_5','01f_5','01g_5','01h_5','01i_5']#chains_191101 3x3 grid scaled #chains=['01a_6','01b_6','01c_6','01d_6','01e_6','01f_6','01g_6','01h_6','01i_6']#chains_191101 11x11 grid #chains=['01a','01b','01c','01d','01e','01f','01g','01h','01i'] #chains_1912 #includeing maskregion chains=['01a_3','01b_3','01c_3','01d_3','01e','01f','01g','01h','01i','01j'] #chains_1912 including peter #chains=['01a_2_1','01b_2_1','01c_2_1','01d_2','01e_2','01f_2','01g_2','01h_2','01i_2','01j_2'] #chains=['01a_4_1','01b_4_1','01c_4','01d_4','01e_4','01f_4_1','01g_4','01h_4','01i_4','01j_4'] #chains_1912 no mass selection #chains=['01a_3','01b_2','01c_2','01d_2','01e_2','01f_2','01g','01h_2','01i_2','01j_3'] #chains_2001 DR4 remove phi2 chains=['01a_5','01b_5','01c_5','01d_5','01e_5','01f_5','01g_5','01h_5','01i_5','01j_5'] #chains_2001 DR4 remove phi2 new changes chains4=['01a_8','01b_8','01c_8','01d_8','01e_8','01f_8','01g_7','01h_8','01i_8','01j_7'] #chains_2001 DR4 dpl_dpl chains=['01a_9','01b_9','01c_9','01d_9','01e_9','01f_9','01g_9','01h_9','01i_9','01j_9'] #chains_2001 DR4 dpl_dpl no mass selection #chains=['02a_z_9_6','02b_z_9_6','02c_z_9_6','02d_z_9_6','02e_z_9_6','02f_z_9_6','02g_z_9_6','02h_z_9_6','02i_z_9_6','02j_z_9_6'] chains=['01a_6_1','01a_8_2','01b_6_3','01c_6_3','01d_6_2','01e_6_2','01f_6_2','01g_6_2','01h_6_3','01i_6_3','01j_6_3'] #chains_2001 DR4 dpl_dpl Lmin=19 newz chains=['02a_4_1','02a_4_2','02b_4','02c_4','02d_4','02e_4','02f_4','02g_4','02h_4','02i_4','02j_3'] chains2=['02a_z_5x','02b_z_5x','02c_z_5x','02d_z_5x','02e_z_5x','02f_z_5x','02g_z_5x','02h_z_5x','02i_z_5x_2','02j_z_5x'] chains2=['02a_z_6x_1','02a_z_6x_2','02b_z_7x','02c_z_7x','02d_z_7x','02e_z_7x','02f_z_7x','02g_z_7x','02h_z_7x','02i_z_7x','02j_z_7x'] #chains=['01a','01b','01c','01d','01e','01f','01g','01h','01i','01j'] #dpl #chains_2001 DR4 newz new_area chains4=['02a','02b','02c','02d','02e','02f','02g','02h','02i','02j'] #lgnorm #chains_2001 DR4 newz new_area chains2=['02a_z_8x','02b_z_8x','02c_z_8x','02d_z_8x','02e_z_8x','02f_z_8x','02g_z_8x','02h_z_8x','02i_z_8x','02j_z_8x']#fixed model newz area chains=['02a_z_8x_4','02b_z_8x_4','02c_z_8x_4','02d_z_8x_4','02e_z_8x_4','02f_z_8x_4','02g_z_8x_4','02h_z_8x_4','02i_z_8x_4','02j_z_8x_4']#fixed model newz area #chains=['02a_z_8x_6','02b_z_8x_6','02c_z_8x_6','02d_z_8x_6','02e_z_8x_6','02f_z_8x_6','02g_z_8x_6','02h_z_8x_6','02i_z_8x_6','02j_z_8x_6']#fixed cut data more bins wrong noise chains=['02a_z_8x_6_1','02b_z_8x_6_1','02c_z_8x_6_1','02d_z_8x_6_1','02e_z_8x_6_1','02f_z_8x_6_1','02g_z_8x_6_3','02h_z_8x_6_3','02i_z_8x_6_3','02j_z_8x_6_3']#fixed cut data more bins _el lmin lose chains2=['02a_z_8x_6_1','02b_z_8x_6_1','02c_z_8x_6_1','02d_z_8x_6_1','02e_z_8x_6_1','02f_z_8x_6_1','02g_z_8x_6_3','02h_z_8x_6_3','02i_z_8x_6_3','02j_z_8x_6_3']#fixed cut data more bins _el lmin lose chains3='02z_31_5_15' print expt.parameters z_new=True Replot=False z_nov = [0.31, 0.5, 0.69, 0.9, 1.16, 1.44, 1.81, 2.18, 2.81, 3.71, 4.83] if z_new: z =[0.1,0.3,0.4,0.6,0.8,1.0,1.3,1.6,2.0,2.5,3.2,4.0] #chains=['11a','11b','11c_3','11d_3','11e_3','11f_3','11g_3','11h','11i','11j', '11k', '11l' ,'11m', '11n']#chains_191111 else: z=[0.1,0.4,0.6,0.8,1.0,1.3,1.6,2.0,2.5,3.2,4.0]#oldest ;) sfrd, sfrd_l,sfrd_h,z_med = numpy.zeros(len(z)+1),numpy.zeros(len(z)+1) ,\ numpy.zeros(len(z)+1) ,numpy.zeros(len(z)+1) sfrd_nov, sfrd_nov_l,sfrd_nov_h, sfrd_2, sfrd_3, sfrd_4, sfrd_2_l, sfrd_3_l, sfrd_2_h, sfrd_3_h = numpy.zeros(len(z)+1),\ numpy.zeros(len(z)+1), numpy.zeros(len(z)+1) ,numpy.zeros(len(z)+1),numpy.zeros(len(z)+1),\ numpy.zeros(len(z)+1), numpy.zeros(len(z)+1) ,numpy.zeros(len(z)+1),numpy.zeros(len(z)+1) ,\ numpy.zeros(len(z)+1) ana3=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join('chains_2012%s'%chains3,outstem)) drawmap3=ana3.get_best_fit()['parameters'] params3 = drawmap3 print 'chains_2002%s'%chains3 print params3 parameters2= ['noise', 'A_SF', 'A_agn', 'LMIN', 'LMAX'] parameters3= ['noise', 'A_agn', 'A_SF', 'B_agn', 'B_SF', 'LMIN', 'LMAX'] parameters3= ['noise', 'A_agn', 'A_SF', 'B_agn', 'B_SF', 'LMIN_1', 'LMIN_2', 'LMIN_3', 'LMIN_4', 'LMIN_5', 'LMIN_6', 'LMIN_7', 'LMIN_8', 'LMIN_9', 'LMIN', 'LMAX'] parameters4=['noise', 'LMIN', 'LMAX2', 'LMIN2', 'LMAX', 'LNORM', 'LSTAR', 'LSLOPE', 'LSLOPE2', 'LNORM_2', 'LSTAR_2', 'LSLOPE_2', 'LSLOPE2_2'] for num in range(1,11): #num = 1. print num z_min,z_max, z_m = get_z(num,False) dl = get_dl(z_m) Vmax = get_Vmax(z_min,z_max) dsdl = get_dsdl(z_m,dl) dl = get_dl(z_m) print z_min,z_m,z_max print expt.kind area = SURVEY_AREA*sqDeg2sr area1 = SURVEY_AREA*sqDeg2sr print SURVEY_AREA ana=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join('chains_20%s%s'%(pre_chain,chains[num-1]),outstem)) drawmap=ana.get_best_fit()['parameters'] drawmid=ana.get_stats()['marginals'] params = drawmap print params ana2=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join('chains_2012%s'%(chains2[num-1]),outstem)) drawmap2=ana2.get_best_fit()['parameters'] params2 = drawmap2 #ana4=pymultinest.analyse.Analyzer(ncols-1,\ # outputfiles_basename=os.path.join('chains_20%s%s'%(pre_chain,chains4[num-1]),outstem)) #drawmap4=ana4.get_best_fit()['parameters'] #params4 = drawmap4 print 'parameter 1 ', params print 'parameters 2 ', params2 print 'parameters 3 ', params3 settingf='chains_20%s%s/bayestack_settings.py'%(pre_chain,chains[num-1]) f = open(settingf, 'r') mod = f.readlines()[31].split()[0] print mod if 'logn' in mod: if 'dpl' in mod: model='LFlognorm_dpl' elif '_el' in mod: model='LFevol_logn_el' elif 'pl_' in mod: model='LFpl_lognorm' else: model='LFlognorm' elif 'LFdpl' in mod or 'LFpl' in mod: if 'LFdpl_dpl' in mod: model='LFdpl_dpl' elif '_pl' in mod: model='LFdpl_pl' elif 'LFpl_' in mod: model='LFpl_dpl' elif 'LFpl' in mod: model='LFpl' else: model = 'LFdpl' with open('chains_20%s%s/params.tex'%(pre_chain,chains[num -1])) as f: parameters=[line.split(None,1)[0] for line in f] #model='LFdpl_pl' print parameters print model print 'LSIGMA' in parameters if model in ['LFsch','LFdpl_pl','LFpl_dpl','LFdpl_dpl','LFlognorm_dpl']: Lnorm=params[parameters.index('LNORM')] Lstar=params[parameters.index('LSTAR')] Lslope=params[parameters.index('LSLOPE')] #Lzevol=params[parameters.index('LZEVOL')] if model in ['LFdpl_pl','LFpl_dpl','LFdpl_dpl','LFlognorm_dpl']: Lslope2=params[parameters.index('LSLOPE2')] if model in ['LFlognorm','LFpl', 'LFdpl', 'LFdpl_pl','LFpl_dpl', 'LFlognorm_dpl','LFdpl_dpl']: Lnorm_2=params[parameters.index('LNORM_2')] Lstar_2=params[parameters.index('LSTAR_2')] Lslope_2=params[parameters.index('LSLOPE_2')] if model in ['LFdpl_dpl','LFdpl']: Lslope2_2=params[parameters.index('LSLOPE2_2')] if model in ['LFlognorm','LFlognorm_dpl']: Lsigma = params[parameters.index('LSIGMA')] Lmin=params[parameters.index('LMIN')] Lmax=params[parameters.index('LMAX')] #Lmax2=params[parameters.index('LMAX2')] Lmax2=Lmax SMIN = get_sbins(numpy.power(10,Lmin),z_m,dl)*1e6 SMAX = get_sbins(numpy.power(10,Lmax),z_m,dl)*1e6 sigma,fsigma = numpy.log10(get_Lbins([SURVEY_NOISE,SURVEY_NOISE*5],z_m,dl,'muJy')*(1.4/3)**(-.7)) sigma2,fsigma2 = numpy.log10(get_Lbins([450,2400],z_m,dl,'muJy')) print z_m,dl, sigma,fsigma print SURVEY_NOISE,SURVEY_NOISE*5,SURVEY_AREA s=numpy.loadtxt('chains_20%s%s/recon_stats.txt'%(pre_chain,chains[num -1])) xrecon=s[:-1,0]; yrecon=s[:-1,1] yrecon_d=s[:-1,2]; yrecon_u=s[:-1,3] yrecon_rms = s[:-1,4] yrecon_avr = s[:-1,5] yrecon_rms_down = yrecon_rms yrec_u = yrecon_u - yrecon yrec_d = yrecon - yrecon_d #print yrecon_d #print yrecon #print yrecon_u #sys.exit() #y_err_u = sqrt(yrec) xreco = get_Lbins(xrecon,z_m,dl,'muJy')#*(1.4/3)**(-.7) xreco2 = get_Lbins(xrecon,z_m,dl,'muJy') yreco = yrecon lin_yrecon = numpy.log10(yreco) lin_xrecon = numpy.log10(xreco) lin_xrecon2 = numpy.log10(xreco2) q_l,q,q_h = get_q(z_m) #print z_nov[num -1] try: yrecon_nov = lumfuncUtils.lognormpl(get_Lbins(xrecon,z_m,dl,'muJy')/(1 + z_nov[num-1])**(3.16-z_nov[num-1]*0.32), numpy.log10(1.85e21),1.22,0.63, numpy.log10(3.55e-3)) except: print '' str_q_l = get_sfr_q(1.,q_l,xreco2) str_q_h = get_sfr_q(1.,q_h,xreco2) str_q = get_sfr_q(1.,q,xreco2) #sys.exit() lmin = 21.5#. 21.5 Lmax=26. sfrd_z_l=get_sfrd_z(yrecon,lin_xrecon2,str_q_l,params,parameters,model,q_l ,Lmax2,lmin,z_m)[0] #lower limit sfrd_z_h=get_sfrd_z(yrecon,lin_xrecon2,str_q_h,params,parameters,model,q_h ,Lmax2,lmin,z_m)[0] #upper limit sfrd_z =get_sfrd_z(yrecon,lin_xrecon2,str_q ,params,parameters,model,q ,Lmax2,lmin,z_m)[0] #26, 21.5 sfrd_2_z =get_sfrd_z(yrecon,lin_xrecon2,str_q ,params2,parameters2,'LFevol_logn_mat',q ,Lmax2,lmin,z_m)[0] sfrd_3_z =get_sfrd_z(yrecon,lin_xrecon2,str_q ,params3,parameters3,'LFevol_logn_L',q ,Lmax2,lmin,z_m)[0] #sfrd_4_z =get_sfrd_z(yrecon,lin_xrecon2,str_q ,params4,parameters4,'LFdpl_dpl',q ,Lmax2,lmin,z_m)[0] sfrd_2_z_l =get_sfrd_z(yrecon,lin_xrecon2,str_q_l ,params2,parameters2,'LFevol_logn_mat',q_l ,Lmax2,lmin,z_m)[0] sfrd_3_z_l =get_sfrd_z(yrecon,lin_xrecon2,str_q_l ,params3,parameters3,'LFevol_logn_L',q_l ,Lmax2,lmin,z_m)[0] sfrd_2_z_h =get_sfrd_z(yrecon,lin_xrecon2,str_q_h ,params2,parameters2,'LFevol_logn_mat',q_h ,Lmax2,lmin,z_m)[0] sfrd_3_z_h =get_sfrd_z(yrecon,lin_xrecon2,str_q_h ,params3,parameters3,'LFevol_logn_L',q_h ,Lmax2,lmin,z_m)[0] #sfrd_z_l=get_sfrd_z(yrecon,lin_xrecon2,str_q_l,params,parameters,model,q_l ,Lmax2,Lmin)[0] #lower limit #sfrd_z_h=get_sfrd_z(yrecon,lin_xrecon2,str_q_h,params,parameters,model,q_h ,Lmax2,Lmin)[0] #upper limit #sfrd_z =get_sfrd_z(yrecon,lin_xrecon2,str_q ,params,parameters,model,q ,Lmax2,Lmin)[0] #26, 21.5 #sys.exit() #sfrd_nov_z =get_sfrd_z(yrecon_nov,lin_xrecon,str_q ,params,parameters,'novak',get_q(z_nov[num-1])[1] ,26,lmin, z=z_nov[num-1])[0] #print 'This is nov z ', z_nov[num-1] #sys.exit() #sfrd_z =get_sfrd_z(yrecon,lin_xrecon,str_q ,params,parameters,model,q ,Lmax2,Lmin)[0] #sfrd_z,sfrd_zerr= get_sfrd_z(yrecon,lin_xrecon,str_q,numpy.inf,0.) sfrd[num-1] = sfrd_z sfrd_l[num-1] = sfrd_z_l sfrd_h[num-1] = sfrd_z_h z_med[num-1] = z_m #sfrd_nov[num-1] =sfrd_nov_z sfrd_2[num-1] = sfrd_2_z sfrd_3[num-1] = sfrd_3_z #sfrd_4[num-1] = sfrd_4_z sfrd_2_l[num-1] = sfrd_2_z_l sfrd_3_l[num-1] = sfrd_3_z_l sfrd_2_h[num-1] = sfrd_2_z_h sfrd_3_h[num-1] = sfrd_3_z_h #plt.plot(lin_xrecon,numpy.log10(str_q),'*',markersize=8) try: zrecon, srecon, srecon_l, srecon_h =numpy.loadtxt('sfrd_chains_2012%s_Lmin_%s'%(chains[0],'21_5'),unpack=True) except: print 'Please note that the 95 percent region has to be run for chains_2001%s ... python reconstruct_lf_plot.py'%chains[0] print 'Ensure that chains in reconstruct_lf_plot.py cooresponds to chains in this file!' zrecon, srecon, srecon_l, srecon_h=0,0,0,0 try: zrecon, srecon2, srecon_l2, srecon_h2 =numpy.loadtxt('sfrd_chains_2012%s_Lmin_%s'%(chains[0],'19'),unpack=True) except: print 'Please note that the 95 percent region has to be run for chains_2001%s ... python reconstruct_lf_plot.py'%chains[0] print 'Ensure that chains in reconstruct_lf_plot.py cooresponds to chains in this file!' zrecon2, srecon2, srecon_l2, srecon_h2=0,0,0,0 try: zrecon_2, srecon_2, srecon_l_2, srecon_h_2 =numpy.loadtxt('sfrd_chains_2011%s_Lmin_%s'%(chains4[0],'21_5'),unpack=True) except: print 'Please note that the 95 percent region has to be run for chains_2002%s ... python reconstruct_lf_plot.py'%(chains2[0]) print 'Ensure that chains in reconstruct_lf_plot.py cooresponds to chains in this file!' zrecon_2, srecon_2, srecon_l_2, srecon_h_2=0,0,0,0 try: zrecon_3, srecon_3, srecon_l_3, srecon_h_3 =numpy.loadtxt('sfrd_chains_2012%s_Lmin_%s'%(chains3,'21_5'),unpack=True) except: print 'Please note that the 95 percent region has to be run for chains_2002%s ... python reconstruct_lf_plot.py'%chains3[0] print 'Ensure that chains in reconstruct_lf_plot.py cooresponds to chains in this file!' zrecon_3, srecon_3, srecon_l_3, srecon_h_3=0,0,0,0 try: zrecon_3_2, srecon_3_2, srecon_l_3_2, srecon_h_3_2 =numpy.loadtxt('sfrd_chains_2012%s_Lmin_%s'%(chains3,'21_5'),unpack=True) except: print 'Please note that the 95 percent region has to be run for chains_2002%s ... python reconstruct_lf_plot.py'%chains3[0] print 'Ensure that chains in reconstruct_lf_plot.py cooresponds to chains in this file!' zrecon_3_2, srecon_3_2, srecon_l_3_2, srecon_h_3_2=0,0,0,0 #plt.rc('lines', linewidth=2) #plt.xlabel(r'$\rm{log_{10}[L_{1.4}/(W}$ $\rm{Hz^{-1})]}$',fontsize = 30) #plt.ylabel(r'$\rm{log_{10}[SFR_{IR}(M_\odot yr^{-1})]}$',fontsize = 30) #plt.tick_params(axis='both',which = 'major', labelsize=20,width =3) #plt.tick_params(axis='both',which = 'minor', labelsize=10, width=2) #plt.show() #fig = plt.figure() #print z_med #print sfrd_l #print sfrd #print sfrd_h #print len(z),len(sfrd) #Salpeter to Chabrier * 0.63 print zrecon_2,srecon_2, srecon_l_2, srecon_h_2 srecon_2_err=2*0.434*(srecon_h_2)/numpy.log10(srecon_2) z_b=numpy.arange(0,60)/10. Ilbert_h = sfrd_Behroozi(z_b,z0=0.95-0.410,A=-1.,B=0.194-0.082,C=0.111+0.04) Ilbert_l = sfrd_Behroozi(z_b,z0=0.95+0.343,A=-1.,B=0.194+0.128,C=0.111-0.029) parasa = parsa_z(z_b,a=0.11,b=1.48,c=2.75) Koprowski= parsa_z(z_b,a=0.18,b=1.04,c=1.77) #plt.errorbar(z_med,numpy.log10(sfrd),fmt='h',fillstyle='none',markeredgewidth=3,markersize=18, label=r'$\rm{Model}$ $\rm{C}$') #plt.errorbar(z_med,numpy.log10(sfrd_3),fmt='h',fillstyle='none',markeredgewidth=3,markersize=18, label=r'$\rm{Model}$ $\rm{C}$ $\rm{PLE}$') plt.errorbar(zrecon_2,numpy.log10(srecon_2),yerr=srecon_2_err,fmt='h',fillstyle='none',markeredgewidth=3,markersize=18, label=r'$\rm{Model}$ $\rm{B}$') #plt.errorbar(z_med,numpy.log10(sfrd),fmt='h',fillstyle='none',markeredgewidth=3,markersize=18, label=r'$\rm{Model}$ $\rm{C}$') #plt.errorbar(z_med,numpy.log10(sfrd_2),fmt='h',fillstyle='none',markeredgewidth=3,markersize=15, label=r'$\rm{Model}$ $\rm{C}$') #plt.errorbar(z_med,numpy.log10(sfrd_3),fmt='-k',linewidth=5, label=r'$\rm{Model}$ $\rm{C}$ $\rm{PLE}$') #plt.errorbar(zrecon_3_2,numpy.log10(srecon_3_2),fmt='-m',linewidth=5, label=r'$\rm{Model}$ $\rm{C}$ $\rm{PLE}$ $\rm{q(z=0)}$') #plt.errorbar(zrecon_2,numpy.log10(srecon_2),fmt='.-k',linewidth=5, label=r'$\rm{Model}$ $\rm{B}$') G_x , Gruppioni = numpy.loadtxt('Gruppioni_2013',unpack=True,delimiter=',') G_x1, Gruppioni_yup = numpy.loadtxt('Gruppioni_2013_y_up',unpack=True,delimiter=',') G_x2, Gruppioni_ydown = numpy.loadtxt('Gruppioni_2013_y_down',unpack=True,delimiter=',') Burg_z, Burg_FIR, Burg_FIR_er, Burg_tot, Burg_tot_er = numpy.loadtxt('Burgarella_2013',unpack=True) Lzl,Lzh,Lphi_tot,Lphi_ir,Ler = numpy.loadtxt('Liu_2018',unpack=True) print Lzl,Lzh Lz = numpy.mean(numpy.array([Lzl,Lzh]),axis=0) print Lz #plt.errorbar(z_med,numpy.log10(sfrd_4),fmt='--k',linewidth=7, label='No mass-limit') plt.errorbar(Lz,Lphi_tot,yerr=Ler,fmt='*g',markeredgewidth=1.8,markersize=16, fillstyle='none', label=r'$\rm{Liu+2018}$ $\rm{FIR+UV}$') try: plt.errorbar(numpy.array(nov_z),numpy.array(nov_sfrd),xerr=[nov_z_l,nov_z_u],yerr=[nov_sfrd_l,nov_sfrd_u], fmt='sr',fillstyle='none',ecolor='k',markeredgewidth=1.5, markersize=10, label=r'$\rm{Novak+2017}$ $\rm{PLE}$ $\rm{radio}$') except: print '' plt.errorbar(z_b,numpy.log10(Koprowski),fmt='--k',linewidth=3, label=r'$\rm{Koprowski+2017}$ $\rm{IR}$') #plt.errorbar(z_b,numpy.log10(parasa),fmt='.g',linewidth=3, label=r'$\rm{Parsa}$ + $\rm{2016}$ $\rm{UV}$') plt.errorbar(z_b,numpy.log10(sfrd_Madau(z_b)),fmt='o-c',linewidth=3,fillstyle='none', label=r'$\rm{Madau&Dickinson}$ $\rm{2014}$') #plt.errorbar(z_med,numpy.log10(sfrd_l)+0.4,fmt='--',markersize=8,label='low') #plt.errorbar(z_med,numpy.log10(sfrd_h)+0.4,fmt='--',markersize=8,label='high') #plt.errorbar(numpy.array(nov_z),numpy.array(Lower),xerr=[nov_z_l,nov_z_u],yerr=[lw_up, lw_lw], fmt='*g', label='lower limit SFRD Novak et al 2017') #plt.yscale('log') #plt.fill_between(z_med,numpy.log10((sfrd_l)),numpy.log10(sfrd_h), color='b',alpha=0.5) #plt.fill_between(z_med,numpy.log10((sfrd_2_l)),numpy.log10(sfrd_2_h), color='c',alpha=0.7) #plt.fill_between(z_med,numpy.log10((sfrd_3_l)),numpy.log10(sfrd_3_h), color='g',alpha=0.5) #plt.fill_between(zrecon,numpy.log10((srecon_l)),numpy.log10(srecon_h), label='95% Free Model',color='b',alpha=0.3) #plt.fill_between(z_b,numpy.log10((Ilbert_l)),numpy.log10(Ilbert_h), color='orange',alpha=0.2) #plt.fill_between(zrecon,numpy.log10((srecon_l_2)),numpy.log10(srecon_h_2), label='95% Model B',color='g',alpha=0.6) #plt.fill_between(zrecon,numpy.log10(srecon_l_3_2),numpy.log10(srecon_h_3_2),edgecolor="k",linewidth=5, label=r'$\rm{95\%}$ $\rm{Model}$ $\rm{C}$ $\rm{PLE}$ $\rm{q_{TIR}(z=0)}$',color='m',alpha=0.6) plt.fill_between(zrecon,numpy.log10((srecon_l_3)),numpy.log10(srecon_h_3), label=r'$\rm{95\%}$ $\rm{Model}$ $\rm{C}$ $\rm{PLE}$',color='m',alpha=0.6) plt.fill_between(zrecon,numpy.log10((srecon_l)),numpy.log10(srecon_h), label=r'$\rm{95\%}$ $\rm{Model}$ $\rm{C}$ $\rm{Individual}$',color='b',alpha=0.4) plt.fill_between(zrecon,numpy.log10((srecon_l2)),numpy.log10(srecon_h2), edgecolor="k", linewidth=4, label=r'$\rm{95\%}$ $\rm{Model}$ $\rm{C}$ $\rm{Individual}$ $\rm{q_{TIR}(z=0)}$',color='b',alpha=0.4) plt.fill_between(G_x,numpy.log10(Gruppioni_ydown),numpy.log10(Gruppioni_yup), color='k',alpha=0.3,label=r'$\rm{Gruppioni+2013}$ $\rm{IR}$') #plt.fill_between(nov_z,nov_phi_L, nov_phi_L2, color='r',alpha=0.4,label='Novak+2017 $\Phi$ and L Evolution') #plt.fill_between(Burg_z,numpy.log10(0.63*0.01*(Burg_FIR - Burg_FIR_er)),numpy.log10(0.63*0.01*(Burg_FIR + Burg_FIR_er)), color='r',alpha=0.2,label='Burgarella-2013 FIR') #plt.fill_between(Burg_z,numpy.log10(0.63*0.01*(Burg_tot - Burg_tot_er)),numpy.log10(0.63*0.01*(Burg_tot + Burg_tot_er)), color='g',alpha=0.2,label='Burgarella-2013 Total') plt.ylabel(r'$\rm{\log10(SFRD[M_\odot yr^{-1} Mpc^{-3}])}$',fontsize=32) plt.xlabel(r'$\rm{z} $',fontsize = 35) #plt.text(23.9,-9.7,'%s'%outdir,fontsize = 16 ) # \n $M_i$ < -22 plt.tick_params(axis='both',which = 'major', labelsize=20,width =1) plt.tick_params(axis='both',which = 'minor', labelsize=10, width=1) plt.subplots_adjust(hspace=0,wspace=0) #plt.xtick(fontsize=15) #plt.ytick(fontsize=15) #plt.ylim(-10.2,-5.8) ##plt.ylim(-2.7,0) plt.ylim(-2.2,-0.5) plt.xlim(0,3.8) #plt.ylim(-2.3,-0.3) #ax.xaxis.set_minor_locator(AutoMinorLocator()) #ax.yaxis.set_minor_locator(AutoMinorLocator()) #print truth['LMIN'] plotf='%s/LF_recon_s1.pdf' % (outdir) handles,labels=plt.gca().get_legend_handles_labels() print labels print len(labels) order=[4, 1,2, 0,3,5, 6, 7,8] plt.legend([handles[idx] for idx in order],[labels[idx] for idx in order],frameon=False,ncol=2, prop={'size':24}).draggable() plt.show() return 0
def main(): """ """ print 'Settings file is %s' % setf # Import the settings variables set_module = importlib.import_module(setf) globals().update(set_module.__dict__) expt = countModel(modelFamily, nlaws, setf, [dataset], floatNoise, doRedshiftSlices=True) recon_expt = countModel(modelFamily, nlaws, setf, [dataset], floatNoise) #print expt.data #print expt.bins # Get MAP parameters print '\n' * 5 print len(expt.parameters) ncols = len(expt.parameters) summf = os.path.join(outdir, '1-summary.txt') summary = numpy.genfromtxt(summf)[-1, :] drawmap = summary[-(ncols + 2):-2] ana=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join(outdir,outstem)) drawmap = ana.get_best_fit()['parameters'] if dataset == 'sdss': print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf) == 20: num = dataf[-5] print num else: num = dataf[-6:-4] d = numpy.genfromtxt('%s/%s' % (outdir, datafiles[0][4:])) print datafiles[0][4:] elif dataset == 'cosmos': #print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf) == 24: num = dataf[-5] print num else: num = dataf[-6:-4] d = numpy.genfromtxt('%s/%s' % (outdir, datafiles[0][8:])) #print '%s%s'%(outdir,datafiles[0][8:]) print datafiles[0][8:] elif 'sim' in dataset: d = numpy.genfromtxt(os.path.join(outdir, 'sim.txt')) ssbin = d[:, 2] Nbin = d[:, 3] dnds = d[:, 4] sbin2 = ssbin dnds2 = dnds #bins2 = numpy.arange(21.4,29.2,0.4) bins2 = numpy.arange(18.0, 29.2, 0.4) bins3 = numpy.arange(18., 29.2, 0.01) print len(expt.parameters) print 'this is 1st num ', num #sys.exit() params = drawmap # [0] #for i in drawmap: # params.append(i) print params print expt.parameters if modelFamily in [ 'LFsch', 'LFdpl_pl', 'LFpl_dpl', 'LFdpl_dpl', 'LFdpl_dpl_z', 'LFlognorm_dpl', 'LFpl_lognorm' ]: Lnorm = params[expt.parameters.index('LNORM')] Lstar = params[expt.parameters.index('LSTAR')] Lslope = params[expt.parameters.index('LSLOPE')] #Lzevol=params[expt.parameters.index('LZEVOL')] if modelFamily in ['LFdpl_pl', 'LFpl_dpl', 'LFdpl_dpl', 'LFlognorm_dpl']: Lslope2 = params[expt.parameters.index('LSLOPE2')] if modelFamily in [ 'LFlognorm', 'LFpl', 'LFdpl', 'LFdpl_pl', 'LFpl_dpl', 'LFlognorm_dpl', 'LFdpl_dpl', 'LFdpl_dpl_z', 'LFpl_lognorm' ]: Lnorm_2 = params[expt.parameters.index('LNORM_2')] Lstar_2 = params[expt.parameters.index('LSTAR_2')] Lslope_2 = params[expt.parameters.index('LSLOPE_2')] if modelFamily in ['LFdpl_dpl', 'LFdpl', 'LFdpl_dpl_z']: Lslope2_2 = params[expt.parameters.index('LSLOPE2_2')] if modelFamily in [ 'LFlognorm', 'LFlognorm_dpl', 'LFpl_lognorm', 'LFevol_logn_sigma' ]: Lsigma = params[expt.parameters.index('LSIGMA')] if modelFamily in [ 'LFdpl_dpl_z', 'LFevol_dpl', 'LFevol_logn', 'LFevol_logn_all', 'LFevol_logn_all_L' ]: alpha_agn = params[expt.parameters.index('A_agn')] alpha_SF = params[expt.parameters.index('A_SF')] beta_agn = params[expt.parameters.index('B_agn')] beta_SF = params[expt.parameters.index('B_SF')] if modelFamily in ['LFevol_dpl_s', 'LFevol_logn_s']: alpha_SF = params[expt.parameters.index('A_SF')] beta_SF = params[expt.parameters.index('B_SF')] if modelFamily in [ 'LFevol_logn_lnorm', 'LFevol_logn_all', 'LFevol_logn_all_L' ]: Lnorm = params[expt.parameters.index('LNORM')] Lstar = params[expt.parameters.index('LSTAR')] if modelFamily in [ 'LFevol_logn_mat', 'LFevol_phi_logn_mat', 'LFevol_logn_el', 'LFevol_logn_sigma', 'LFevol_logn_lmin', 'LFevol_logn_lnorm' ]: alpha_SF = params[expt.parameters.index('A_SF')] alpha_agn = params[expt.parameters.index('A_agn')] if modelFamily in [ 'LFevol_logn_slope', 'LFevol_logn_all', 'LFevol_logn_all_L' ]: alpha_SF = params[expt.parameters.index('A_SF')] alpha_agn = params[expt.parameters.index('A_agn')] Lslope2_2 = params[expt.parameters.index('LSLOPE2_2')] Lmin = params[expt.parameters.index('LMIN')] Lmax = params[expt.parameters.index('LMAX')] truth = { 'noise': 150, 'LMIN': 22., 'LMAX': 24.5, 'LNORM': numpy.log10(1e-7), 'LSTAR': 23.3, 'LSLOPE': 3., 'LSLOPE2': 1. } #z = [0, 0.5, 1 , 1.5, 2, 2.3, 2.6, 3, 3.5, 4] #old #z = [ 0.7, 1 , 1.35, 1.7, 2, 2.3, 2.6, 3, 3.5, 4]# older print expt.parameters s = pylab.loadtxt('%s/recon_stats.txt' % outdir) xrecon = s[:-1, 0] yrecon = s[:-1, 1] yrecon_d = s[:-1, 2] yrecon_u = s[:-1, 3] yrecon_rms = s[:-1, 4] yrecon_avr = s[:-1, 5] yrecon_rms_down = yrecon_rms #novak 2018 L_n2 =[[21.77,22.24,22.68,23.16,23.69,24.34, 24.74,25.56],\ [22.30,22.61,22.96,23.38,23.80,24.10, 24.55,25.14],\ [22.61,22.86,23.14,23.45,23.82,24.14, 24.40,24.71],\ [22.85,23.16,23.69,24.24,24.80,25.31, 25.96,26.69],\ [23.10,23.38,23.86,24.36,24.86,25.35, 25.94,26.36],\ [23.32,23.57,23.94,24.32,24.67,25.06, 25.47,25.96],\ [23.54,23.75,24.13,24.45,24.90,25.27, 25.74,26.10],\ [23.73,23.99,24.57,25.10,25.68,26.18, 26.83,27.51],\ [24.01,24.26,24.76,25.26,25.91,26.19, 27.45],\ [24.30,24.56,24.80,25.13,25.37,25.80, 25.97,26.49]] L_ner_u2 =[[0.23,0.27, 0.34, 0.37, 0.35, 0.21, 0.31, 0.03],\ [0.11,0.20, 0.26, 0.25, 0.24, 0.35, 0.31, 0.15],\ [0.08,0.15, 0.20, 0.22, 0.17, 0.18, 0.24, 0.28],\ [0.072,0.33,0.38, 0.40, 0.48, 0.42, 0.41, 0.28],\ [0.080,0.30,0.32, 0.32, 0.32, 0.33, 0.24, 0.34],\ [0.068,0.22,0.24, 0.25, 0.29, 0.30, 0.28, 0.21],\ [0.067,0.22,0.21, 0.26, 0.18, 0.17,0.075, 0.11],\ [0.093,0.36,0.31, 0.30, 0.25, 0.28, 0.16,0.028],\ [0.076,0.34,0.36, 0.38, 0.24, 0.47, 0.27],\ [0.097,0.14,0.20, 0.16, 0.23, 0.092,0.22,0.026]] L_ner_d2 =[[1.0, 0.24, 0.17, 0.14, 0.16, 0.30, 0.20, 0.50],\ [0.29, 0.21, 0.15, 0.16, 0.17, 0.06, 0.099,0.29],\ [0.24, 0.17, 0.12, 0.10, 0.15, 0.15, 0.08,0.074],\ [0.16, 0.24, 0.19, 0.17, 0.15, 0.09, 0.16, 0.33],\ [0.30, 0.19, 0.18, 0.18, 0.18, 0.17, 0.26, 0.18],\ [0.14, 0.18, 0.15, 0.14, 0.10, 0.095,0.11, 0.21],\ [0.19, 0.14, 0.15, 0.11, 0.19, 0.19, 0.29, 0.28],\ [0.40, 0.17, 0.21, 0.23, 0.27, 0.25, 0.37, 0.53],\ [0.20, 0.17, 0.16, 0.14, 0.27, 0.042, 0.27],\ [0.22, 0.16, 0.10, 0.14,0.072, 0.21, 0.08, 0.30]] rho_n2 =[[-2.84,-2.90,-3.34,-4.00,-4.92,-4.92, -5.22,-5.07],\ [-2.95,-3.17,-3.46,-4.24,-4.76,-5.41, -5.23,-5.44],\ [-2.95,-3.11,-3.44,-3.81,-4.37,-4.48, -4.90,-5.14],\ [-2.99,-3.24,-3.89,-4.54,-5.27,-5.33, -5.69,-5.89],\ [-3.32,-3.51,-4.06,-4.74,-5.28,-5.43, -6.08,-5.70],\ [-3.29,-3.54,-4.02,-4.45,-5.11,-5.56, -5.37,-6.07],\ [-3.43,-3.61,-4.19,-4.56,-5.09,-5.34, -5.70,-5.75],\ [-3.88,-3.98,-4.64,-5.33,-5.73,-6.27, -6.14,-6.77],\ [-3.85,-4.28,-5.05,-5.60,-5.68,-6.44, -6.59],\ [-4.43,-4.91,-5.46,-5.58,-5.89,-6.23, -6.26,-6.91]] rho_ner_u2=[[0.08,0.024,0.038,0.083,0.28,0.28 , 0.45, 0.34],\ [0.048,0.027,0.036,0.089,0.17,0.45, 0.34, 0.45],\ [0.062,0.024,0.032,0.048,0.096, 0.11,0.18,0.25],\ [0.042,0.018,0.035,0.073,0.180, 0.20,0.34,0.45],\ [0.045,0.019,0.033,0.072,0.15, 0.17,0.45,0.25],\ [0.040,0.022,0.033,0.055,0.13, 0.22,0.17,0.45],\ [0.061,0.020,0.035,0.055,0.099, 0.14,0.22,0.25],\ [0.044,0.022,0.044,0.11, 0.16, 0.34, 0.28,0.76],\ [0.048,0.025,0.058,0.13, 0.24, 0.34, 0.45],\ [0.084,0.058,0.11 ,0.24, 0.20, 0.28, 0.28,0.76]] rho_ner_d2=[[0.07,0.023,0.035,0.070,0.25,0.25 , 0.37, 0.30],\ [0.043,0.026,0.033,0.074,0.16,0.37, 0.30, 0.37],\ [0.054,0.023,0.030,0.043,0.079,0.086,0.17,0.22],\ [0.038,0.017,0.032,0.062,0.17,0.19, 0.30, 0.37],\ [0.041,0.019,0.031,0.062,0.11,0.16, 0.37, 0.22],\ [0.037,0.021,0.031,0.049,0.098,0.20,0.16, 0.37],\ [0.054,0.019,0.032,0.049,0.081,0.11,0.20, 0.22],\ [0.040,0.021,0.040,0.085,0.15, 0.30, 0.25,0.52],\ [0.043,0.024,0.051,0.10, 0.15, 0.30, 0.37],\ [0.070,0.051,0.087,0.16,0.19, 0.25, 0.25, 0.52]] #print xrecon #print yrecon #sys.exit() z_new = True Replot = False loglike = 0. loglike_nov = 0. lmin3 = [19.2, 19.8, 20.5, 20.8, 21.6, 22.2, 22.5, 23., 22.9, 23.] lmin3 = [19.7, 20.3, 21., 21.3, 22.1, 22.7, 23., 23.5, 23.4, 23.5] lmin3 = [20.2, 20.8, 21.5, 21.8, 22.6, 23.2, 23.5, 24., 23.9, 24.] lmin3 = [20.7, 21.3, 22., 22.3, 23.1, 23.7, 24., 24.5, 24.4, 24.5] lmin3 = [21.7, 22.3, 23., 23.3, 24.1, 24.7, 25., 25.5, 25.4, 25.5] lmin3 = [21.2, 21.8, 22.5, 22.8, 23.6, 24.2, 24.5, 25., 24.9, 25.] sm = [ 0.05162624, 0.0651364, 0.17144366, 0.19570955, 0.73934002, 1.58958387 ] sm = [ 0.16325651, 0.20597938, 0.54215247, 0.61888793, 2.33799844, 5.02670556 ] sm = [ 0.51626243, 0.651364, 1.71443663, 1.95709547, 7.39340024, 15.89583871 ] sm = [ 1.63256513, 2.05979383, 5.42152466, 6.18887928, 23.37998442, 50.26705564 ] sm = [ 16.32565134, 20.5979383, 54.21524659, 61.88879277, 233.79984425, 502.67055637 ] sm = [5.16, 6.51, 17.14, 19.57, 73.93, 158.95, 206.55] if not z_new: z = [0.1, 0.4, 0.6, 0.8, 1.0, 1.3, 1.6, 2.0, 2.5, 3.2, 4.0] else: z = [0.1, 0.4, 0.6, 0.8, 1.0, 1.3, 1.6, 2.0, 2.5, 3.2, 4.0] #oldest ;) num = int(num) #num = 1. print num z_min, z_max, z_m = get_z(num, z_new=False) dl = get_dl(z_m) Vmax = get_Vmax(z_min, z_max) dsdl = get_dsdl(z_m, dl) #z_m = (z_min + z_max)/2 dl = get_dl(z_m) print z_min, z_max print expt.kind area = SURVEY_AREA * sqDeg2sr area1 = SURVEY_AREA * sqDeg2sr print SURVEY_AREA SMIN = get_sbins(numpy.power(10, Lmin), z_m, dl) * 1e6 SMAX = get_sbins(numpy.power(10, Lmax), z_m, dl) * 1e6 sigma, fsigma = numpy.log10( get_Lbins([SURVEY_NOISE, SURVEY_NOISE * 5], z_m, dl, 'muJy') * (1.4 / 3)**(-.7)) print z_m, dl, sigma, fsigma print SURVEY_NOISE, SURVEY_NOISE * 5, SURVEY_AREA #area = 6672*sqDeg2sr #143165.15 49996.49 59876.8861135 sbin3 = get_sbins(10**bins2, z_m, dl) * 1e6 sbin4 = get_sbins(10**bins3, z_m, dl) * 1e6 #L_s = numpy.log10(get_Lbins(ssbin,z_m,dl,'muJy')) #print expt.binsMedian #sys.exit() xreco = get_Lbins(xrecon, z_m, dl, 'muJy') #*(1.4/3)**(-.7) yreco = yrecon print SMIN, SMAX #sys.exit() lin_yrecon = numpy.log10(yreco) lin_xrecon = numpy.log10(xreco) bins2 = numpy.arange(15., 25., 0.4) bins = numpy.arange(fsigma - 0.2, 29.2, 0.4) #bin +0.2 #bins =[23.6,23.9,24.1,24.3,24.9,25.6,26.,26.7,28] #2< z<3.2 #bins =[23.6, 23.9,24.1,24.4,24.6,24.9,25.2,25.6,26.,26.4,27.,27.5,28] #3.2< z<4 bins = numpy.array(bins) if not os.path.isfile( 'cos_data/cos_s%s_LF.el' % num) and z_new or not os.path.isfile( 'cos_data/cos_s%s_LF_old.el' % num) and not z_new or Replot: print 'Reploting the RLF and storing them for next time.' #l,z_l = open_anytype('cos_data/cosmos_d1_0_8arc.txt',(12,21), F='uJy',L=True,getz=True) #l2,z_l2 = open_anytype('cos_data/cosmos_d1_0_8arc.txt',(12,24), F='uJy',L=True,getz=True) if z_new: L, z_L = open_anytype('cos_data/cos_s%s.txt' % num, (2, 3), F='uJy', L=True, getz=True, band='S') print 'this is the new z bins (please check if lumfuncUtils and cos_manifest are using the right z)' else: L, z_L = open_anytype('cos_data/cos_s%s.txt' % num, (2, 3), F='uJy', L=True, getz=True, band='S') print 'this is the old z binning style. (please check if lumfuncUtils and cos_manifest are using the right z)' L_c, z_c = open_anytype('cosmos_counter_parts_II.txt', (3, 4), [z_min, z_max], F='uJy', L=True, getz=True, band='S') L_c2, z_c2 = open_anytype('cosmos_comp_vla.el', (2, 3), [z_min, z_max], F='uJy', L=True, getz=True, band='S') L_c3, z_c3 = open_anytype('cosmos_vla.el', (2, 3), [z_min, z_max], F='uJy', L=True, getz=True, band='S') L_c4, z_c4 = open_anytype( '/home/eliab/Documents/OC/Project/cosmos/Cosmos/dr4_cos2015_vla.tx', (-4, -1), [z_min, z_max], F='uJy', L=True, getz=True, band='S') L_c5, z_c5 = open_anytype( '/home/eliab/Documents/OC/Project/cosmos/Cosmos/dr4_cos2015_vla.tx', (3, -1), [z_min, z_max], F='uJy', L=True, getz=True, band='S') #z_c2,S_c2,L_c2 =numpy.loadtxt('cosmos_counter_parts_II.txt',unpack=True, usecols=(3,4,5)) #L_c2=L_c2[(z_c2<z_max)&(z_c2 >z_min)] #S_c2=S_c2[(z_c2<z_max)&(z_c2 >z_min)] #z_c2=z_c2[(z_c2<z_max)&(z_c2 >z_min)] #rho_1,er1 = calc_Vmax(calcu_zeff(z_l,l,11.5e-32),l,bins,z_max,z_min,area) #rho_2,er2 = calc_Vmax(calcu_zeff(z_l2,l2,11.5e-32),l2,bins,z_max,z_min,area) #print numpy.log10(L) #print (1.4/3)**(-.7) #print numpy.log10(L*(1.4/3)**(-.7)) #sys.exit() rho_3, er3, b3, n3 = calc_Vmax(calcu_zeff(z_L, L, 1.15e-31), L, bins, z_max, z_min, area, table=True) #rho_4,er4 = calc_Vmax(99.,L,bins,z_max,z_min,area) print 'COS15 VLA' rho_5, er5, b5, n5 = calc_Vmax(calcu_zeff(z_c, L_c, 1.15e-31), L_c, bins, z_max, z_min, 1.77 * sqDeg2sr, table=True) print 'mass lim DR4-vla' rho_6, er6, b6, n6 = calc_Vmax(calcu_zeff(z_c2, L_c2, 1.15e-31), L_c2, bins, z_max, z_min, 1.5 * sqDeg2sr, table=True) print 'DR4-vla' rho_7, er7, b7, n7 = calc_Vmax(calcu_zeff(z_c3, L_c3, 1.15e-31), L_c3, bins, z_max, z_min, 1.5 * sqDeg2sr, table=True) print 'cos-DR4-vla DR4 photo-z' rho_8, er8, b8, n8 = calc_Vmax(calcu_zeff(z_c4, L_c4, 1.15e-31), L_c4, bins, z_max, z_min, 1.5 * sqDeg2sr, table=True) print 'cos-DR4-vla COS15 photo-z' rho_9, er9, b9, n9 = calc_Vmax(calcu_zeff(z_c5, L_c5, 1.15e-31), L_c5, bins, z_max, z_min, 1.5 * sqDeg2sr, table=True) for i in range(len(b3)): print '%5.2f %7d %10d %13d %17d %11d' % (b3[i], n3[i], n7[i], n8[i], n9[i], n5[i]) if z_new: f = open('cos_data/cos_s%s_LF_5.el' % num, 'w') #_2 paper _5 stellar mass 10.2 print 'saving data for future use in cos_data/cos_s%s_LF_5.el' % num else: f = open('cos_data/cos_s%s_LF_old.el' % num, 'w') print 'saving data for future use in cos_data/cos_s%s_LF_old.el' % num for i in range(len(bins)): f.write( '%5.1f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f\n' % (bins[i], rho_3[i], er3[i], rho_5[i], er5[i], rho_6[i], er6[i], rho_7[i], er7[i], rho_8[i], er8[i], rho_9[i], er9[i])) f.close() else: if z_new: bins, rho_3, er3, rho_5, er5, rho_6, er6, rho_7, er7, rho_8, er8, rho_9, er9 = numpy.loadtxt( 'cos_data/cos_s%s_LF_2.el' % num, unpack=True) print 'Using stored RLF for the new z (The one with more z bins ) from cos_data/cos_s%s_LF.el. If you want to calculate the plot the set "Replot=True"' % num else: bins, rho_3, er3, rho_5, er5, rho_6, er6, rho_7, er7, rho_8, er8, rho_9, er9 = numpy.loadtxt( 'cos_data/cos_s%s_LF_old.el' % num, unpack=True) print 'Using stored RLF for the is old z bins in fr cos_data/cos_s%s_LF.el. If you want to calculate the plot the set "Replot=True"' % num #novak 2017 ''' L_n =[21.77,22.15,22.46,22.77,23.09,23.34] rho_n =[-2.85,-2.88,-3.12,-3.55,-4.05,-4.63] L_ner_u =[0.23,0.18,0.19, 0.2, 0.21, 0.28] L_ner_d =[1.1, 0.15, 0.14, 0.12, 0.12, 0.048] rho_ner=[0.09, 0.03,0.0355,0.059,0.1,0.234] #novak 2018 L_n2 =[21.77,22.24,22.68,23.16,23.69,24.34, 24.74,25.56] rho_n2 =[-2.84,-2.90,-3.34,-4.00,-4.92,-4.92, -5.22,-5.07] L_ner_u2 =[0.23,0.27, 0.34, 0.37, 0.35, 0.21, 0.31, 0.03] L_ner_d2 =[1.0, 0.24, 0.17, 0.14, 0.16, 0.30, 0.20, 0.50] rho_ner_u2=[0.08,0.024,0.038,0.083,0.28,0.28 , 0.45, 0.34] rho_ner_d2=[0.07,0.023,0.035,0.070,0.25,0.25 , 0.37, 0.30] #l*= (1.4/3)**(-.7) #l2*= (1.4/3)**(-.7) #L*= (1.4/3)**(-.7) ''' #Lbins2 = numpy.log10(lf.get_Lbins(sbin2[sbin2>0],z_m,dl)) print z_min, z_max #bins = numpy.arange(fsigma -4.2,30,0.4) #bin #s,s_z = numpy.loadtxt('sdss/dr12s_s1_vol.txt', unpack=True, usecols=(-1,2)) s, s_z = numpy.loadtxt('cos_data/cos_s%s.txt' % (num), unpack=True, usecols=(-1, 2)) #s=s*1e6 print fsigma L_s = (get_Lbins(ssbin, z_m, dl, 'muJy')) * (1.4 / 3.)**(-.7) L_s = numpy.log10(L_s) rho_1 = lumfuncs( Nbin, L_s, calc_Vmax(calcu_zeff(z_m, 10**L_s), L_s, L_s, z_max, z_min, area, getLF=False)) #L_s = numpy.log10(10**L_s*(1.4/3.)**(-.7)) #sys.exit() rho_11 = dntoLF(L_s, Nbin, dsdl, Vmax) #dn = expt.realise(params) #nov_real=expt.realise([2.3,2.95,2.86,-0.29,-0.7,19.5,26.0]) fig, ax = plt.subplots() plt.rc('lines', linewidth=2) if modelFamily in ['LFdpl', 'LFdpl_dpl', 'LFdpl_dpl_z']: faint = lumfuncUtils.doublepowerlaw(numpy.power(10, bins3), Lstar_2, Lslope_2, Lslope2_2, Lnorm_2) elif modelFamily in ['LFpl', 'LFdpl_pl']: faint = lumfuncUtils.powerlaw(numpy.power(10, bins3), Lstar_2, Lslope_2, Lnorm_2) elif modelFamily in ['LFpl_dpl', 'LFdpl_dpl_z']: faint = lumfuncUtils.doublepowerlaw(numpy.power(10, bins3), Lstar, Lslope, Lslope2, Lnorm) elif modelFamily == 'LFevol_logn_mat': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_logn_mat',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_phi_logn_mat': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_phi_logn_mat',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_logn_el': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_logn_el',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_phi_logn': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_phi_logn',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_logn': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_logn',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_logn_slope': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_logn_slope',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_logn_sigma': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_logn_sigma',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_logn_lstar': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_logn_lstar',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_logn_lmin': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_logn_lmin',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_logn_lnorm': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_logn_lnorm',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_logn_all': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_logn_all',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] elif modelFamily == 'LFevol_logn_all_L': faint =[lumfuncUtils.LF(L=numpy.power(10,lL),params=params,paramsList=expt.parameters,\ family='LFevol_logn_all_L',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True,SF=True) for lL in bins3] else: faint = lumfuncUtils.lognormpl(numpy.power(10, bins3), Lstar_2, Lslope_2, Lsigma, Lnorm_2) #phi_dpl =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3),Lstar ,Lslope,Lslope2,Lnorm) L_1 = numpy.power(10, bins3) / (1 + z_m)**(2.86 - z_m * 0.7) L_2 = numpy.power(10, bins3) / (1 + z_m)**(2.95 - z_m * 0.29) #L_4 = numpy.power(10,bins3)/(1 + z_m)**(alpha_SF) #L_3 = numpy.power(10,bins3)/(1 + z_m)**(alpha_agn) #L_4 = numpy.power(10,bins3)/(10)**(alpha_SF) #L_3 = numpy.power(10,bins3)/(10)**(1)#alpha_agn) #for i in range(len(L_3)): #print bins3[i],numpy.log10(L_3[i]) #L_4 = numpy.power(10,bins3)/(1 + z_m)**(alpha_SF+z_m*beta_SF) #L_3 = numpy.power(10,bins3)/(1 + z_m)**(alpha_agn+z_m*beta_agn) phi_agn_n = lumfuncUtils.doublepowerlaw(L_1, 24.59, 1.27, 0.49, numpy.log10(10**(-5.5))) phi_sf_n = lumfuncUtils.lognormpl(L_2, numpy.log10(1.85e21), 1.22, 0.63, numpy.log10(3.55e-3 / 2.5)) #0.33 2.97 #phi_sf =lumfuncUtils.lognormpl(L_4, 20.56,1.22,0.63,-2.26)#numpy.log10(3.55e-3/2.5))#0.33 2.97 phi_sf2 = lumfuncUtils.lognormpl(L_2, numpy.log10(1.85e21), 1.22, 0.63, numpy.log10(3.55e-3 / 2.5)) #0.33 2.97 #phi_sf =lumfuncUtils.lognormpl(L_4, Lstar,1.22,0.63,Lnorm)#numpy.log10(3.55e-3/2.5))#0.33 2.97 #phi_sf =lumfuncUtils.lognormpl(L_4, numpy.log10(1.85e21),1.22,0.63,numpy.log10(3.55e-3/2.5))#0.33 2.97 nov_Tot_n = phi_agn_n + phi_sf_n #phi_agn=lumfuncUtils.doublepowerlaw(L_3,24.59,1.27,0.49,numpy.log10(10**(-5.5))) #print 'this is Lminz', numpy.log10(10**18/(1 + z_m)**(alpha_SF+z_m*beta_SF)) #phi_agn=lumfuncUtils.doublepowerlaw(L_3,24.59,1.27,0.49,numpy.log10(10**(-5.5))) phi_1 = lumfuncUtils.doublepowerlaw(numpy.power(10, bins3), 23.68, 3.68, 0.8, -3.36) #0.33 2.97 phi_2 = lumfuncUtils.doublepowerlaw(numpy.power(10, bins3), 24.5, 1.37, 0.5, -4.) #tot = phi_1+phi_2 dm = 0.4 #02 hm = 0. #Map =expt.evaluate(params)[0] bins_map = get_Lbins(expt.binsMedian, z_m, dl, 'muJy') bins1_4 = numpy.log10(10**bins * (1.4 / 3.)**(-.7)) #fix=[lumfuncUtils.LF(L=numpy.power(10,lL),params=[3.75,2.55,4.74,0,0,20.3,26.65],paramsList=expt.parameters,\ # family='LFevol_logn',inta=None,area=0,S=0, z=z_m, dlds=0,Vmax=0,dl=0,bypassLim=True) for lL in bins3] #plt.plot(numpy.log10(10**bins3 *(1.4/3)**(-.7)),numpy.log10(faint)-dm,'--b' ,label='faint-end') #plt.plot(numpy.log10(bins_map),numpy.log10(Map), label='my MAP') #plt.plot(bins3,numpy.log10(fix)-dm,'--c', label='Fix') #plt.plot(bins3,numpy.log10(phi_agn),'-.c', label='local agn') #plt.plot(bins3,numpy.log10(phi_sf),'--r', label='local sf') #plt.plot(bins3,numpy.log10(phi_sf2),'--c', label='local sf2') #plt.plot(numpy.log10(10**bins3),numpy.log10(phi_dpl)-dm,'--c', label='agn') #plt.plot(numpy.log10(10**bins3*(1.4/3.)**(.7)),numpy.log10(tot)-0.4,'-.g',linewidth=5, label='Tot') #plt.plot(bins3,numpy.log10(phi_agn),'--r', label='local agn nov') plt.errorbar(lin_xrecon + hm, lin_yrecon - dm, fmt='-b', label='This work Total', linewidth=2) plt.plot(numpy.log10(10**bins3), numpy.log10(faint) - dm, '--b', label='This work SFG') #plt.errorbar(lin_xrecon+hm,numpy.log10(yrecon_avr)-dm,fmt='-g', label = 'Average') #plt.plot(L_s2+.2, numpy.log10(rho_10), '*c',label='average LF',markersize=13)#bin + 0.2 plt.errorbar(bins, rho_3, yerr=er3, fmt='ob', label='This work 1/Vmax', markersize=8) #bin #plt.errorbar(bins2[17:],rho_3[17:] ,yerr=er3[17:],fmt='ob',label='extracted',markersize=8) #bin #plt.errorbar(bins,rho_5 ,yerr=er5,fmt='^k',label='VLA-COSMOS2015',markersize=10) #bin #plt.errorbar(bins,rho_8 ,yerr=er8,fmt='sc',label='VLA-COSMOS2015 in DR4 using DR4 z',markersize=10) #bin #plt.errorbar(bins,rho_9 ,yerr=er9,fmt='*m',label='VLA-COSMOS2015 in DR4 using COS15z',markersize=14) #bin #plt.errorbar(bins,rho_6 ,yerr=er6,fmt='ok',label='DR4 detected',fillstyle='none',markersize=14) #bin #plt.errorbar(bins,rho_7 ,yerr=er6,fmt='dg',label='DR4 detected - Full NIR sample',markersize=12) #bin #plt.plot(L_s, numpy.log10(rho_1), '*m',label='low LF',markersize=10) #plt.plot(L_s, numpy.log10(rho_11), 'sc',label='reconstruct LF',markersize=10) #plt.errorbar(numpy.array(L_n2[num-1]),numpy.array(rho_n2[num-1]) -0.4,xerr=[L_ner_d2[num-1],L_ner_u2[num-1]],yerr=[rho_ner_d2[num-1],rho_ner_u2[num-1]], fmt='sr',fillstyle='none',ecolor='r',markeredgewidth=1.5, label='Total RLF Novak+2018') plt.errorbar(numpy.log10(10**bins3), numpy.log10(nov_Tot_n), fmt='-r', label='Total Novak + 2018') plt.plot(bins3, numpy.log10(phi_sf_n), '-.r', label='SFG Novak + 2017') ''' print 'This is the dn' print dn for key in dn.keys(): if round(key,2)==round(z_m,2):z_m=key dn=dn[z_m] nov_real=nov_real[z_m] for i in range(len(L_s)): loglike_i= Nbin[i]*numpy.log(dn[i]) + Nbin[i] - (Nbin[i] + 0.5)*numpy.log(Nbin[i]) - 0.5*numpy.log(2*numpy.pi) - dn[i] loglike_nov_i= Nbin[i]*numpy.log(nov_real[i]) + Nbin[i] - (Nbin[i] + 0.5)*numpy.log(Nbin[i]) - 0.5*numpy.log(2*numpy.pi) - nov_real[i] if nov_real[i]>0:loglike_nov+=loglike_nov_i if dn[i]>0:loglike+=loglike_i print '%10.5f %8.2d %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f'%(ssbin[i], Nbin[i], dn[i],nov_real[i],loglike_i,loglike_nov_i,loglike, loglike_nov) ''' #plt.errorbar(bins[1:],rho_2[1:] ,yerr=er2[1:],fmt='ok',label='dectected catalog',markersize=10) #bin #plt.errorbar(bins2[1:]-0.2,rho_3[1:],yerr=er3[1:],fmt='sr',label='noisy',markersize=10) #bin #plt.errorbar(bins2[1:]-0.2,rho_4[1:],yerr=er4[1:],fmt='vm',label='noisy lim',markersize=10) #bin #plt.errorbar(numpy.array(L_n),numpy.array(rho_n) -0.4,xerr=[L_ner_d,L_ner_u],yerr=rho_ner, fmt='^c', label='Novak et al 2017') #plt.errorbar(numpy.array(L_n2),numpy.array(rho_n2) -0.4,xerr=[L_ner_d2,L_ner_u2],yerr=[rho_ner_d2,rho_ner_u2], fmt='sk', label='Total RLF Novak et al 2018') #plt.plot(bins3+0.4,numpy.log10(logn)-0.4 ,'--k', label='faint-end') #plt.plot(bins3,numpy.log10(logn) ,'--', label='lognorm') #plt.plot(bins3,numpy.log10(logn2)-dm,'--r', label='lognorm2') # #plt.plot(bins3,numpy.log10(phi_dpl2), label='dpl bright-end2') #plt.plot(Lbins4[(Lbins4<23.6) &(Lbins4>22.12)],numpy.log10(phi_dpl)[(Lbins4<23.6) &(Lbins4>22.12)], '-c',linewidth=5 ,label = r'$\rm{ MAP dpl < 5\sigma}$') #plt.plot(bins2,numpy.log10(logn_2),label='starforming_2') #plt.plot(bins2,numpy.log10(logn_3),label='starforming_3') #plt.plot(bins2,numpy.log10(logn_4),label='starforming_4') #plt.fill_between(xrecon,numpy.log10(yrecon - yrecon_down2 ) ,numpy.log10(yrecon+yrecon_up2), color='c',alpha=0.2) #plt.errorbar(lin_xrecon+0.4,lin_yrecon -0.4,fmt='-b', label='MAP',linewidth=2) #plt.errorbar(lin_xrecon+0.4,lin_yrecon- 0.4,yerr=numpy.log10(yrecon_rms),fmt='r',label='rms') #plt.plot(L_s, numpy.log10(rho_1), '*c',label='average LF',markersize=10) #plt.plot(L_s5, numpy.log10(rho_14)-0.2, '*r',label='average LF',markersize=13) #plt.plot(L_s6+0.0, numpy.log10(rho_16)-0.2, '*b',label='average LF(bin)',markersize=13) #plt.plot(bins2[:-1], numpy.log10(rho_15), '*g',label='LF average',markersize=13) #print len(rho_11),len(rho_10),len(rho_12) #plt.fill_betweenx(numpy.log10(rho_10) ,L_s3,L_s4, color='red',alpha=0.2) #plt.plot(L_s6, numpy.log10(rho_13), '*b',label='average LF(bin+0.2)',markersize=13)#bin + 0.2 #plt.plot(L_s1, numpy.log10(rho_1), 'oc',label='average LF(bin)',markersize=13)#bin #plt.plot(Lbins4,lin_phi ,'--b',label='MAP') #plt.fill_between(lin_xrecon+.0,numpy.log10((yrecon_avr -yrecon_rms))-dm,numpy.log10(yrecon_avr +yrecon_rms)-dm , color='r',alpha=0.3) #plt.fill_between(lin_xrecon[1:-1]+0.2,numpy.log10(yreco[1:-1] - yrecon_down[1:-1] )-dm,numpy.log10(yreco[1:-1]+yrecon_up[1:-1])-dm , color='b',alpha=0.2) plt.fill_between(lin_xrecon + hm, numpy.log10((yrecon_d)) - dm, numpy.log10(yrecon_u) - dm, color='k', alpha=0.2) #plt.errorbar(bins[2:],rho_1[2:],yerr=er1[2:],fmt = 'ob',label='Detected') #plt.errorbar(bins2,rho_6-0.2,yerr=er6,fmt='ob',label='Detected') #working one #plt.plot(Lbins2,rho,'ob',label='simulation') #plt.plot(Lbins3,rho_,label='Noisy fluxes') #rho_2 #plt.errorbar(bins,rho_2 -0.2,yerr=er2,fmt='ok',label='data',markersize=10) #bin +0.2 #plt.errorbar(bins2,rho_6-0.2,yerr=er6,fmt='vm',label='Noisy NVSS') #plt.errorbar(bins2,rho_7-0.2,yerr=er6,fmt='xc',label='NVSS Detected') #for i in range(len(bins)): # print bins[i], rho_2[i] #sys.exit() #plt.errorbar(Lbins2,rho, err,fmt = 'ob',label='simulation') #plt.errorbar(Lbins2,rho_1,err_1,fmt = 'or',label='simulation_noisy') #plt.errorbar(L2,rho2,color='g',label='Analytic') #plt.errorbar(L3,rho3,color='g',label='Analytic II') #plt.axvspan(22.55 ,23.51,color='r',alpha=0.2) #plt.axvline(Lmin,color='r',linestyle='dashed') plt.axvline(fsigma, color='k', linestyle='dashed') #plt.axvline(sigma,color='g') #plt.axvline(Llmin,color='r',linewidth=5) #plt.axvline(sigma2,color='m') #plt.axvline(fsigma2,color='m') #plt.axvline(23.89,color='b') #plt.axvline(23.71,color='c') #plt.axvline(23.52,color='r') #plt.axvline(truth['LMIN'],color='r', linestyle='dashed', label = 'True params') #plt.axvline(truth['LMAX'],color='r', linestyle='dashed') #plt.axvline(truth['LSTAR'],color='b') #plt.text(truth['LSTAR']-0.2,-9., '$L_*$',fontsize=18) #plt.axvline(Lmax,color='r', label= 'MAP params') #plt.axvline(Lmin,color='b') #plt.axvline(Lmax, color='r',linestyle='dashed') #plt.text(21,-1, '$L_*$',fontsize=18) #plt.text(fsigma+0.1,-6.7, '$5\sigma$',fontsize=25) #plt.text(sigma+0.1,-6.7, '$\sigma$',fontsize=25) plt.xlabel(r'$\rm{log_{10}[L_{1.4 GHz}/(W}$ $\rm{Hz^{-1})]}$', fontsize=30) plt.ylabel(r'$\rm{log_{10}[\rho_m(Mpc^{-3} mag^{-1})]}$', fontsize=30) lmin3_14 = 10**lmin3[num - 1] * (1.4 / 3.)**(-.7) #plt.text(22,-7.7,'%.1f < z < %.1f %s Lmin=%6.2f %s Lmin_cut=%6.2f %s Smin_cut=%6.2f $\mu$Jy'%(z_min,z_max,'\n',Lmin,'\n',numpy.log10(lmin3_14),'\n',sm[num-1]),fontsize = 30,alpha=0.6 ) # \n $M_i$ < -22 #plt.text(22,-7.7,'%.1f < z < %.1f %s Lmin=%6.2f'%(z_min,z_max,'\n',Lmin),fontsize = 30,alpha=0.6 ) # \n $M_i$ < -22 plt.text(22, -7.7, '%.1f < z < %.1f' % (z_min, z_max), fontsize=30, alpha=0.6) # \n $M_i$ < -22 #plt.text(22.9,-8.7,'%s'%outdir,fontsize = 16 ) # \n $M_i$ < -22 plt.tick_params(axis='both', which='major', labelsize=20, width=3) plt.tick_params(axis='both', which='minor', labelsize=10, width=2) #plt.tight_layout() #plt.xtick(fontsize=15) #plt.ytick(fontsize=15) plt.xlim(20, 28.) plt.ylim(-9, -2) #plt.ylim(-11,-5.5) ax.xaxis.set_minor_locator(AutoMinorLocator()) ax.yaxis.set_minor_locator(AutoMinorLocator()) #print truth['LMIN'] plt.legend(frameon=False).draggable() plotf = '%s/LF_recon_s1.pdf' % (outdir) plt.show() return 0
def main(): """ """ print 'Settings file is %s' % setf # Import the settings variables set_module = importlib.import_module(setf) globals().update(set_module.__dict__) expt = countModel(modelFamily, nlaws, setf, [dataset], floatNoise, doRedshiftSlices=True) recon_expt = countModel(modelFamily, nlaws, setf, [dataset], floatNoise) #print expt.data #print expt.bins # Get MAP parameters print '\n' * 5 print len(expt.parameters) ncols = len(expt.parameters) summf = os.path.join(outdir, '1-summary.txt') summary = numpy.genfromtxt(summf)[-1, :] drawmap = summary[-(ncols + 2):-2] ana=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join(outdir,outstem)) drawmap = ana.get_best_fit()['parameters'] chains = ['a', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] if dataset == 'sdss': print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf) == 20: num = dataf[-5] print num else: num = dataf[-6:-4] d = numpy.genfromtxt('%s/%s' % (outdir, datafiles[0][4:])) print datafiles[0][4:] elif dataset == 'cosmos': #print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf) == 24: num = dataf[-5] print num else: num = dataf[-6:-4] d = numpy.genfromtxt('%s/%s' % (outdir, datafiles[0][8:])) #print '%s%s'%(outdir,datafiles[0][8:]) print datafiles[0][8:] elif 'sim' in dataset: d = numpy.genfromtxt(os.path.join(outdir, 'sim.txt')) ssbin = d[:, 2] Nbin = d[:, 3] dnds = d[:, 4] sbin2 = ssbin dnds2 = dnds #bins2 = numpy.arange(21.4,29.2,0.4) bins2 = numpy.arange(18.0, 29.2, 0.4) bins3 = numpy.arange(18., 29.2, 0.01) print len(expt.parameters) num = 5 print 'this is 1st num ', num #sys.exit() params = drawmap # [0] #for i in drawmap: # params.append(i) print params print expt.parameters if modelFamily in [ 'LFsch', 'LFdpl_pl', 'LFpl_dpl', 'LFdpl_dpl', 'LFdpl_dpl_z', 'LFlognorm_dpl', 'LFpl_lognorm' ]: Lnorm = params[expt.parameters.index('LNORM')] Lstar = params[expt.parameters.index('LSTAR')] Lslope = params[expt.parameters.index('LSLOPE')] #Lzevol=params[expt.parameters.index('LZEVOL')] if modelFamily in [ 'LFdpl_pl', 'LFpl_dpl', 'LFdpl_dpl', 'LFdpl_dpl_z', 'LFlognorm_dpl' ]: Lslope2 = params[expt.parameters.index('LSLOPE2')] if modelFamily in [ 'LFlognorm', 'LFpl', 'LFdpl', 'LFdpl_pl', 'LFpl_dpl', 'LFlognorm_dpl', 'LFdpl_dpl', 'LFdpl_dpl_z', 'LFpl_lognorm' ]: Lnorm_2 = params[expt.parameters.index('LNORM_2')] Lstar_2 = params[expt.parameters.index('LSTAR_2')] Lslope_2 = params[expt.parameters.index('LSLOPE_2')] if modelFamily in ['LFdpl_dpl', 'LFdpl_dpl_z', 'LFdpl']: Lslope2_2 = params[expt.parameters.index('LSLOPE2_2')] if modelFamily in ['LFlognorm', 'LFlognorm_dpl', 'LFpl_lognorm']: Lsigma = params[expt.parameters.index('LSIGMA')] if modelFamily in ['LFdpl_dpl_z', 'LFevol']: alpha_agn = params[expt.parameters.index('A_agn')] alpha_SF = params[expt.parameters.index('A_SF')] beta_agn = params[expt.parameters.index('B_agn')] beta_SF = params[expt.parameters.index('B_SF')] if modelFamily in ['LFevol_dpl_s', 'LFevol_logn_s']: alpha_SF = params[expt.parameters.index('A_SF')] beta_SF = params[expt.parameters.index('B_SF')] Lmin = params[expt.parameters.index('LMIN')] Lmax = params[expt.parameters.index('LMAX')] truth = { 'noise': 150, 'LMIN': 22., 'LMAX': 24.5, 'LNORM': numpy.log10(1e-7), 'LSTAR': 23.3, 'LSLOPE': 3., 'LSLOPE2': 1. } #z = [0, 0.5, 1 , 1.5, 2, 2.3, 2.6, 3, 3.5, 4] #old #z = [ 0.7, 1 , 1.35, 1.7, 2, 2.3, 2.6, 3, 3.5, 4]# older print expt.parameters s = pylab.loadtxt('%s/recon_stats_%s.txt' % (outdir, chains[num - 1])) xrecon = s[:-1, 0] yrecon = s[:-1, 1] yrecon_d = s[:-1, 2] yrecon_u = s[:-1, 3] yrecon_rms = s[:-1, 4] yrecon_avr = s[:-1, 5] yrecon_rms_down = yrecon_rms for i in range(len(yrecon_rms)): if yrecon_avr[i] < yrecon_rms[i]: yrecon_rms_down[i] = 10**(numpy.log10(yrecon_avr[i]) - 0.01) #print xrecon #print yrecon #sys.exit() z_new = False Replot = False if z_new: z = [ 0.1, 0.3, 0.4, 0.6, 0.8, 1.0, 1.3, 1.6, 1.9, 2.2, 2.5, 2.8, 3.2, 3.6, 4.0 ] else: z = [0.1, 0.4, 0.6, 0.8, 1.0, 1.3, 1.6, 2.0, 2.5, 3.2, 4.0] #oldest ;) num = int(num) #num = 1. print num z_min, z_max, z_m = get_z(num, z_new=z_new) dl = get_dl(z_m) Vmax = get_Vmax(z_min, z_max) dsdl = get_dsdl(z_m, dl) z_m = (z_min + z_max) / 2 dl = get_dl(z_m) print z_min, z_max print expt.kind area = SURVEY_AREA * sqDeg2sr area1 = SURVEY_AREA * sqDeg2sr print SURVEY_AREA SMIN = get_sbins(numpy.power(10, Lmin), z_m, dl) * 1e6 SMAX = get_sbins(numpy.power(10, Lmax), z_m, dl) * 1e6 sigma, fsigma = numpy.log10( get_Lbins([SURVEY_NOISE, SURVEY_NOISE * 5], z_m, dl, 'muJy') * (1.4 / 3)**(-.7)) print z_m, dl, sigma, fsigma print SURVEY_NOISE, SURVEY_NOISE * 5, SURVEY_AREA #area = 6672*sqDeg2sr #143165.15 49996.49 59876.8861135 sbin3 = get_sbins(10**bins2, z_m, dl) * 1e6 sbin4 = get_sbins(10**bins3, z_m, dl) * 1e6 #L_s = numpy.log10(get_Lbins(ssbin,z_m,dl,'muJy')) #print expt.binsMedian #sys.exit() xreco = get_Lbins(xrecon, z_m, dl, 'muJy') #*(1.4/3)**(-.7) yreco = yrecon print SMIN, SMAX #sys.exit() lin_yrecon = numpy.log10(yreco) lin_xrecon = numpy.log10(xreco) bins2 = numpy.arange(15., 25., 0.4) bins = numpy.arange(fsigma, 26.2, 0.4) #bin +0.2 if not os.path.isfile( 'cos_data/cos_s%s_LF.el' % num) and z_new or not os.path.isfile( 'cos_data/cos_s%s_LF_old.el' % num) and not z_new or Replot: print 'Reploting the RLF and storing them for next time.' #l,z_l = open_anytype('cos_data/cosmos_d1_0_8arc.txt',(12,21), F='uJy',L=True,getz=True) #l2,z_l2 = open_anytype('cos_data/cosmos_d1_0_8arc.txt',(12,24), F='uJy',L=True,getz=True) if z_new: L, z_L = open_anytype('cos_data/cos_s%s.txt' % num, (2, 3), F='uJy', L=True, getz=True, band='S') print 'this is the new z bins (please check if lumfuncUtils and cos_manifest are using the right z)' else: L, z_L = open_anytype('cos_data/cos_s%s_old.txt' % num, (2, 3), F='uJy', L=True, getz=True, band='S') print 'this is the old z binning style. (please check if lumfuncUtils and cos_manifest are using the right z)' L_c, z_c = open_anytype('cosmos_counter_parts_II.txt', (3, 4), [z_min, z_max], F='uJy', L=True, getz=True, band='S') z_c2, S_c2, L_c2 = numpy.loadtxt('cosmos_counter_parts_II.txt', unpack=True, usecols=(3, 4, 5)) L_c2 = L_c2[(z_c2 < z_max) & (z_c2 > z_min)] S_c2 = S_c2[(z_c2 < z_max) & (z_c2 > z_min)] z_c2 = z_c2[(z_c2 < z_max) & (z_c2 > z_min)] #rho_1,er1 = calc_Vmax(calcu_zeff(z_l,l,11.5e-32),l,bins,z_max,z_min,area) #rho_2,er2 = calc_Vmax(calcu_zeff(z_l2,l2,11.5e-32),l2,bins,z_max,z_min,area) #print numpy.log10(L) #print (1.4/3)**(-.7) #print numpy.log10(L*(1.4/3)**(-.7)) #sys.exit() rho_3, er3 = calc_Vmax(calcu_zeff(z_L, L, 1.15e-31), L, bins, z_max, z_min, area) rho_4, er4 = calc_Vmax(99., L, bins, z_max, z_min, area) rho_5, er5 = calc_Vmax(calcu_zeff(z_c, L_c, 1.15e-31), L_c, bins, z_max, z_min, area) rho_6, er6 = calc_Vmax(calcu_zeff(z_c2, 10**L_c2, 1.15e-31), 10**L_c2, bins, z_max, z_min, area) if z_new: f = open('cos_data/cos_s%s_LF.el' % num, 'w') else: f = open('cos_data/cos_s%s_LF_old.el' % num, 'w') for i in range(len(bins)): f.write('%5.1f %5.3f %5.3f %5.3f %5.3f %5.3f %5.3f\n' % (bins[i], rho_3[i], er3[i], rho_5[i], er5[i], rho_6[i], er6[i])) f.close() dl_c = get_dl(z_c2) L_c3 = numpy.log10( get_Lbins(S_c2, z_c2, numpy.array(dl_c), 'muJy') * (1.4 / 3.)**(-.7)) else: if z_new: bins, rho_3, er3, rho_5, er5, rho_6, er6 = numpy.loadtxt( 'cos_data/cos_s%s_LF.el' % num, unpack=True) print 'Using stored RLF for the new z (The one with more z bins). If you want to calculate the plot the set "Replot=True"' else: bins, rho_3, er3, rho_5, er5, rho_6, er6 = numpy.loadtxt( 'cos_data/cos_s%s_LF_old.el' % num, unpack=True) print 'Using stored RLF for the is old z bins. If you want to calculate the plot the set "Replot=True"' #novak 2017 L_n = [21.77, 22.15, 22.46, 22.77, 23.09, 23.34] rho_n = [-2.85, -2.88, -3.12, -3.55, -4.05, -4.63] L_ner_u = [0.23, 0.18, 0.19, 0.2, 0.21, 0.28] L_ner_d = [1.1, 0.15, 0.14, 0.12, 0.12, 0.048] rho_ner = [0.09, 0.03, 0.0355, 0.059, 0.1, 0.234] #novak 2018 L_n2 = [21.77, 22.24, 22.68, 23.16, 23.69, 24.34, 24.74, 25.56] rho_n2 = [-2.84, -2.90, -3.34, -4.00, -4.92, -4.92, -5.22, -5.07] L_ner_u2 = [0.23, 0.27, 0.34, 0.37, 0.35, 0.21, 0.31, 0.03] L_ner_d2 = [1.0, 0.24, 0.17, 0.14, 0.16, 0.30, 0.20, 0.50] rho_ner_u2 = [0.08, 0.024, 0.038, 0.083, 0.28, 0.28, 0.45, 0.34] rho_ner_d2 = [0.07, 0.023, 0.035, 0.070, 0.25, 0.25, 0.37, 0.30] #l*= (1.4/3)**(-.7) #l2*= (1.4/3)**(-.7) #L*= (1.4/3)**(-.7) #Lbins2 = numpy.log10(lf.get_Lbins(sbin2[sbin2>0],z_m,dl)) print z_min, z_max #bins = numpy.arange(fsigma -4.2,30,0.4) #bin #s,s_z = numpy.loadtxt('sdss/dr12s_s1_vol.txt', unpack=True, usecols=(-1,2)) s, s_z = numpy.loadtxt('cos_data/cos_s%s.txt' % (num), unpack=True, usecols=(-1, 2)) #s=s*1e6 print fsigma #sys.exit() Ncount = sum(Nbin[fsigma > ssbin]) Llmin = numpy.log10( get_Lbins([fsigma / numpy.sqrt(Ncount)], z_min, get_dl(z_min), 'muJy'))[0] Llmin *= (1.4 / 3.)**(-.7) print Llmin L_s = (get_Lbins(ssbin, z_m, dl, 'muJy')) L_s *= (1.4 / 3.)**(-.7) L_s = numpy.log10(L_s) rho_1 = lumfuncs( Nbin, L_s, calc_Vmax(calcu_zeff(z_m, 10**L_s), L_s, L_s, z_max, z_min, area, getLF=False)) #sys.exit() fig, ax = plt.subplots() plt.rc('lines', linewidth=2) ''' if modelFamily in ['LFdpl','LFdpl_dpl']: faint =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3), Lstar_2,Lslope_2,Lslope2_2,Lnorm_2) elif modelFamily in ['LFpl','LFdpl_pl']: faint =lumfuncUtils.powerlaw(numpy.power(10,bins3), Lstar_2,Lslope_2,Lnorm_2) elif modelFamily in ['LFpl_dpl','LFdpl_dpl_z']: faint =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3),Lstar,Lslope,Lslope2,Lnorm) else: faint = lumfuncUtils.lognormpl(numpy.power(10,bins3), Lstar_2,Lslope_2,Lsigma,Lnorm_2) ''' #phi_dpl =lumfuncUtils.doublepowerlaw(numpy.power(10,bins3),Lstar ,Lslope,Lslope2,Lnorm) #L_2 = numpy.power(10,bins3)/(1 + z_m)**(alpha_SF+z_m*beta_SF) L_2 = numpy.power( 10, bins3) * (1.4 / 3.)**(-.7) / (1 + z_m)**(2.95 - z_m * 0.29) L_1 = numpy.power( 10, bins3) * (1.4 / 3.)**(-.7) / (1 + z_m)**(2.86 - z_m * 0.7) phi_agn = lumfuncUtils.doublepowerlaw(L_1, 24.29, 1.27, 0.49, numpy.log10(2.5 * 10**(-5.5))) phi_sf = lumfuncUtils.doublepowerlaw(L_2, 22.11, 2.4, 0.43, -3.10) #0.33 2.97 phi_logn = lumfuncUtils.lognormpl(L_2, numpy.log10(1.85e21), 1.22, 0.63, numpy.log10(3.55e-3)) #phi_pl =lumfuncUtils.powerlaw(numpy.power(10,bins3),Lstar ,Lslope,Lnorm) dm = 0. #05 hm = 0. Map = expt.evaluate(params)[0] bins_map = get_Lbins(expt.binsMedian, z_m, dl, 'muJy') #plt.plot(numpy.log10(10**bins3 *(1.4/3)**(-.7)),numpy.log10(faint)-dm,'--b' ,label='faint-end') plt.plot(bins3, numpy.log10(phi_sf) - dm, '--c', label='local sf') plt.plot(bins3, numpy.log10(phi_agn) - dm, '--c', label='local agn') plt.plot(bins3, numpy.log10(phi_logn) - dm, '--r', label='local lognorm') #plt.plot(numpy.log10(bins_map),numpy.log10(Map), label='my MAP') plt.errorbar(lin_xrecon + hm, lin_yrecon - dm, fmt='-k', label='MAP', linewidth=2) plt.errorbar(lin_xrecon + hm, numpy.log10(yrecon_avr) - dm, fmt='-g', label='Average') #plt.plot(L_s2+.2, numpy.log10(rho_10), '*c',label='average LF',markersize=13)#bin + 0.2 plt.errorbar(bins, rho_3, yerr=er3, fmt='ob', label='extracted', markersize=8) #bin #plt.errorbar(bins2[17:],rho_3[17:] ,yerr=er3[17:],fmt='ob',label='extracted',markersize=8) #bin #plt.errorbar(bins,rho_5 ,yerr=er5,fmt='*r',label='Total',markersize=8) #bin #plt.errorbar(bins,rho_6 ,yerr=er6,fmt='>g',label='Total LF',markersize=10) #bin plt.plot(L_s, numpy.log10(rho_1), '*m', label='low LF', markersize=10) #plt.errorbar(bins[1:],rho_2[1:] ,yerr=er2[1:],fmt='ok',label='dectected catalog',markersize=10) #bin #plt.errorbar(bins2[1:]-0.2,rho_3[1:],yerr=er3[1:],fmt='sr',label='noisy',markersize=10) #bin #plt.errorbar(bins2[1:]-0.2,rho_4[1:],yerr=er4[1:],fmt='vm',label='noisy lim',markersize=10) #bin #plt.errorbar(numpy.array(L_n),numpy.array(rho_n) -0.4,xerr=[L_ner_d,L_ner_u],yerr=rho_ner, fmt='^c', label='Novak et al 2017') #plt.errorbar(numpy.array(L_n2),numpy.array(rho_n2) -0.4,xerr=[L_ner_d2,L_ner_u2],yerr=[rho_ner_d2,rho_ner_u2], fmt='sk', label='Total RLF Novak et al 2018') #plt.plot(bins3+0.4,numpy.log10(logn)-0.4 ,'--k', label='faint-end') #plt.plot(bins3,numpy.log10(logn) ,'--', label='lognorm') #plt.plot(bins3,numpy.log10(logn2)-dm,'--r', label='lognorm2') # #plt.plot(bins3,numpy.log10(phi_dpl2), label='dpl bright-end2') #plt.plot(Lbins4[(Lbins4<23.6) &(Lbins4>22.12)],numpy.log10(phi_dpl)[(Lbins4<23.6) &(Lbins4>22.12)], '-c',linewidth=5 ,label = r'$\rm{ MAP dpl < 5\sigma}$') #plt.plot(bins2,numpy.log10(logn_2),label='starforming_2') #plt.plot(bins2,numpy.log10(logn_3),label='starforming_3') #plt.plot(bins2,numpy.log10(logn_4),label='starforming_4') #plt.fill_between(xrecon,numpy.log10(yrecon - yrecon_down2 ) ,numpy.log10(yrecon+yrecon_up2), color='c',alpha=0.2) #plt.errorbar(lin_xrecon+0.4,lin_yrecon -0.4,fmt='-b', label='MAP',linewidth=2) #plt.errorbar(lin_xrecon+0.4,lin_yrecon- 0.4,yerr=numpy.log10(yrecon_rms),fmt='r',label='rms') #plt.plot(L_s, numpy.log10(rho_1), '*c',label='average LF',markersize=10) #plt.plot(L_s5, numpy.log10(rho_14)-0.2, '*r',label='average LF',markersize=13) #plt.plot(L_s6+0.0, numpy.log10(rho_16)-0.2, '*b',label='average LF(bin)',markersize=13) #plt.plot(bins2[:-1], numpy.log10(rho_15), '*g',label='LF average',markersize=13) #print len(rho_11),len(rho_10),len(rho_12) #plt.fill_betweenx(numpy.log10(rho_10) ,L_s3,L_s4, color='red',alpha=0.2) #plt.plot(L_s6, numpy.log10(rho_13), '*b',label='average LF(bin+0.2)',markersize=13)#bin + 0.2 #plt.plot(L_s1, numpy.log10(rho_1), 'oc',label='average LF(bin)',markersize=13)#bin #plt.plot(Lbins4,lin_phi ,'--b',label='MAP') #plt.fill_between(lin_xrecon+.0,numpy.log10((yrecon_avr -yrecon_rms))-dm,numpy.log10(yrecon_avr +yrecon_rms)-dm , color='r',alpha=0.3) #plt.fill_between(lin_xrecon[1:-1]+0.2,numpy.log10(yreco[1:-1] - yrecon_down[1:-1] )-dm,numpy.log10(yreco[1:-1]+yrecon_up[1:-1])-dm , color='b',alpha=0.2) plt.fill_between(lin_xrecon + hm, numpy.log10((yrecon_d)), numpy.log10(yrecon_u) - dm, color='k', alpha=0.2) #plt.errorbar(bins[2:],rho_1[2:],yerr=er1[2:],fmt = 'ob',label='Detected') #plt.errorbar(bins2,rho_6-0.2,yerr=er6,fmt='ob',label='Detected') #working one #plt.plot(Lbins2,rho,'ob',label='simulation') #plt.plot(Lbins3,rho_,label='Noisy fluxes') #rho_2 #plt.errorbar(bins,rho_2 -0.2,yerr=er2,fmt='ok',label='data',markersize=10) #bin +0.2 #plt.errorbar(bins2,rho_6-0.2,yerr=er6,fmt='vm',label='Noisy NVSS') #plt.errorbar(bins2,rho_7-0.2,yerr=er6,fmt='xc',label='NVSS Detected') #for i in range(len(bins)): # print bins[i], rho_2[i] #sys.exit() #plt.errorbar(Lbins2,rho, err,fmt = 'ob',label='simulation') #plt.errorbar(Lbins2,rho_1,err_1,fmt = 'or',label='simulation_noisy') #plt.errorbar(L2,rho2,color='g',label='Analytic') #plt.errorbar(L3,rho3,color='g',label='Analytic II') #plt.axvspan(22.55 ,23.51,color='r',alpha=0.2) #plt.axvline(Lmin,color='r',linestyle='dashed') plt.axvline(fsigma, color='k', linestyle='dashed') #plt.axvline(sigma,color='g') plt.axvline(Llmin, color='r', linewidth=5) #plt.axvline(sigma2,color='m') #plt.axvline(fsigma2,color='m') #plt.axvline(23.89,color='b') #plt.axvline(23.71,color='c') #plt.axvline(23.52,color='r') #plt.axvline(truth['LMIN'],color='r', linestyle='dashed', label = 'True params') #plt.axvline(truth['LMAX'],color='r', linestyle='dashed') #plt.axvline(truth['LSTAR'],color='b') #plt.text(truth['LSTAR']-0.2,-9., '$L_*$',fontsize=18) #plt.axvline(Lmax,color='r', label= 'MAP params') #plt.axvline(Lstar,color='b',linestyle='dashed') #plt.axvline(Lmax, color='r',linestyle='dashed') #plt.text(Lstar-0.12,-10.5, '$L_*$',fontsize=18) #plt.text(fsigma+0.1,-6.7, '$5\sigma$',fontsize=25) #plt.text(sigma+0.1,-6.7, '$\sigma$',fontsize=25) plt.xlabel(r'$\rm{log_{10}[L_{1.4 GHz}/(W}$ $\rm{Hz^{-1})]}$', fontsize=30) plt.ylabel(r'$\rm{log_{10}[\rho_m(Mpc^{-3} mag^{-1})]}$', fontsize=30) plt.text(19.9, -7.7, '%.1f < z < %.1f' % (z_min, z_max), fontsize=30, alpha=0.6) # \n $M_i$ < -22 #plt.text(23.9,-9.7,'%s'%outdir,fontsize = 16 ) # \n $M_i$ < -22 plt.tick_params(axis='both', which='major', labelsize=20, width=3) plt.tick_params(axis='both', which='minor', labelsize=10, width=2) #plt.tight_layout() #plt.xtick(fontsize=15) #plt.ytick(fontsize=15) plt.xlim(18, 27.) plt.ylim(-11.2, 0.) #plt.ylim(-11,-5.5) ax.xaxis.set_minor_locator(AutoMinorLocator()) ax.yaxis.set_minor_locator(AutoMinorLocator()) #print truth['LMIN'] plt.legend(frameon=False).draggable() plotf = '%s/LF_recon_s1.pdf' % (outdir) plt.show() return 0
def main(): """ """ print 'Settings file is %s' % setf # Import the settings variables set_module = importlib.import_module(setf) globals().update(set_module.__dict__) expt = countModel(modelFamily, nlaws, setf, [dataset], floatNoise) recon_expt = countModel(modelFamily, nlaws, setf, [dataset], floatNoise) #print expt.data #print expt.bins # Get MAP parameters print '\n' * 5 print len(expt.parameters) ncols = len(expt.parameters) summf = os.path.join(outdir, '1-summary.txt') summary = numpy.genfromtxt(summf)[-1, :] drawmap = summary[-(ncols + 2):-2] ana=pymultinest.analyse.Analyzer(ncols-1,\ outputfiles_basename=os.path.join(outdir,outstem)) drawmap = ana.get_best_fit()['parameters'] if dataset == 'sdss': print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf) == 20: num = dataf[-5] print num else: num = dataf[-6:-4] d = numpy.genfromtxt('%s/%s' % (outdir, datafiles[0][4:])) print datafiles[0][4:] elif dataset == 'cosmos': print datafiles, len(datafiles[0]) dataf = datafiles[0] if len(dataf) == 24: num = dataf[-5] print num else: num = dataf[-6:-4] d = numpy.genfromtxt('%s/%s' % (outdir, datafiles[0][8:])) print datafiles[0][8:] elif 'sim' in dataset: d = numpy.genfromtxt(os.path.join(outdir, 'sim.txt')) ssbin = d[:, 2] Nbin = d[:, 3] dnds = d[:, 4] sbin2 = ssbin dnds2 = dnds #bins2 = numpy.arange(21.4,29.2,0.4) bins2 = numpy.arange(18.0, 29.2, 0.4) bins3 = numpy.arange(18., 29.2, 0.01) print len(expt.parameters) print 'this is 1st num ', num #sys.exit() params = drawmap # [0] #for i in drawmap: # params.append(i) print params print expt.parameters if modelFamily in ['LFsch', 'LFdpl_pl', 'LFdpl_dpl', 'LFlognorm_dpl']: Lnorm = params[expt.parameters.index('LNORM')] Lstar = params[expt.parameters.index('LSTAR')] Lslope = params[expt.parameters.index('LSLOPE')] #Lzevol=params[expt.parameters.index('LZEVOL')] if modelFamily in ['LFdpl_pl', 'LFdpl_dpl', 'LFlognorm_dpl']: Lslope2 = params[expt.parameters.index('LSLOPE2')] if modelFamily in [ 'LFlognorm', 'LFpl', 'LFdpl', 'LFdpl_pl', 'LFlognorm_dpl', 'LFdpl_dpl' ]: Lnorm_2 = params[expt.parameters.index('LNORM_2')] Lstar_2 = params[expt.parameters.index('LSTAR_2')] Lslope_2 = params[expt.parameters.index('LSLOPE_2')] if modelFamily in ['LFdpl_dpl', 'LFdpl']: Lslope2_2 = params[expt.parameters.index('LSLOPE2_2')] if modelFamily in ['LFlognorm', 'LFlognorm_dpl']: Lsigma = params[expt.parameters.index('LSIGMA')] Lmin = params[expt.parameters.index('LMIN')] Lmax = params[expt.parameters.index('LMAX')] truth = { 'noise': 150, 'LMIN': 22., 'LMAX': 24.5, 'LNORM': numpy.log10(1e-7), 'LSTAR': 23.3, 'LSLOPE': 3., 'LSLOPE2': 1. } #z = [0, 0.5, 1 , 1.5, 2, 2.3, 2.6, 3, 3.5, 4] #old #z = [ 0.7, 1 , 1.35, 1.7, 2, 2.3, 2.6, 3, 3.5, 4]# older print expt.parameters s = pylab.loadtxt('%s/recon_stats.txt' % outdir) xrecon = s[:-1, 0] yrecon = s[:-1, 1] yrecon_d = s[:-1, 2] yrecon_u = s[:-1, 3] yrecon_rms = s[:-1, 4] yrecon_avr = s[:-1, 5] yrecon_rms_down = yrecon_rms for i in range(len(yrecon_rms)): if yrecon_avr[i] < yrecon_rms[i]: yrecon_rms_down[i] = 10**(numpy.log10(yrecon_avr[i]) - 0.01) #print xrecon #print yrecon #sys.exit() z = [ 0.1, 0.4, 0.6, 0.8, 1.0, 1.3, 1.6, 2.0, 2.15, 2.35, 2.55, 2.85, 3.15, 3.5 ] #oldest ;) num = int(num) #num = 1. print num z_min, z_max, z_m = get_z(num) dl = get_dl(z_m) Vmax = get_Vmax(z_min, z_max) dsdl = get_dsdl(z_m, dl) z_m = (z_min + z_max) / 2 dl = get_dl(z_m) print z_min, z_max print expt.kind area = SURVEY_AREA * sqDeg2sr area1 = SURVEY_AREA * sqDeg2sr print SURVEY_AREA SMIN = get_sbins(numpy.power(10, Lmin), z_m, dl) * 1e6 SMAX = get_sbins(numpy.power(10, Lmax), z_m, dl) * 1e6 sigma, fsigma = numpy.log10( get_Lbins([SURVEY_NOISE, SURVEY_NOISE * 5], z_m, dl, 'muJy')) #*(1.4/3)**(-.7)) sigma2, fsigma2 = numpy.log10(get_Lbins([450, 2400], z_m, dl, 'muJy')) print z_m, dl, sigma, fsigma print SURVEY_NOISE, SURVEY_NOISE * 5, SURVEY_AREA #area = 6672*sqDeg2sr #143165.15 49996.49 59876.8861135 sbin3 = get_sbins(10**bins2, z_m, dl) * 1e6 sbin4 = get_sbins(10**bins3, z_m, dl) * 1e6 L_s = numpy.log10(get_Lbins(ssbin, z_m, dl, 'muJy')) #print expt.binsMedian #sys.exit() xreco = get_Lbins(xrecon, z_m, dl, 'muJy') #*(1.4/3)**(-.7) yreco = yrecon print SMIN, SMAX #sys.exit() lin_yrecon = numpy.log10(yreco) print xrecon lin_xrecon = numpy.log10(xreco) bins2 = numpy.arange(15., 25., 0.4) bins5, rho_5, er5, rho_6, er6 = numpy.loadtxt('cos_data/skads_s1_3_LF.el', unpack=True) #novak 2017 L_n = [21.77, 22.15, 22.46, 22.77, 23.09, 23.34] rho_n = [-2.85, -2.88, -3.12, -3.55, -4.05, -4.63] L_ner_u = [0.23, 0.18, 0.19, 0.2, 0.21, 0.28] L_ner_d = [1.1, 0.15, 0.14, 0.12, 0.12, 0.048] rho_ner = [0.09, 0.03, 0.0355, 0.059, 0.1, 0.234] #novak 2018 L_n2 = [21.77, 22.24, 22.68, 23.16, 23.69, 24.34, 24.74, 25.56] rho_n2 = [-2.84, -2.90, -3.34, -4.00, -4.92, -4.92, -5.22, -5.07] L_ner_u2 = [0.23, 0.27, 0.34, 0.37, 0.35, 0.21, 0.31, 0.03] L_ner_d2 = [1.0, 0.24, 0.17, 0.14, 0.16, 0.30, 0.20, 0.50] rho_ner_u2 = [0.08, 0.024, 0.038, 0.083, 0.28, 0.28, 0.45, 0.34] rho_ner_d2 = [0.07, 0.023, 0.035, 0.070, 0.25, 0.25, 0.37, 0.30] #l*= (1.4/3)**(-.7) #l2*= (1.4/3)**(-.7) #L*= (1.4/3)**(-.7) #Lbins2 = numpy.log10(lf.get_Lbins(sbin2[sbin2>0],z_m,dl)) print z_min, z_max bins = numpy.arange(fsigma - 0., 26.2, 0.4) #bin +0.2 #bins = numpy.arange(fsigma -4.2,30,0.4) #bin #s,s_z = numpy.loadtxt('sdss/dr12s_s1_vol.txt', unpack=True, usecols=(-1,2)) fig, ax = plt.subplots() plt.rc('lines', linewidth=2) if modelFamily in ['LFdpl', 'LFdpl_dpl']: faint = lumfuncUtils.doublepowerlaw(numpy.power(10, bins3), Lstar_2, Lslope_2, Lslope2_2, Lnorm_2) elif modelFamily in ['LFpl', 'LFdpl_pl']: faint = lumfuncUtils.powerlaw(numpy.power(10, bins3), Lstar_2, Lslope_2, Lnorm_2) else: faint = lumfuncUtils.lognormpl(numpy.power(10, bins3), Lstar_2, Lslope_2, Lsigma, Lnorm_2) dm = 0. #05 hm = 0. plt.errorbar(bins5, rho_6, yerr=er6, fmt='sr', label=r'$\rm{25 >\log_{10}(L) > %s}$' % (20.8), markersize=10) plt.errorbar(bins5, rho_5, yerr=er5, fmt='*b', label=r'$\rm{25 >\log_{10}(L) > %s}$' % (20.8), markersize=10) plt.plot(bins3 + hm, numpy.log10(faint) - dm, '--b', label='faint-end') plt.errorbar(lin_xrecon + hm, lin_yrecon - dm, fmt='-k', label='MAP', linewidth=2) plt.errorbar(lin_xrecon + hm, numpy.log10(yrecon_avr) - dm, fmt='-g', label='Average') #plt.errorbar(numpy.array(L_n),numpy.array(rho_n) -0.4,xerr=[L_ner_d,L_ner_u],yerr=rho_ner, fmt='^c', label='Novak et al 2017') #plt.errorbar(numpy.array(L_n2),numpy.array(rho_n2) -0.4,xerr=[L_ner_d2,L_ner_u2],yerr=[rho_ner_d2,rho_ner_u2], fmt='sk', label='Total RLF Novak et al 2018') plt.fill_between(lin_xrecon + hm, numpy.log10((yrecon_d)), numpy.log10(yrecon_u) - dm, color='k', alpha=0.2) plt.axvline(fsigma, color='k', linestyle='dashed') #plt.axvline(sigma,color='g') #plt.axvline(Llmin,color='r',linewidth=5) plt.xlabel(r'$\rm{log_{10}[L_{3 GHz}/(W}$ $\rm{Hz^{-1})]}$', fontsize=30) plt.ylabel(r'$\rm{log_{10}[\rho_m(Mpc^{-3} mag^{-1})]}$', fontsize=30) plt.text(19.9, -7.7, '%.1f < z < %.1f' % (0.1, 0.4), fontsize=30, alpha=0.6) # \n $M_i$ < -22 #plt.text(23.9,-9.7,'%s'%outdir,fontsize = 16 ) # \n $M_i$ < -22 plt.tick_params(axis='both', which='major', labelsize=20, width=3) plt.tick_params(axis='both', which='minor', labelsize=10, width=2) plt.xlim(18, 26.) plt.ylim(-7, -1) ax.xaxis.set_minor_locator(AutoMinorLocator()) ax.yaxis.set_minor_locator(AutoMinorLocator()) #print truth['LMIN'] plt.legend(frameon=False).draggable() plotf = '%s/LF_recon_s1.pdf' % (outdir) plt.show() return 0