def prepare_inst(thervalue, inst, ellbins, freqs, type, NETs, name, col, fsky, duration, epsilon, camblib=None, dustParams=None): instrument = [inst, ellbins, freqs, type, NETs, fsky, duration, epsilon, name, col] bla = db.get_multiband_covariance(instrument, thervalue, doplot=True, dustParams=dustParams, verbose=True, camblib=camblib) spec = bla[3] all_neq_nh = bla[6] data = {"specin":spec, "inst_info":instrument, "all_neq_nh":all_neq_nh, "camblib":camblib} return data
def dotheplot(r, instruments ,damp=1, marginalized=True, nn=30, rrange=[0.,0.3], dustrange = [0.,25.], saveplot=False): dldust_80_353 = 13.4*damp alphadust = -2.42 betadust = 1.59 Tdust = 19.6 ThedustParams = np.array([dldust_80_353, alphadust, betadust, Tdust]) clf() paramsdefault = np.array([r, dldust_80_353, alphadust, betadust, Tdust]) xlabel('r') ylabel('Likelihood') likelihoods = [] maxlike = [] for instinfo in instruments: ### Calculate input spectra bla = db.get_multiband_covariance(instinfo, r, doplot=False, dustParams=ThedustParams, verbose=True, camblib=camblib) spec = bla[3] if marginalized: ### Marginalizing over Dust Amplitude title('Marginalized over Dust (Amplitude = {0:1.0f} ) ; r = {1:4.2f}'.format(damp,r)) # dust amplitude nvalsmarg = nn valsmarg = linspace(dustrange[0],dustrange[1], nvalsmarg) indexmarg = 1 # r nvals = nn valsamp = linspace(rrange[0], rrange[1], nvals) index = 0 thelike = db.like_1d_marginalize(spec, index, valsamp, indexmarg, valsmarg, instinfo, camblib=camblib, paramsdefault=paramsdefault) else: ### r nvals = nn valsamp = linspace(rrange[0], rrange[1], nvals) index = 0 #### Likelihoods 1D title('Fixed Dust = {0:1.0f} ; r = {1:4.2f}'.format(damp, r)) thelike = db.like_1d(spec, index, valsamp, instinfo, camblib=camblib, paramsdefault=paramsdefault) maxlike.append(np.max(thelike[0])) likelihoods.append(thelike) ylim(0,np.max(np.array(maxlike))*1.2) draw() if saveplot: if marginalized: savefig('db_marginalized_dust={0:1.0f}_r={1:4.2f}.png'.format(damp,r)) else: savefig('db_fixed_dust={0:1.0f}_r={1:4.2f}.png'.format(damp,r)) return likelihoods
def log_likelihood(r=0, dldust_80_353=13.4, alphadust=-2.42, betadust=1.59, Tdust=19.6, data=None): rval = r dpars = np.array([dldust_80_353, alphadust, betadust, Tdust]) specin = data['specin'] instrument_info = data['inst_info'] all_neq_nh = data['all_neq_nh'] camblib = data['camblib'] covmat, covmatnoise, covmatsample, allspec, allvars, ClBBcosmo, all_neq_nh = db.get_multiband_covariance(instrument_info, rval, dustParams=dpars, all_neq_nh=all_neq_nh, camblib=camblib) invcov = np.linalg.inv(covmat + np.random.randn(covmat.shape[0], covmat.shape[1])*1e-10) resid = specin - allspec chi2 = np.sum(np.dot(resid,invcov)*resid) chi2 = chi2 + (dldust_80_353 - 13.4)**2/0.26**2 #From Planck XXX chi2 = chi2 + (alphadust +2.42)**2/0.02**2 #From Planck XXX chi2 = chi2 + (betadust - 1.59)**2/0.11**2 #From Planck XXX section 6.2 chi2 = chi2 + (Tdust - 19.6)**2/0.8**2 #From Planck XXII fig 2 if np.isnan(chi2): chi2=1e10 return -0.5 * chi2
betadust = 1.59 Tdust = 19.6 defaultpars = np.array([dldust_80_353, alphadust, betadust, Tdust]) ### r default value thervalue = 0. ### Camblib ellcamblib = FitsArray('camblib_ell.fits') rcamblib = FitsArray('camblib_r.fits') clcamblib = FitsArray('camblib_cl.fits') camblib = [ellcamblib, rcamblib, clcamblib] ### Instruments netplanck_353 = 850 net150 = 550. net220 = 1450. ### QUBIC 150 GHz two focal planes freqsA = [150] typeA = ['bi'] NETsA = [net150/np.sqrt(2)] nameA = ['150x2'] colA = 'k' fskyA = 0.01 instrumentA = [inst, ellbins, freqsA, typeA, NETsA, fskyA, nameA, colA] bla = db.get_multiband_covariance(instrumentA, thervalue, doplot=True, dustParams=defaultpars, verbose=True, camblib=camblib) specA = bla[3] all_neq_nhA = bla[6] dataA = {"specin":specA, "inst_info":instrumentA, "all_neq_nh":all_neq_nhA, "camblib":camblib}
def truc(thervalue, inst, ellbins, freqs, type, NETs, name, col, fsky, duration, epsilon, camblib=None, dustParams=None): instrument = [inst, ellbins, freqs, type, NETs, fsky, duration, epsilon, name, col] bla = db.get_multiband_covariance(instrument, thervalue, doplot=True, dustParams=dustParams, verbose=True, camblib=camblib) return(bla)
##### Checking Planck 353 GHz noise ########################################### ellav = 0.5 * (ellmin + ellmax) deltal = ellmax - ellmin fskyplanck = 0.01 dlnoise = ellav * (ellav +1) / (2*pi) * np.sqrt(2./((2*ellav+1)*deltal*fskyplanck)) * 0.0151 duration = 1 epsilon =1 freq = [353] type = ['im'] NET = [850] name = ['353'] col = 'r' instinfo = [inst, ellbins, freq, type, NET, fskyplanck, duration, epsilon, name, col] bla = db.get_multiband_covariance(instinfo, r, doplot=True, dustParams=dustParams, verbose=True, camblib=camblib) plot(ellav, dlnoise,'ro') ############################################################################### def dotheplot(r, instruments ,damp=1, marginalized=True, nn=30, rrange=[0.,0.3], dustrange = [0.,25.], saveplot=False): dldust_80_353 = 13.4*damp alphadust = -2.42 betadust = 1.59 Tdust = 19.6 ThedustParams = np.array([dldust_80_353, alphadust, betadust, Tdust]) clf() paramsdefault = np.array([r, dldust_80_353, alphadust, betadust, Tdust]) xlabel('r') ylabel('Likelihood')