Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first try at getting lensed CMB maps in #4

Merged
merged 28 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0b0ee74
First pass at cmb sims. Based on actsims.simTools.getActpolCmbsim.
ajvanengelen Dec 6, 2018
f2904f7
tweak
ajvanengelen Dec 6, 2018
fa1d903
tweak
ajvanengelen Dec 6, 2018
7158bbb
tweak
ajvanengelen Dec 6, 2018
cc6026a
mostly cosmetic changes (e.g. remove CamelCase variables) ; but also …
msyriac Dec 6, 2018
5a3cdca
test script for loading cmb sim
msyriac Dec 6, 2018
83a3a24
missing return variable
msyriac Dec 6, 2018
1e1dfb4
test fix
msyriac Dec 6, 2018
4035e61
docstring
msyriac Dec 6, 2018
1c46ab0
tweak
ajvanengelen Dec 6, 2018
bce752d
moved cmb.py
msyriac Dec 20, 2018
550e407
moved cmb.py
msyriac Dec 20, 2018
d0e7e10
improvements to cmb
msyriac Dec 20, 2018
2bb1fe4
unit tests
msyriac Dec 21, 2018
2cc49f1
unit tests
msyriac Dec 21, 2018
af966d7
black formatting
msyriac Dec 21, 2018
c1c034a
use astropy utils to get data path
zonca Jan 2, 2019
09d81fc
rename data preparation so not automatically tested
zonca Jan 2, 2019
b0e8f32
relative import in test
zonca Jan 2, 2019
4d4d0c0
[FIXME, ci] temporarily install so_pysm_models from branch
zonca Jan 2, 2019
c748420
[ci] install PySM on travis
zonca Jan 3, 2019
64202ac
changed google style docstring to numpy style
msyriac Jan 3, 2019
2beccb2
[ci] install so_pysm_models from master
zonca Jan 2, 2019
c960ccc
[ci] install PySM on travis
zonca Jan 3, 2019
598e1ca
[ci] remove OS-X from Travis
zonca Jan 3, 2019
d69761f
removed command line argument from test generator
msyriac Jan 3, 2019
585e6da
fixed conflict
msyriac Jan 3, 2019
37791f0
Argument type in docstring
zonca Jan 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions mapsims/cmb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import healpy as hp, numpy as np
msyriac marked this conversation as resolved.
Show resolved Hide resolved
from pixell import enmap, curvedsky

def get_cmb_sky(iteration_num,
nside = None, #set this if healpix is desired
msyriac marked this conversation as resolved.
Show resolved Hide resolved
shape = None, #set shape and wcs if CAR maps are desired
wcs = None,
lensed = True,
aberrated = False,
pol = True,
cmb_set = 0, #We allow for more than one CMB map per lensing map
cmb_dir = None,
nfreqs = 1):
'''
Return a CMB map from stored alm's. This can be in Healpix format
(if nside is specified) or rectangular pixel format (if wcs and shape are
specified). The lensed alm's are pre-stored.
If rectangular, it returns a stack of enmaps of shape (nfreqs, ncomp, ny, nx).
zonca marked this conversation as resolved.
Show resolved Hide resolved
If Healpix, it will return a numpy array of shape (nfreqs, ncomp, npix)

Args:
iteration_num: integer specifying which sim iteration to use
msyriac marked this conversation as resolved.
Show resolved Hide resolved
nside: nside of healpix map to project alms to. If None, uses
rectangular pixel geometry specified through shape and wcs.
shape: shape of ndmap array (see pixell.enmap)
wcs: World Coordinate System for geometry of map (see pixell.enmap)
lensed: whether to load lensed or unlensed sims
aberrated: whether to load aberrated or unaberrated sims
pol: if True, return ncomp=3 I,Q,U components, else just ncomp=1 I
cmb_set: integer specifying which set of sims to use
cmb_dir: override the default lensed alm directory path
nfreqs: number of copies of the CMB sky to provide. When modulation
is implemented, this argument will be changed to a frequency bandpass
specification that applies frequency-dependent modulation to the sims.

Returns:
output: (nfreqs,ncomp,npix) healpix array if nside is specified, else
returns (nfreqs,ncomp,Ny,Nx) rectangular pixel ndmap.

'''
ncomp = 3 if pol else 1
filename = _get_cmb_map_string(cmb_dir,iteration_num,cmb_set,lensed,aberrated)
#The hdu = (1, 2,3) means get all of T, E, B
#Note the alm's are stored as complex32, so upgrade this for processing
alm_teb = np.complex128(hp.fitsfunc.read_alm(filename, hdu = (1,2,3) if pol else 1))
#Here we can multiply the alms by the appropriate beam;
#hp.sphtfunc.almxfl can be used. Not included yet. Once we
#do, we will have to call the inverse SHT nfreqs times, as in actsims.
if nside is not None:
#Then we are outputting a healpix map
map_tqu = hp.alm2map(alm_teb, nside)
output = np.tile(map_tqu, (nfreqs, 1, 1)) # if nfreqs>1 else map_tqu
#Here we want to multiply the map by the modulation factor. FIXME: not implemented yet
msyriac marked this conversation as resolved.
Show resolved Hide resolved
elif (wcs is not None and shape is not None):
map_tqu = enmap.empty( (ncomp,)+shape[-2:], wcs)
curvedsky.alm2map(alm_teb, map_tqu, spin = [0, 2], verbose = True)
#Tile this to return something of shape (nfreqs, 3, Ny, Nx)
#Why do we need to return this nfreqs times? Because in the
#future we will multiply by a frequency-dependent modulation
#factor.
output = enmap.ndmap(np.tile(mapTqu, (nfreqs, 1, 1, 1)), wcs) #if nfreqs>1 else map_tqu
#Here we want to multiply the map by the modulation factor. FIXME: not implemented yet
else:
raise ValueError("You must specify either nside or both of shape and wcs")
return output

def _get_default_cmb_directory():
#FIXME: remove hard-coding to use preferred directory path system
return "/global/project/projectdirs/sobs/v4_sims/mbs/cmb"
msyriac marked this conversation as resolved.
Show resolved Hide resolved

def _get_cmb_map_string(cmb_dir,iteration_num,cmb_set,lensed,aberrated):
# Implements the CMB lensed alms file naming convention
# Ideally the same function should be used when saving sims
if cmb_dir is None: cmb_dir = _get_default_cmb_directory()
lstring = "Lensed" if lensed else "Unlensed"
abstring = "Abberated" if aberrated else "Unabberated"
cmb_map_type = "%s%sCMB" % (lstring,abstring)
filename = cmb_dir + "/fullsky%s_alm_set%02d_%05d.fits" % ( cmb_map_type, cmb_set , iteration_num)
zonca marked this conversation as resolved.
Show resolved Hide resolved
return filename


15 changes: 15 additions & 0 deletions mapsims/tests/test_cmb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pixell import enmap
import numpy as np
import os,sys
import healpy as hp
from mapsims import cmb # FIXME: relative path import?

def test_load_sim():
zonca marked this conversation as resolved.
Show resolved Hide resolved
nside = 32
# Make an IQU sim
imap = cmb.get_cmb_sky(iteration_num=0,nside = nside)
assert imap.shape[0]==3
# Make an I only sim
imap = cmb.get_cmb_sky(iteration_num=0,nside = nside, pol=False)
assert imap.ndim==1