# 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) # -------------------------------------------------------------------- # Read in lightcones from pickles: calcones = [] for i in range(Nc): calcones.append(pangloss.readPickle(calpickles[i])) obscone = pangloss.readPickle(obspickle)
# 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) # -------------------------------------------------------------------- # Read in lightcones from pickles: calcones = [] for i in range(Nc): calcones.append(pangloss.readPickle(calpickles[i])) obscone = pangloss.readPickle(obspickle)
D1s = self.Da_ps[i] D2 = self.Da_l D12 = self.Da_pl[i] self.beta[i] = (D12*self.Da_s)/(D2*D1s) return # --------------------------------------------------------------------------- def snap(self,z): snapped_p = numpy.digitize(z,self.redshifts-(self.dz)/2.0)-1 snapped_p[snapped_p < 0] = 0 # catalogs have some blue-shifted objects! snapped_z = self.redshifts[snapped_p] return snapped_z,snapped_p # --------------------------------------------------------------------------- def __str__(self): return '1-D Grid of %i planes seperated in redshift by dz= %f' % (self.nplanes,self.dz) # ============================================================================ if __name__ == '__main__': nplanes=100 g=Grid(0.6,1.4,nplanes=nplanes) testfile = "/data/tcollett/Pangloss/grid%i.grid"%nplanes pangloss.writePickle(g,testfile) # ============================================================================
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) else: print "Calibrate: Unrecognised comparatorType "+comparatorType print "Calibrate: If you want to use a comparatorType other than median " print "Calibrate: or mean, you'll need to code it up!" print "Calibrate: (This should be easy, but you can ask [email protected] for help)." exit() jd.append(callist[i]) pangloss.writePickle(callist,jointdistfile) # Also store the joint dist as a pangloss pdf: pangloss.writePickle(jd,jointdistasPDFfile) # Plot: plotfile = jointdistasPDFfile.split('.')[0]+'.png' jd.plot("Kappah_median","kappa_ext",weight=None,output=plotfile,title="The joint distribution of $\kappa_{\mathrm{ext}}$ and calibrator \n\n (more correlated means a better calibrator!)") print "Calibrate: calibration joint PDF saved in:" print "Calibrate: "+jointdistfile print "Calibrate: and "+jointdistasPDFfile print "Calibrate: you can view this PDF in "+plotfile # -------------------------------------------------------------------- # Mode 2: calibrate a real line of sight's Pr(kappah|D) using the
lc.plots('kappa', output=CALIB_DIR + "/example_snapshot_kappa_uncalib_z=1.4.png") lc.plots('mu', output=CALIB_DIR + "/example_snapshot_mu_uncalibz=1.4.png") del lc pk = numpy.array(pk) pmu = numpy.array(pmu) # -------------------------------------------------------------------- # Write PDFs to pickles pangloss.writePickle(pk, CALIB_DIR + "/Pofk_z=" + str(zs) + ".pickle") pangloss.writePickle(pmu, CALIB_DIR + "/PofMu_z=" + str(zs) + ".pickle") del pk del pmu print "Magnifier: saved PofMu to " + CALIB_DIR + "/Pofk_z=" + str( zs) + ".pickle" pmu = pangloss.readPickle(CALIB_DIR + "/PofMu_z=" + str(zs) + ".pickle") pk = pangloss.readPickle(CALIB_DIR + "/Pofk_z=" + str(zs) + ".pickle") # -------------------------------------------------------------------- # Plot contributions to total kappa and mass at redshifts if plot_contributions:
print "Drill: Pickling lightcones from this patch of sky..." for k in range(Ncones): if k % 200 == 0 and k !=0: print ("Drill: ...on cone %i out of %i..." % (k,Ncones)) lc = pangloss.Lightcone(table,'simulated',[x[k],y[k]],Rc) if kappamaps is not None: lc.kappa_hilbert = MSconvergence.at(x[k],y[k],coordinate_system='physical') # Coming soon... # lc.gamma1_hilbert = MSgamma1.at(x[k],y[k],coordinate_system='physical') # lc.gamma2_hilbert = MSgamma2.at(x[k],y[k],coordinate_system='physical') calpickle = experiment.getLightconePickleName('simulated',pointing=count) pangloss.writePickle(lc,calpickle) count += 1 # Save memory! del table del lc del catalog print "Drill: ...done." print ("Drill: All %i calibration lightcones made." % (count)) # -------------------------------------------------------------------- # Now, make any observed lightcones required:
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) else: print "Calibrate: Unrecognised comparatorType " + comparatorType print "Calibrate: If you want to use a comparatorType other than median " print "Calibrate: or mean, you'll need to code it up!" print "Calibrate: (This should be easy, but you can ask [email protected] for help)." exit() jd.append(callist[i]) pangloss.writePickle(callist, jointdistfile) # Also store the joint dist as a pangloss pdf: pangloss.writePickle(jd, jointdistasPDFfile) # Plot: plotfile = jointdistasPDFfile.split('.')[0] + '.png' jd.plot( "Kappah_median", "kappa_ext", weight=None, output=plotfile, title= "The joint distribution of $\kappa_{\mathrm{ext}}$ and calibrator \n\n (more correlated means a better calibrator!)" )
(k, Ncones)) lc = pangloss.Lightcone(table, 'simulated', [x[k], y[k]], Rc) if kappamaps is not None: lc.kappa_hilbert = MSconvergence.at( x[k], y[k], coordinate_system='physical') # Coming soon... # lc.gamma1_hilbert = MSgamma1.at(x[k],y[k],coordinate_system='physical') # lc.gamma2_hilbert = MSgamma2.at(x[k],y[k],coordinate_system='physical') calpickle = experiment.getLightconePickleName( 'simulated', pointing=count) pangloss.writePickle(lc, calpickle) count += 1 # Save memory! del table del lc del catalog print "Drill: ...done." print("Drill: All %i calibration lightcones made." % (count)) # -------------------------------------------------------------------- # Now, make any observed lightcones required: if obscat != 'none':
Mstell_cont[j:,] = lc.findContributions("stellarmass") # Make a nice visualisation of one of the lightcones if j == 0: lc.plots("kappa", output=CALIB_DIR + "/example_snapshot_kappa_uncalib_z=1.4.png") lc.plots("mu", output=CALIB_DIR + "/example_snapshot_mu_uncalibz=1.4.png") del lc pk = numpy.array(pk) pmu = numpy.array(pmu) # -------------------------------------------------------------------- # Write PDFs to pickles pangloss.writePickle(pk, CALIB_DIR + "/Pofk_z=" + str(zs) + ".pickle") pangloss.writePickle(pmu, CALIB_DIR + "/PofMu_z=" + str(zs) + ".pickle") del pk del pmu print "Magnifier: saved PofMu to " + CALIB_DIR + "/Pofk_z=" + str(zs) + ".pickle" pmu = pangloss.readPickle(CALIB_DIR + "/PofMu_z=" + str(zs) + ".pickle") pk = pangloss.readPickle(CALIB_DIR + "/Pofk_z=" + str(zs) + ".pickle") # -------------------------------------------------------------------- # Plot contributions to total kappa and mass at redshifts if plot_contributions: mean_kappa_cont = numpy.mean(kappa_cont, axis=0)