noise.py 1.03 KB
Newer Older
Maude Le Jeune's avatar
Maude Le Jeune committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
""" noise.py

Generate a noise map from hitcount map.
Compute coupling matrix
"""

import healpy as hp
import pylab as pl

### Define some global parameters
lst_par = ['lmax', 'nside', 'noise_unit', 'seed', 'input_hitcount', 'noise_level']
lst_tag = lst_par[:-2]

nside = seg_input.values()[0]
seed  = seg_input.values()[1] ## actually not use by synfast
lmax  = 2*nside
noise_unit = "K_RJ"


### Generate a noise map
input_hitcount = ""
hitcount = hp.read_map(input_hitcount)
hitcount = hp.ud_grade(hitcount, nside)
hitnside = pl.sqrt(len(hitcount)/12)
hitcount = hitcount * (hitnside/nside)**2
noise_map= pl.random.standard_normal(12*nside*nside)*noise_level / pl.sqrt(hitcount)

### Save it to disk
noise_fn = get_data_fn("map_noise.fits")
hp.write_map(noise_fn, noise_map)

### Compute mll'
mll    = sp.mask2mll (hitcount, lmax)
mll_fn = get_data_fn("mll.dat")
save_products (mll_fn, globals(), ["mll"])

### Make a plot
noise_fig = noise_fn.replace('.fits', '.png')
hp.mollview(noise_map)
pl.savefig (noise_fig)

### Set output
seg_output = [seed]