carronj / plancklens Goto Github PK
View Code? Open in Web Editor NEWPlanck 2018 lensing pipeline
License: Other
Planck 2018 lensing pipeline
License: Other
Hello:
I was wondering whether you could provide an example about how to use the code to calculate the N1 bias as a python script.
Thanks
Hi,
I have been trying to run qcinv and compare its output to the true solution when using a noise covariance matrix porportional to the identity matrix and no skymap - in this case the matrix A.T N^-1 A + C^-1 is diagonal.
Using a stopping criterion of an error lower than 1e-6, I am finding unexpected discrepencies between the solution found by qcinv and the one computed directly. Here you will find a minimal code:
import numpy as np
import healpy as hp
import qcinv
import utils
import matplotlib.pyplot as plt
from classy import Class
cosmo = Class()
## Setting params
LENSING = 'yes'
OUTPUT_CLASS = 'tCl pCl lCl'
observations = None
COSMO_PARAMS_NAMES = ["n_s", "omega_b", "omega_cdm", "100*theta_s", "ln10^{10}A_s", "tau_reio"]
nside=512
lmax=2*nside
npix = 12*nside**2
def generate_cls(theta, pol = False):
params = {'output': OUTPUT_CLASS,
"modes":"s,t",
"r":0.001,
'l_max_scalars': lmax,
'lensing': LENSING}
d = {name:val for name, val in zip(COSMO_PARAMS_NAMES, theta)}
params.update(d)
cosmo.set(params)
cosmo.compute()
cls = cosmo.lensed_cl(lmax)
# 10^12 parce que les cls sont exprimés en kelvin carré, du coup ça donne une stdd en 10^6
cls_tt = cls["tt"]*2.7255e6**2
if not pol:
cosmo.struct_cleanup()
cosmo.empty()
return cls_tt
else:
cls_ee = cls["ee"]*2.7255e6**2
cls_bb = cls["bb"]*2.7255e6**2
cls_te = cls["te"]*2.7255e6**2
cosmo.struct_cleanup()
cosmo.empty()
return cls_tt, cls_ee, cls_bb, cls_te
COSMO_PARAMS_MEAN_PRIOR = np.array([0.9665, 0.02242, 0.11933, 1.04101, 3.047, 0.0561])
noise_covar_temp = 0.1**2*np.ones(npix)
inv_noise = (1/noise_covar_temp)
beam_fwhm = 0.35
fwhm_radians = (np.pi / 180) * 0.35
bl_gauss = hp.gauss_beam(fwhm=fwhm_radians, lmax=lmax)
### Generating skymap
theta_ = COSMO_PARAMS_MEAN_PRIOR
cls_ = generate_cls(theta_, False)
map_true = hp.synfast(cls_, nside=nside, lmax=lmax, fwhm=beam_fwhm, new=True)
d = map_true
d += np.random.normal(scale=np.sqrt(noise_covar_temp))
#### Setting solver's params
class cl(object):
pass
s_cls = cl
s_cls.cltt = cls_
n_inv_filt = qcinv.opfilt_tt.alm_filter_ninv(inv_noise, bl_gauss)
chain_descr = [
[0, ["diag_cl"], lmax, nside, np.inf, 1.0e-6, qcinv.cd_solve.tr_cg, qcinv.cd_solve.cache_mem()]]
chain = qcinv.multigrid.multigrid_chain(qcinv.opfilt_tt, chain_descr, s_cls, n_inv_filt,
debug_log_prefix=('log_'))
soltn_complex = np.zeros(int(qcinv.util_alm.lmax2nlm(lmax)), dtype=np.complex)
#### Solving
chain.solve(soltn_complex,d)
hp.almxfl(soltn_complex, cls_, inplace=True)
weiner_map_pcg = soltn_complex
##### Computing the exact weiner map:
## comouting b part of the system
b_weiner = hp.almxfl(hp.map2alm(inv_noise * d, lmax=lmax)*(npix/(4*np.pi)), bl_gauss)
inv_cls = np.array([cl if cl != 0 else 0 for cl in cls_])
Sigma = 1 / (inv_cls + inv_noise[0] * (npix / (4 * np.pi)) * bl_gauss ** 2)
##### Solving:
weiner_map_diag = hp.almxfl(b_weiner, Sigma)
##Graphics
pix_map_pcg = hp.alm2map(weiner_map_pcg, lmax=lmax, nside=nside)
pix_map_diag = hp.alm2map(weiner_map_diag, lmax=lmax, nside=nside)
rel_error_pix = np.abs((pix_map_pcg-pix_map_diag)/pix_map_diag)
hp.mollview(rel_error_pix)
plt.show()
plt.boxplot(rel_error_pix, showfliers=True)
plt.show()
plt.boxplot(rel_error_pix, showfliers=False)
plt.show()
Note that with such a choice of beam, noise and resolution, the errors are acceptables on most of the pixels. Here are plots of the map and boxplot (with and without outliers) of relative differences:
Note that keeping all values equal but reducing the resolution increases the errors. For example, with nside = 32, we get the following graphics:
Now the fractional errors are about 1%, which is pretty big... Keeping a high resolution but increasing the noise level has the same effect.
Have you encountered such a behavior ? Am I missing something and using qcinv the wrong way ?
Thank you,
Gabriel.
I managed to run it on windows via Ubuntu WSL!
Things that were a bit confusing:
Starting point: whether to use plancklens or lensit to make noise forecasts..
qe_key is missing from https://plancklens.readthedocs.io/en/latest/qresp.html
Valid values for "ksource", "qe_key" are not obviously documented.
plot_noiselevels is not advertised on home page. Would be easier to just provide a general more-obviously-named N0 function. I made this (which is not totally general -not all keys/legs and no general N_L - but seems to work)
def get_N0(beam_fwhm = 1.4, nlev_t = 5.,nlev_p = None, lmax_CMB= 3000,
lmin_CMB =100, lmax_out=None, cls_len = None, cls_weight = None,
joint_TP=True, ksource = 'p', fname = None):
if nlev_p is None:
nlev_p = nlev_t*np.sqrt(2)
lmax_ivf = lmax_CMB
lmin_ivf = lmin_CMB
lmax_qlm = lmax_out or lmax_ivf
cls_path = os.path.join(os.path.dirname(os.path.abspath(plancklens.__file__)), 'data', 'cls')
cls_len = cls_len or utils.camb_clfile(os.path.join(cls_path, 'FFP10_wdipole_lensedCls.dat'))
cls_weight = cls_weight or utils.camb_clfile(os.path.join(cls_path, 'FFP10_wdipole_lensedCls.dat'))
assert ksource in ['p', 'f']
qe_keys = [ksource + 'tt', ksource+'_p']
if not joint_TP:
qe_keys.append(ksource)
transf = hp.gauss_beam(beam_fwhm / 60. / 180. * np.pi, lmax=lmax_ivf)
Noise_L_T = (nlev_t / 60. /180. * np.pi) ** 2 / transf ** 2
Noise_L_P = (nlev_p / 60. /180. * np.pi) ** 2 / transf ** 2
cls_dat = {
'tt': (cls_len['tt'][:lmax_ivf + 1] + Noise_L_T),
'ee': (cls_len['ee'][:lmax_ivf + 1] + Noise_L_P),
'bb': (cls_len['bb'][:lmax_ivf + 1] + Noise_L_P),
'te': np.copy(cls_len['te'][:lmax_ivf + 1]) }
# 1/(C+N) filter spectra
fal_sepTP = {spec: utils.cli(cls_dat[spec]) for spec in ['tt','ee','bb']}
cls_ivfs_sepTP = {'tt':fal_sepTP['tt'].copy(),
'ee':fal_sepTP['ee'].copy(),
'bb':fal_sepTP['bb'].copy(),
'te':cls_len['te'][:lmax_ivf + 1] * fal_sepTP['tt'] * fal_sepTP['ee']}
fal_jtTP = utils.cl_inverse(cls_dat)
cls_ivfs_jtTP = utils.cl_inverse(cls_dat)
for cls in [fal_sepTP, fal_jtTP, cls_ivfs_sepTP, cls_ivfs_jtTP]:
for cl in cls.values():
cl[:max(1, lmin_ivf)] *= 0.
N0s = {}
N0_curls = {}
for qe_key in qe_keys:
NG, NC, NGC, NCG = nhl.get_nhl(qe_key, qe_key, cls_weight, cls_ivfs_sepTP, lmax_ivf, lmax_ivf, lmax_out=lmax_qlm)
RG, RC, RGC, RCG = qresp.get_response(qe_key, lmax_ivf, ksource, cls_weight, cls_len, fal_sepTP, lmax_qlm=lmax_qlm)
N0s[qe_key] = utils.cli(RG ** 2) * NG
N0_curls[qe_key]= utils.cli(RC ** 2) * NC
if joint_TP:
NG, NC, NGC, NCG = nhl.get_nhl(ksource, ksource, cls_weight, cls_ivfs_jtTP, lmax_ivf, lmax_ivf, lmax_out=lmax_qlm)
RG, RC, RGC, RCG = qresp.get_response(ksource, lmax_ivf, ksource, cls_weight, cls_len, fal_jtTP, lmax_qlm=lmax_qlm)
N0s[ksource] = utils.cli(RG ** 2) * NG
N0_curls[ksource] = utils.cli(RC ** 2) * NC
return N0s, N0_curls
Hi Julien,
I have a simple question about the parameter file for lensing reconstruction on the Planck public release 3 SMICA CMB map.
What is the content of the dcl
and dcl _dat
files, I thought they were like theory/data CMB power spectra but they don't really look like that, maybe I'm missing something!
Cheers,
~federico
Hi Julien,
just wanted to confirm that the correct way of including other bias-hardened estimators is simply by adding the relevant key in plancklens/qest.py
at this line.
For example, if I want to add the TT patchy-tau (i.e. the amplitude modulation) estimator bias-hardened against lensing I should include ftt_bh_p
.
That's what I did and it looks like it's working, just wanted to double check, cheers!
~federico
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.