cmb.py 938 Bytes
Newer Older
Maude Le Jeune's avatar
Maude Le Jeune committed
1 2 3 4 5 6 7 8 9
""" cmb.py

Generate a cmb map from lambda-CDM power spectrum. 
"""

import healpy as hp
import pylab as pl

### Define some global parameters
Maude Le Jeune's avatar
Maude Le Jeune committed
10 11
lst_par = ['lmax', 'nside', 'cmb_unit', 'sim_id', 'input_cl']
lst_tag = lst_par[:-1]
Maude Le Jeune's avatar
Maude Le Jeune committed
12

Maude Le Jeune's avatar
Maude Le Jeune committed
13 14 15
nside  = seg_input.values()[0][0] ## pushed from main
sim_id = seg_input.values()[0][1] ## pushed from main
lmax   = 2*nside
Maude Le Jeune's avatar
Maude Le Jeune committed
16 17 18

### Generate a cmb map
input_cl = "lambda_best_fit.txt"
Maude Le Jeune's avatar
Maude Le Jeune committed
19 20 21
cmb_unit = "uK_CMB"
cmb_cl   = pl.loadtxt(input_cl)[0:lmax+1,0]     ## load cl
cmb_map  = hp.synfast(cmb_cl, nside, lmax=lmax) ## make a map
Maude Le Jeune's avatar
Maude Le Jeune committed
22

Maude Le Jeune's avatar
Maude Le Jeune committed
23
### Save to disk
Maude Le Jeune's avatar
Maude Le Jeune committed
24
cmb_cl_fn  = get_data_fn ('cls_cmb.txt')
Maude Le Jeune's avatar
Maude Le Jeune committed
25
pl.savetxt  (cmb_cl_fn , cmb_cl)
Maude Le Jeune's avatar
Maude Le Jeune committed
26 27 28 29 30
cmb_map_fn = get_data_fn ('map_cmb.fits')
hp.write_map(cmb_map_fn, cmb_map)

### Make a plot
cmb_map_fig = cmb_map_fn.replace('.fits', '.png')
Maude Le Jeune's avatar
Maude Le Jeune committed
31
hp.mollview(cmb_map, title="cmb in %s"%cmb_unit)
Maude Le Jeune's avatar
Maude Le Jeune committed
32 33
pl.savefig (cmb_map_fig)

Maude Le Jeune's avatar
Maude Le Jeune committed
34 35
### Set output : forward as many childs as sim ids
seg_output = [sim_id] 
Maude Le Jeune's avatar
Maude Le Jeune committed
36 37