def makeHaloMassFunction(self,catalog): assert catalog != None #Infer halo mass function from Millenium Mh,z catalogue ; we use a power-law for this. zeds,dz = numpy.linspace(0,1.8,10,retstep=True)#coarse redshift bin. these things change slowly. self.HMF = {} self.HMF['catalog'] = catalog self.HMFzkeys,self.HMFdz = zeds-dz,dz infer_from_data=True if infer_from_data: # Load in the catalog's list of halo masses and redshift. # import cPickle # F=open(self.HMFdata,'rb') # inhalomass,inhaloZ = cPickle.load(F) # F.close() inhalomass,inhaloZ = pangloss.readPickle(catalog) inhaloZ[inhaloZ<0]=0 for i in range(len(zeds)): z=zeds[i]+dz/2. Masses=inhalomass[inhaloZ>z-dz/2] newinZ=inhaloZ[inhaloZ>z-dz/2] Mhalos=Masses[newinZ<z+dz/2] Massbins=numpy.linspace(10,20,101) hist,bins=numpy.histogram(Mhalos,Massbins) MOD = interpolate.splrep(Massbins[:-1],hist,s=0,k=1) HMF = interpolate.splev(self.Mh_axis,MOD) self.TCM = self.Mh_axis[HMF.argmax()+1:] self.TCHM = HMF[HMF.argmax()+1:] self.TCM=self.TCM[self.TCHM>0] self.TCHM=self.TCHM[self.TCHM>0] # Fit a powerlaw to the HMF PLcoeff,ier = optimize.leastsq(self.getPL,[14.56,-1.]) self.HMF[i] = PLcoeff # We've already fit a powerlaw to millenium: it's parameters as a function of z are # included here. # elif catalog='Millennium': # for Z in zeds: # z=Z+dz/2. # if z>0 and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= return
def makeHaloMassFunction(self, catalog): assert catalog != None # Infer halo mass function from Millenium Mh,z catalogue ; we use a power-law for this. zeds, dz = numpy.linspace(0, 1.8, 10, retstep=True) # coarse redshift bin. these things change slowly. self.HMF = {} self.HMF["catalog"] = catalog self.HMFzkeys, self.HMFdz = zeds - dz, dz infer_from_data = True if infer_from_data: # Load in the catalog's list of halo masses and redshift. # import cPickle # F=open(self.HMFdata,'rb') # inhalomass,inhaloZ = cPickle.load(F) # F.close() inhalomass, inhaloZ = pangloss.readPickle(catalog) inhaloZ[inhaloZ < 0] = 0 for i in range(len(zeds)): z = zeds[i] + dz / 2.0 Masses = inhalomass[inhaloZ > z - dz / 2] newinZ = inhaloZ[inhaloZ > z - dz / 2] Mhalos = Masses[newinZ < z + dz / 2] Massbins = numpy.linspace(10, 20, 101) hist, bins = numpy.histogram(Mhalos, Massbins) MOD = interpolate.splrep(Massbins[:-1], hist, s=0, k=1) HMF = interpolate.splev(self.Mh_axis, MOD) self.TCM = self.Mh_axis[HMF.argmax() + 1 :] self.TCHM = HMF[HMF.argmax() + 1 :] self.TCM = self.TCM[self.TCHM > 0] self.TCHM = self.TCHM[self.TCHM > 0] # Fit a powerlaw to the HMF PLcoeff, ier = optimize.leastsq(self.getPL, [14.56, -1.0]) self.HMF[i] = PLcoeff # We've already fit a powerlaw to millenium: it's parameters as a function of z are # included here. # elif catalog='Millennium': # for Z in zeds: # z=Z+dz/2. # if z>0 and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= # if z> and z<:self.HMF[z]= return
zperr = experiment.parameters['PhotozError'] # Stellar mass observations: MserrP = experiment.parameters['PhotometricMstarError'] MserrS = experiment.parameters['SpectroscopicMstarError'] # Sampling Pr(kappah|D): Ns = experiment.parameters['NRealisations'] # Reconstruct calibration lines of sight? DoCal = experiment.parameters['ReconstructCalibrations'] # -------------------------------------------------------------------- # Load in stellar mass to halo relation, or make a new one: try: shmr = pangloss.readPickle('dummy') #SHMfile) except IOError: print "Reconstruct: generating the stellar mass to halo mass grid." print "Reconstruct: this may take a moment..." shmr = pangloss.SHMR(method=SHMrelation) shmr.makeHaloMassFunction(HMFfile) shmr.makeCDFs() pangloss.writePickle(shmr, SHMfile) print "Reconstruct: SHMR saved to " + SHMfile # -------------------------------------------------------------------- # Make redshift grid: grid = pangloss.Grid(zd, zs, nplanes=100) # --------------------------------------------------------------------
zperr = experiment.parameters['PhotozError'] # Stellar mass observations: MserrP = experiment.parameters['PhotometricMstarError'] MserrS = experiment.parameters['SpectroscopicMstarError'] # Sampling Pr(kappah|D): Ns = experiment.parameters['NRealisations'] # Reconstruct calibration lines of sight? DoCal = experiment.parameters['ReconstructCalibrations'] # -------------------------------------------------------------------- # Load in stellar mass to halo relation, or make a new one: try: shmr = pangloss.readPickle('dummy')#SHMfile) except IOError: print "Reconstruct: generating the stellar mass to halo mass grid." print "Reconstruct: this may take a moment..." shmr = pangloss.SHMR(method=SHMrelation) shmr.makeHaloMassFunction(HMFfile) shmr.makeCDFs() pangloss.writePickle(shmr,SHMfile) print "Reconstruct: SHMR saved to "+SHMfile # -------------------------------------------------------------------- # Make redshift grid: grid = pangloss.Grid(zd,zs,nplanes=100) # --------------------------------------------------------------------
# Reconstruct calibration lines of sight? DoCal = experiment.parameters['ReconstructCalibrations'] # -------------------------------------------------------------------- # Make redshift grid: grid = pangloss.Grid(zd, zs, nplanes=100) # -------------------------------------------------------------------- # Read in lightcones from pickles: calcones = [] for i in xrange(Nc): calcones.append(pangloss.readPickle(calpickles[i])) if i == 0: print calpickles[i] if DoCal == "False": #must be string type calcones = [] calpickles = [] allcones = calcones allconefiles = calpickles # ============================================================== # Find the overdensity of lightcones cut at m<22 in F125W # ============================================================== print "Magnifier: finding the distribution of lightcones with density..." lc_dens = []
pfile = x.split('.')[0].split("_lightcone")[0]+"_"+EXP_NAME+"_KappaHilbert_Kappah_"+comparatorType+".pickle" calresultpickles.append(pfile) else: print "Calibrate: Unrecognised comparator "+Comparator print "Calibrate: If you want to use a comparator other than kappa_h, " print "Calibrate: you'll need to code it up!" print "Calibrate: (This should be easy, but you can ask [email protected] for help)." exit() # Now calculate comparators: callist=numpy.empty((Nc,2)) jd=pangloss.PDF(["kappa_ext",comparator+'_'+comparatorType]) for i in range(Nc): C = calresultpickles[i] pdf = pangloss.readPickle(C) if comparator=="Kappah": if comparatorType=="median": # Recall that we created a special file for this # choice of comparator and comparator type, in # Reconstruct. You could also use the # comparatortype=="mean" code, swapping mean for median. callist[i,0]=pdf[0] callist[i,1]=pdf[1][0] elif comparatorType=="mean": callist[i,0] = pdf.truth[0] callist[i,1] = numpy.mean(pdf.samples)
)[0] + "_" + EXP_NAME + "_KappaHilbert_Kappah_" + comparatorType + ".pickle" calresultpickles.append(pfile) else: print "Calibrate: Unrecognised comparator " + Comparator print "Calibrate: If you want to use a comparator other than kappa_h, " print "Calibrate: you'll need to code it up!" print "Calibrate: (This should be easy, but you can ask [email protected] for help)." exit() # Now calculate comparators: callist = numpy.empty((Nc, 2)) jd = pangloss.PDF(["kappa_ext", comparator + '_' + comparatorType]) for i in range(Nc): C = calresultpickles[i] pdf = pangloss.readPickle(C) if comparator == "Kappah": if comparatorType == "median": # Recall that we created a special file for this # choice of comparator and comparator type, in # Reconstruct. You could also use the # comparatortype=="mean" code, swapping mean for median. callist[i, 0] = pdf[0] callist[i, 1] = pdf[1][0] elif comparatorType == "mean": callist[i, 0] = pdf.truth[0] callist[i, 1] = numpy.mean(pdf.samples)
# Reconstruct calibration lines of sight? DoCal = experiment.parameters["ReconstructCalibrations"] # -------------------------------------------------------------------- # Make redshift grid: grid = pangloss.Grid(zd, zs, nplanes=100) # -------------------------------------------------------------------- # Read in lightcones from pickles: calcones = [] for i in xrange(Nc): calcones.append(pangloss.readPickle(calpickles[i])) if i == 0: print calpickles[i] if DoCal == "False": # must be string type calcones = [] calpickles = [] allcones = calcones allconefiles = calpickles # ============================================================== # Find the overdensity of lightcones cut at m<22 in F125W # ============================================================== print "Magnifier: finding the distribution of lightcones with density..."