def __init__(self,iniFile,expName,gridName,version,ClusterCosmology): Config = SafeConfigParser() Config.optionxform=str Config.read(iniFile) self.cc = ClusterCosmology bigDataDir = Config.get('general','bigDataDirectory') self.clttfile = Config.get('general','clttfile') self.constDict = dict_from_section(Config,'constants') self.clusterDict = dict_from_section(Config,'cluster_params') #version = Config.get('general','version') beam = list_from_config(Config,expName,'beams') noise = list_from_config(Config,expName,'noises') freq = list_from_config(Config,expName,'freqs') lknee = list_from_config(Config,expName,'lknee')[0] alpha = list_from_config(Config,expName,'alpha')[0] self.fsky = Config.getfloat(expName,'fsky') self.mgrid,self.zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+".pkl",'rb')) #self.cc = ClusterCosmology(self.fparams,self.constDict,clTTFixFile=self.clttfile) self.SZProp = SZ_Cluster_Model(self.cc,self.clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha) self.HMF = Halo_MF(self.cc,self.mgrid,self.zgrid) self.HMF.sigN = siggrid.copy()
def counts_from_config(Config,bigDataDir,version,expName,gridName,mexp_edges,z_edges,lkneeTOverride=None,alphaTOverride=None): suffix = "" if lkneeTOverride is not None: suffix += "_"+str(lkneeTOverride) if alphaTOverride is not None: suffix += "_"+str(alphaTOverride) mgrid,zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+suffix+".pkl",'rb')) #mgrid,zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+suffix+".pkl",'rb'),encoding='latin1') experimentName = expName cosmoDict = dict_from_section(Config,"params") constDict = dict_from_section(Config,'constants') clusterDict = dict_from_section(Config,'cluster_params') clttfile = Config.get("general","clttfile") cc = ClusterCosmology(cosmoDict,constDict,clTTFixFile = clttfile) beam = list_from_config(Config,experimentName,'beams') noise = list_from_config(Config,experimentName,'noises') freq = list_from_config(Config,experimentName,'freqs') lmax = int(Config.getfloat(experimentName,'lmax')) lknee = float(Config.get(experimentName,'lknee').split(',')[0]) alpha = float(Config.get(experimentName,'alpha').split(',')[0]) fsky = Config.getfloat(experimentName,'fsky') SZProf = SZ_Cluster_Model(cc,clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha) hmf = Halo_MF(cc,mexp_edges,z_edges) hmf.sigN = siggrid.copy() Ns = np.multiply(hmf.N_of_z_SZ(fsky,SZProf),np.diff(z_edges).reshape(1,z_edges.size-1)) return Ns.ravel().sum()
def priors_from_config(Config, expName, calName, fishName, paramList, tauOverride=None): fishSection = 'fisher-' + fishName try: priorNameList = Config.get(fishSection, 'prior_names').split(',') priorValueList = list_from_config(Config, fishSection, 'prior_values') except: priorNameList = [] priorValueList = [] if tauOverride is not None: try: tauind = priorNameList.index('tau') priorValueList[tauind] = tauOverride except ValueError: priorNameList.append("tau") priorValueList.append(tauOverride) # if "CMB" in calName: # assert "sigR" not in paramList # paramList.append("sigR") # try: # priorNameList.append("sigR") # beam = list_from_config(Config,expName,'beams') # freq = list_from_config(Config,expName,'freqs') # freq_to_use = Config.getfloat(calName,'freq') # ind = np.where(np.isclose(freq,freq_to_use)) # beamFind = np.array(beam)[ind] # priorValueList.append(old_div(beamFind,2.)) # print("Added sigR prior ", priorValueList[-1]) # except: # traceback.print_exc() # print("Couldn't add sigR prior. Is this CMB lensing? Exiting.") # sys.exit(1) # if not("b_wl" in paramList): # print "OWL but b_wl not found in paramList. Adding with a 1% prior." # paramList.append("b_wl") #priorNameList.append("b_wl") #priorValueList.append(0.01) # if "owl" in calName: # if not("b_wl" in paramList): # print "OWL but b_wl not found in paramList. Adding with a 1% prior." # paramList.append("b_wl") # priorNameList.append("b_wl") # priorValueList.append(0.01) print(paramList, priorNameList, priorValueList) return paramList, priorNameList, priorValueList
def instantiate_grids(self): mubins = list_from_config(self.config, 'general', 'mubins') self.mus = np.linspace(mubins[0], mubins[1], int(mubins[2]) + 1) cc = ClusterCosmology(paramDict=self.params, constDict=self.constdict, clTTFixFile=self.clttfile) clst = Clustering(self.inifile, self.expname, self.gridname, self.version, cc) self.ks = clst.HMF.kh self.ps_fid = clst.fine_ps_bar(self.mus) self.veff_fid = clst.V_eff(self.mus) self.deltaks = np.gradient(self.ks) self.deltamus = np.gradient(self.mus)
# Get list of parameters paramList = Config.get("fisher","paramList").split(',') # Load fiducials and derivatives fidCls = tryLoad(derivRoot+'_fCls.csv',',') dCls = {} for paramName in paramList: dCls[paramName] = tryLoad(derivRoot+'_dCls_'+paramName+'.csv',',') # Get CMB noise functions and ell ranges. if (noise_func_tt is None) or (noise_func_ee is None): fnTT, fnEE = noiseFromConfig(Config,expName,TCMB=TCMB,beamsOverride=None,noisesOverride=None,lkneeTOverride=None,lkneePOverride=None,alphaTOverride=None,alphaPOverride=None) tellmin,tellmax = list_from_config(Config,expName,'tellrange') pellmin,pellmax = list_from_config(Config,expName,'pellrange') if (noise_func_tt is not None): fnTT = cosmology.noise_pad_infinity(noise_func_tt,tellmin,tellmax) if (noise_func_ee is not None): fnEE = cosmology.noise_pad_infinity(noise_func_ee,pellmin,pellmax) # Pad CMB lensing noise with infinity outside L ranges kellmin,kellmax = list_from_config(Config,'lensing','Lrange') fnKK = cosmology.noise_pad_infinity(interp1d(ls,Nls,fill_value=np.inf,bounds_error=False),kellmin,kellmax) # Decide on what ell range to calculate the Fisher matrix ellrange = np.arange(min(tellmin,pellmin,kellmin),max(tellmax,pellmax,kellmax)).astype(int) # Get fsky
pzcutoff = Config.getfloat('general', 'photoZCutOff') mgrid, zgrid, siggrid = pickle.load(open( bigDataDir + "szgrid_" + expName + "_" + gridName + "_v" + version + ".pkl", 'rb'), encoding='latin1') assert np.all(mgrid == mexprange) assert np.all(zrange == zgrid) saveId = expName + "_" + gridName + "_" + calName + "_v" + version from orphics.io import dict_from_section, list_from_config constDict = dict_from_section(Config, 'constants') clusterDict = dict_from_section(Config, 'cluster_params') beam = list_from_config(Config, expName, 'beams') noise = list_from_config(Config, expName, 'noises') freq = list_from_config(Config, expName, 'freqs') lknee = list_from_config(Config, expName, 'lknee')[0] alpha = list_from_config(Config, expName, 'alpha')[0] fsky = Config.getfloat(expName, 'fsky') massMultiplier = Config.getfloat('general', 'mass_calib_factor') clttfile = Config.get('general', 'clttfile') # get s/n q-bins qs = list_from_config(Config, 'general', 'qbins') qspacing = Config.get('general', 'qbins_spacing') if qspacing == "log": qbins = np.logspace(np.log10(qs[0]), np.log10(qs[1]), int(qs[2]) + 1)
def lensNoise(Config, expName, lensName, beamOverride=None, noiseTOverride=None, lkneeTOverride=None, lkneePOverride=None, alphaTOverride=None, alphaPOverride=None, tellminOverride=None, pellminOverride=None, tellmaxOverride=None, pellmaxOverride=None, deg=5., px=1.0, gradCut=10000, bigell=9000, plot=False, theoryOverride=None, lensedEqualsUnlensed=True, noiseFuncT=None, noiseFuncP=None): from orphics.io import list_from_config beam = list_from_config(Config, expName, 'beams') noise = list_from_config(Config, expName, 'noises') freq = list_from_config(Config, expName, 'freqs') lkneeT, lkneeP = list_from_config(Config, expName, 'lknee') alphaT, alphaP = list_from_config(Config, expName, 'alpha') if (noiseFuncT is None) and (noiseFuncP is None): print 'Not using noise files for generating lensing noise' else: print 'Using noise files for generating lensing noise' tellmin, tellmax = list_from_config(Config, expName, 'tellrange') if tellminOverride is not None: tellmin = tellminOverride if tellmaxOverride is not None: tellmax = tellmaxOverride pellmin, pellmax = list_from_config(Config, expName, 'pellrange') if pellminOverride is not None: pellmin = pellminOverride if pellmaxOverride is not None: pellmax = pellmaxOverride lmax = int(Config.getfloat(expName, 'lmax')) pols = Config.get(lensName, 'polList').split(',') freq_to_use = Config.getfloat(lensName, 'freq') ind = np.where(np.isclose(freq, freq_to_use)) beamFind = np.array(beam)[ind] noiseFind = np.array(noise)[ind] assert beamFind.size == 1 assert noiseFind.size == 1 if beamOverride is not None: beamX = beamY = beamOverride else: beamX = beamY = beamFind[0] if noiseTOverride is not None: noiseTX = noiseTY = noiseTOverride else: noiseTX = noiseTY = noiseFind[0] if lkneeTOverride is not None: lkneeT = lkneeTOverride if lkneePOverride is not None: lkneeP = lkneePOverride if alphaTOverride is not None: alphaT = alphaTOverride if alphaPOverride is not None: alphaP = alphaPOverride from orphics.lensing import NlGenerator, getMax from orphics import maps #deg = 5. #px = 1.0 dell = 10 kellmin = 10 shape, wcs = maps.rect_geometry(width_deg=deg, px_res_arcmin=px) kellmax = max(tellmax, pellmax) if theoryOverride is None: from orphics.cosmology import Cosmology cc = Cosmology(lmax=int(kellmax), pickling=True) theory = cc.theory else: theory = theoryOverride cc = None bin_edges = np.arange(kellmin, kellmax, dell) myNls = NlGenerator(shape, wcs, theory, bin_edges, gradCut=gradCut, bigell=bigell, unlensedEqualsLensed=lensedEqualsUnlensed) myNls.updateNoise(beamX, noiseTX, np.sqrt(2.) * noiseTX, tellmin, tellmax, pellmin, pellmax, beamY=beamY, noiseTY=noiseTY, noisePY=np.sqrt(2.) * noiseTY, lkneesX=(lkneeT, lkneeP), lkneesY=(lkneeT, lkneeP), alphasX=(alphaT, alphaP), alphasY=(alphaT, alphaP), noiseFuncTX=noiseFuncT, noiseFuncTY=noiseFuncT, noiseFuncPX=noiseFuncP, noiseFuncPY=noiseFuncP) lsmv, Nlmv, ells, dclbb, efficiency = myNls.getNlIterative(pols, kellmin, kellmax, tellmax, pellmin, pellmax, dell=dell, halo=True, plot=plot) return lsmv, Nlmv, ells, dclbb, efficiency, cc
iniFile = "input/pipeline.ini" Config = SafeConfigParser() Config.optionxform = str Config.read(iniFile) expList = [ "dummy-S3", "S4-3.0-0.4", "S4-2.5-0.4", "S4-2.0-0.4", "S4-1.5-0.4", "S4-1.0-0.4" ] beams = {} noises = {} for i, expName in enumerate(expList): beams[expName] = list_from_config(Config, expName, 'beams') freqs = list_from_config(Config, expName, 'freqs') if i == 0: freqOrig = list(freqs) assert [f == forig for f, forig in zip(freqs, freqOrig)] latex = "" print("BEAMS") print("============") for i, freq in enumerate(freqs): latex += '{:.0f}'.format(freq) for exp in expList: val = beams[exp][i]
".pkl", 'rb')) #for expName,col in zip(expList,colList): # mgrid,zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+".pkl",'rb')) if (cal == 'owl2'): massGridName = bigDataDir + "lensgrid_grid-" + cal + "_" + cal + ".pkl" else: massGridName = bigDataDir + "lensgrid_" + expName + "_" + gridName + "_" + cal + "_v" + version + ".pkl" mexp_edges, z_edges, lndM = pickle.load(open(massGridName, "rb")) zrange = (z_edges[1:] + z_edges[:-1]) / 2. beam = list_from_config(Config, expName, 'beams') noise = list_from_config(Config, expName, 'noises') freq = list_from_config(Config, expName, 'freqs') lknee = list_from_config(Config, expName, 'lknee')[0] alpha = list_from_config(Config, expName, 'alpha')[0] fsky = Config.getfloat(expName, 'fsky') HMF = Halo_MF(cc, mexp_edges, z_edges) HMF.sigN = siggrid.copy() SZProf = SZ_Cluster_Model(cc, clusterDict, rms_noises=noise, fwhms=beam, freqs=freq, lknee=lknee, alpha=alpha)
fparams = {} for (key, val) in Config.items('params'): if ',' in val: param, step = val.split(',') if key == 'sigR': rayFid = float(param) rayStep = float(step) fparams[key] = float(param) else: fparams[key] = float(val) from orphics.io import dict_from_section, list_from_config bigDataDir = Config.get('general', 'bigDataDirectory') ms = list_from_config(Config, gridName, 'mexprange') Mexp_edges = np.arange(ms[0], ms[1] + ms[2], ms[2]) zs = list_from_config(Config, gridName, 'zrange') z_edges = np.arange(zs[0], zs[1] + zs[2], zs[2]) M_edges = 10**Mexp_edges M = old_div((M_edges[1:] + M_edges[:-1]), 2.) mgrid = np.log10(M) zgrid = old_div((z_edges[1:] + z_edges[:-1]), 2.) beam = list_from_config(Config, expName, 'beams') noise = list_from_config(Config, expName, 'noises') freq = list_from_config(Config, expName, 'freqs') fsky = Config.getfloat(expName, 'fsky') try:
def noiseFromConfig(Config, expName, TCMB=2.7255e6, beamsOverride=None, noisesOverride=None, lkneeTOverride=None, lkneePOverride=None, alphaTOverride=None, alphaPOverride=None, tellminOverride=None, pellminOverride=None, tellmaxOverride=None, pellmaxOverride=None): tellmin, tellmax = list_from_config(Config, expName, 'tellrange') if tellminOverride is not None: tellmin = tellminOverride if tellmaxOverride is not None: tellmax = tellmaxOverride pellmin, pellmax = list_from_config(Config, expName, 'pellrange') if pellminOverride is not None: pellmin = pellminOverride if pellmaxOverride is not None: pellmax = pellmaxOverride if beamsOverride is not None: beams = beamsOverride else: beams = list_from_config(Config, expName, 'beams') if noisesOverride is not None: noises = noisesOverride else: noises = list_from_config(Config, expName, 'noises') lkneeT, lkneeP = list_from_config(Config, expName, 'lknee') alphaT, alphaP = list_from_config(Config, expName, 'alpha') if lkneeTOverride is not None: lkneeT = lkneeTOverride if lkneePOverride is not None: lkneeP = lkneePOverride if alphaTOverride is not None: alphaT = alphaTOverride if alphaPOverride is not None: alphaP = alphaPOverride invnTTs = 0. invnEEs = 0. for beam, noise in zip(beams, noises): invnTTs += 1. / cosmo.noise_func(np.arange(tellmin, tellmax), beam, noise, lknee=lkneeT, alpha=alphaT, TCMB=TCMB, dimensionless=True) invnEEs += 1. / cosmo.noise_func(np.arange(pellmin, pellmax), beam, noise * np.sqrt(2.), lknee=lkneeP, alpha=alphaP, TCMB=TCMB, dimensionless=True) fnTT = interp1d(np.arange(tellmin, tellmax), 1. / invnTTs, bounds_error=False, fill_value=np.inf) fnEE = interp1d(np.arange(pellmin, pellmax), 1. / invnEEs, bounds_error=False, fill_value=np.inf) return fnTT, fnEE
def fisher_from_config(fidCls, dCls, paramList, Config, expName, lensName=None, TCMB=2.7255e6, beamsOverride=None, noisesOverride=None, lkneeTOverride=None, lkneePOverride=None, alphaTOverride=None, alphaPOverride=None, tellminOverride=None, pellminOverride=None, tellmaxOverride=None, pellmaxOverride=None): fnTT, fnEE = noiseFromConfig(Config, expName, TCMB, beamsOverride, noisesOverride, lkneeTOverride, lkneePOverride, alphaTOverride, alphaPOverride, tellminOverride, pellminOverride, tellmaxOverride, pellmaxOverride) tellmin, tellmax = list_from_config(Config, expName, 'tellrange') pellmin, pellmax = list_from_config(Config, expName, 'pellrange') if tellminOverride is not None: tellmin = tellminOverride if tellmaxOverride is not None: tellmax = tellmaxOverride if pellminOverride is not None: pellmin = pellminOverride if pellmaxOverride is not None: pellmax = pellmaxOverride if lensName is not None: doLens = True ls, Nls, ellbb, dlbb, efficiency, cc = lensNoise( Config, expName, lensName, beamsOverride, noisesOverride, lkneeTOverride, lkneePOverride, alphaTOverride, alphaPOverride) # Pad CMB lensing noise with infinity outside L ranges kellmin, kellmax = list_from_config(Config, lensName, 'Lrange') fnKK = cosmo.noise_pad_infinity( interp1d(ls, Nls, fill_value=np.inf, bounds_error=False), kellmin, kellmax) else: doLens = False fnKK = lambda x: np.nan kellmin = np.inf kellmax = -np.inf # Decide on what ell range to calculate the Fisher matrix ellrange = np.arange(min(tellmin, pellmin, kellmin), max(tellmax, pellmax, kellmax)).astype(int) # Get fsky fsky = Config.getfloat(expName, 'fsky') # Calculate the Fisher matrix and add to other Fishers Fisher = calcFisher(paramList, ellrange, fidCls, dCls, lambda x: fnTT(x) * TCMB**2., lambda x: fnEE(x) * TCMB**2., fnKK, fsky, lensing=doLens, verbose=True) return Fisher
#Initiate foreground class fgs = fgNoises(cc.c, ksz_battaglia_test_csv="data/ksz_template_battaglia.csv", tsz_battaglia_template_csv="data/sz_template_battaglia.csv") #constrained ilc flag 0=False 1=True cf = 0 constraint_tag = ['', '_constrained'] #choose experiment #experimentName = "SO-v3-goal-40" experimentName = "CCATpSOg-v1-40" #experimentName = "CMB-Probe-v4-CBE" #experimentName = "CCATp-v1-40" #experimentName = "CCATp-v1-40-noatm" beams = list_from_config(Config, experimentName, 'beams') noises = list_from_config(Config, experimentName, 'noises') freqs = list_from_config(Config, experimentName, 'freqs') lmax = int(Config.getfloat(experimentName, 'lmax')) lknee = list_from_config(Config, experimentName, 'lknee')[0] alpha = list_from_config(Config, experimentName, 'alpha')[0] fsky = Config.getfloat(experimentName, 'fsky') try: v3mode = Config.getint(experimentName, 'V3mode') except: v3mode = -1 try: noatm = Config.getint(experimentName, 'noatm') except: noatm = False
def sel_counts_from_config(Config,bigDataDir,version,expName,gridName,calName,mexp_edges,z_edges,lkneeTOverride=None,alphaTOverride=None,zmin=-np.inf,zmax=np.inf,mmin=-np.inf,mmax=np.inf,recalculate=False,override_params=None): suffix = "" if lkneeTOverride is not None: suffix += "_"+str(lkneeTOverride) if alphaTOverride is not None: suffix += "_"+str(alphaTOverride) mgrid,zgrid,siggrid = pickle.load(open(bigDataDir+"szgrid_"+expName+"_"+gridName+ "_v" + version+suffix+".pkl",'rb'),encoding='latin1') experimentName = expName cosmoDict = dict_from_section(Config,"params") constDict = dict_from_section(Config,'constants') clusterDict = dict_from_section(Config,'cluster_params') clttfile = Config.get("general","clttfile") if override_params is not None: for key in override_params.keys(): cosmoDict[key] = override_params[key] # print(cosmoDict) cc = ClusterCosmology(cosmoDict,constDict,clTTFixFile = clttfile) beam = list_from_config(Config,experimentName,'beams') noise = list_from_config(Config,experimentName,'noises') freq = list_from_config(Config,experimentName,'freqs') lmax = int(Config.getfloat(experimentName,'lmax')) lknee = float(Config.get(experimentName,'lknee').split(',')[0]) alpha = float(Config.get(experimentName,'alpha').split(',')[0]) fsky = Config.getfloat(experimentName,'fsky') SZProf = SZ_Cluster_Model(cc,clusterDict,rms_noises = noise,fwhms=beam,freqs=freq,lknee=lknee,alpha=alpha) hmf = Halo_MF(cc,mexp_edges,z_edges) hmf.sigN = siggrid.copy() saveId = save_id(expName,gridName,calName,version) # Fiducial number counts if recalculate: from . import counts # get s/n q-bins qs = list_from_config(Config,'general','qbins') qspacing = Config.get('general','qbins_spacing') if qspacing=="log": qbin_edges = np.logspace(np.log10(qs[0]),np.log10(qs[1]),int(qs[2])+1) elif qspacing=="linear": qbin_edges = np.linspace(qs[0],qs[1],int(qs[2])+1) else: raise ValueError calFile = mass_grid_name_owl(bigDataDir,calName) mexp_edges, z_edges, lndM = pickle.load(open(calFile,"rb")) dN_dmqz = hmf.N_of_mqz_SZ(lndM,qbin_edges,SZProf) nmzq = counts.getNmzq(dN_dmqz,mexp_edges,z_edges,qbin_edges) else: nmzq = np.load(fid_file(bigDataDir,saveId)) nmzq = nmzq*fsky zs = (z_edges[1:]+z_edges[:-1])/2. zsel = np.logical_and(zs>zmin,zs<=zmax) M_edges = 10**mexp_edges M = (M_edges[1:]+M_edges[:-1])/2. Mexp = np.log10(M) msel = np.logical_and(Mexp>mmin,Mexp<=mmax) Ns = nmzq.sum(axis=-1)[msel,:][:,zsel] return Ns #.ravel().sum()
import pickle as pickle zz = 0.5 MM = 5.e14 clusterParams = 'LACluster' # from ini file cosmologyName = 'LACosmology' # from ini file experimentName = "v3test" iniFile = "input/params.ini" #iniFile = "input/pipeline.ini" Config = SafeConfigParser() Config.optionxform=str Config.read(iniFile) beam = list_from_config(Config,experimentName,'beams') noise = list_from_config(Config,experimentName,'noises') freq = list_from_config(Config,experimentName,'freqs') lmax = int(Config.getfloat(experimentName,'lmax')) lknee = Config.getfloat(experimentName,'lknee') alpha = Config.getfloat(experimentName,'alpha') fsky = Config.getfloat(experimentName,'fsky') # accuracy params dell=10 pmaxN=5 numps=1000 tmaxN=5 numts=1000
def cluster_fisher_from_config(Config,expName,gridName,calName,fishName, overridePlanck=None,overrideBAO=None,overrideOther=None,pickling=True,s8=False, tauOverride=None,do_clkk_override=None): """ Returns 1. Fisher - the Fisher matrix 2. paramList - final parameter list defining the Fisher contents. Might add extra params (e.g. sigR, bwl) Accepts 1. Config - a ConfigParser object containing the ini file contents 2. expName - name of experiment section in ini file 3. gridName - name of M,q,z grid definition in ini file 4. calName - name of weak lensing calibration section 5. fishName - looks for a section in ini file named "fisher-"+fishName for Fisher options 6. overridePlanck - Fisher matrix to add to upper left corner of original in place of Planck fisher matrix specified in ini. Can be zero. 7. overrideBAO - Fisher matrix to add to upper left corner of original in place of BAO fisher matrix specified in ini. Can be zero. 8. overrideOther - Fisher matrix to add to upper left corner of original in place of "other" fisher matrix specified in ini. Can be zero. """ pickling = False #!!!!! bigDataDir = Config.get('general','bigDataDirectory') version = Config.get('general','version') pzcutoff = Config.getfloat('general','photoZCutOff') fsky = Config.getfloat(expName,'fsky') # Fisher params fishSection = 'fisher-'+fishName paramList = Config.get(fishSection,'paramList').split(',') zs = list_from_config(Config,gridName,'zrange') z_edges = np.arange(zs[0],zs[1]+zs[2],zs[2]) saveId = save_id(expName,gridName,calName,version) derivRoot = deriv_root(bigDataDir,saveId) # Fiducial number counts new_z_edges, N_fid = rebinN(np.load(fid_file(bigDataDir,saveId)),pzcutoff,z_edges)#,mass_bin=None) N_fid = N_fid*fsky # get mass and z grids # ms = list_from_config(Config,gridName,'mexprange') # mexp_edges = np.arange(ms[0],ms[1]+ms[2],ms[2]) # M_edges = 10**mexp_edges # Masses = (M_edges[1:]+M_edges[:-1])/2. # print Masses.shape # print N_fid.shape # print N_fid.sum() # print N_fid[Masses>2.e14,:,:].sum() # sys.exit() print("Effective number of clusters: ", N_fid.sum()) paramList, priorNameList, priorValueList = priors_from_config(Config,expName,calName,fishName,paramList,tauOverride) if s8: zrange = old_div((z_edges[1:]+z_edges[:-1]),2.) zlist = ["S8Z"+str(i) for i in range(len(zrange))] paramList = paramList+zlist Fisher = getFisher(N_fid,paramList,priorNameList,priorValueList,derivRoot,pzcutoff,z_edges,fsky) # Number of non-SZ params (params that will be in Planck/BAO) numCosmo = Config.getint(fishSection,'numCosmo') #numLeft = len(paramList) - numCosmo try: do_cmb_fisher = Config.getboolean(fishSection,"do_cmb_fisher") except: do_cmb_fisher = False try: do_clkk_fisher = Config.getboolean(fishSection,"do_clkk_fisher") except: do_clkk_fisher = False if do_clkk_override is not None: do_clkk_fisher = do_clkk_override if do_clkk_fisher: assert do_cmb_fisher, "Sorry, currently Clkk fisher requires CMB fisher to be True as well." lensName = Config.get(fishSection,"clkk_section") else: lensName = None if do_cmb_fisher: import pyfisher.clFisher as pyfish # Load fiducials and derivatives cmbDerivRoot = Config.get("general","cmbDerivRoot") cmbParamList = paramList[:numCosmo] cmb_fisher_loaded = False if pickling: import time hashval = hash_func(cmbParamList,expName,lensName,do_clkk_fisher,time.strftime('%Y%m%d')) pkl_file = "output/pickledFisher_"+hashval+".pkl" try: cmb_fisher = pickle.load(open(pkl_file,'rb')) cmb_fisher_loaded = True print("Loaded pickled CMB fisher.") except: pass if not(cmb_fisher_loaded): fidCls = np.loadtxt(cmbDerivRoot+'_fCls.csv',delimiter=',') dCls = {} for paramName in cmbParamList: dCls[paramName] = np.loadtxt(cmbDerivRoot+'_dCls_'+paramName+'.csv',delimiter=',') print("Calculating CMB fisher matrix...") print(cmbParamList,expName,lensName) cmb_fisher = pyfish.fisher_from_config(fidCls,dCls,cmbParamList,Config,expName,lensName) if pickling: print("Pickling CMB fisher...") pickle.dump(cmb_fisher,open(pkl_file,'wb')) numLeft = len(paramList) - cmb_fisher.shape[0] print("numLeft , " ,numLeft) cmb_fisher = pad_fisher(cmb_fisher,numLeft) else: cmb_fisher = 0. print(len(paramList)) print(Fisher.shape) from orphics import stats tszFish = stats.FisherMatrix(Fisher+cmb_fisher,param_list=paramList) stats.write_fisher("tsz_fish.txt",tszFish) #np.savetxt("tsz.txt",Fisher) try: otherFishers = Config.get(fishSection,'otherFishers').split(',') except: traceback.print_exc() print("No other fishers found.") otherFishers = [] try: external_param_list = Config.get(fishSection,'external_param_list').split(',') except: traceback.print_exc() external_param_list = "H0,ombh2,omch2,tau,As,ns,mnu,w0,wa".split(',') print("No external param list found in fisher section. Assuming ", external_param_list) nex = len(external_param_list) all_others = np.zeros((nex,nex)) for otherFisherFile in otherFishers: do_other = True try: other_fisher = np.loadtxt(otherFisherFile) except: try: other_fisher = np.loadtxt(otherFisherFile,delimiter=',') #[:numCosmo,:numCosmo] except: print("WARNING: Skipped ",otherFisherFile, " either because it was not found or doesn't have enough elements. This means no external fishers have been added!!!") do_other = False pass if do_other: #numLeft = len(paramList) - other_fisher.shape[0] #other_fisher = pad_fisher(other_fisher,numLeft) print("shapes",other_fisher.shape) all_others += other_fisher otherFish = stats.FisherMatrix(all_others,param_list=external_param_list) for p in otherFish.params: if p not in paramList: otherFish.delete(p) print("Deleted ", p , " from external fishers.") print("External params : ",otherFish.params) #print(otherFish.sigmas()['mnu']*1000.) retfish = (tszFish + otherFish).ix[paramList,paramList] #print(stats.FisherMatrix(retfish.as_matrix(),paramList).marge_var_2param('mnu','w0')) return retfish.as_matrix(), paramList
# load the mass calibration grid mexp_edges, z_edges, lndM = pickle.load(open(calFile, "rb")) mgrid, zgrid, siggrid = pickle.load( open( bigDataDir + "szgrid_" + expName + "_" + gridName + "_v" + version + ".pkl", 'rb')) assert np.all(mgrid == mexp_edges) assert np.all(z_edges == zgrid) saveId = expName + "_" + gridName + "_" + calName + "_v" + version from orphics.io import dict_from_section, list_from_config constDict = dict_from_section(Config, 'constants') clusterDict = dict_from_section(Config, 'cluster_params') beam = list_from_config(Config, expName, 'beams') noise = list_from_config(Config, expName, 'noises') freq = list_from_config(Config, expName, 'freqs') lknee = list_from_config(Config, expName, 'lknee')[0] alpha = list_from_config(Config, expName, 'alpha')[0] fsky = Config.getfloat(expName, 'fsky') try: v3mode = Config.getint(expName, 'V3mode') except: v3mode = -1 clttfile = Config.get('general', 'clttfile') # get s/n q-bins mus = list_from_config(Config, 'general', 'mubins') mubin_edges = np.linspace(mus[0], mus[1], int(mus[2]) + 1)
#fishSection = "mnu-w0-wa" fishSection = "lcdm" noatm = "" #noatm = "-noatm" #cal = "CMB_all_miscentered" cal = "CMB_all" #cal = "owl2" derivSet = "v0.3_ysig_0.127" #gridName = "grid-default" gridName = "grid-high" cosmoFisher = Config.get('fisher-'+fishSection,'saveSuffix') from orphics.io import list_from_config zs = list_from_config(Config,gridName,'zrange') z_edges = np.arange(zs[0],zs[1]+zs[2],zs[2]) zrange = old_div((z_edges[1:]+z_edges[:-1]),2.) zlist = ["S8Z"+str(i) for i in range(len(zrange))] paramList = Config.get('fisher-'+fishSection,'paramList').split(',')+["S8Z20"]#+zlist print(paramList) paramLatexList = Config.get('fisher-'+fishSection,'paramLatexList').split(',') fparams = {} for (key, val) in Config.items('params'): param = val.split(',')[0] fparams[key] = float(param) """RES STUDY""" #cmbfisher3 = getFisher("S4-3.0-0.4"+noatm,gridName,cal,cosmoFisher,paramList,derivSet)
gridName = sys.argv[2] calName = sys.argv[3] fishName = sys.argv[4] iniFile = "input/pipeline.ini" Config = SafeConfigParser() Config.optionxform = str Config.read(iniFile) bigDataDir = Config.get('general', 'bigDataDirectory') version = Config.get('general', 'version') pzcutoff = Config.getfloat('general', 'photoZCutOff') saveId = expName + "_" + gridName + "_" + calName + "_v" + version # get s/n q-bins qs = list_from_config(Config, 'general', 'qbins') qspacing = Config.get('general', 'qbins_spacing') if qspacing == "log": qbins = np.logspace(np.log10(qs[0]), np.log10(qs[1]), int(qs[2])) elif qspacing == "linear": qbins = np.linspace(qs[0], qs[1], int(qs[2])) else: raise ValueError dq = np.diff(qbins) fsky = Config.getfloat(expName, 'fsky') # get mass and z grids ms = list_from_config(Config, gridName, 'mexprange') mexp_edges = np.arange(ms[0], ms[1] + ms[2], ms[2]) zs = list_from_config(Config, gridName, 'zrange')