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 all 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
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ env:

# List other runtime dependencies for the package that are available as
# pip packages here.
- PIP_DEPENDENCIES=''
- PIP_DEPENDENCIES='git+https://github.com/bthorne93/PySM_public.git'

# Conda packages for affiliated packages are hosted in channel
# "astropy" while builds for astropy LTS with recent numpy versions
Expand Down Expand Up @@ -72,8 +72,8 @@ matrix:

include:
# Try MacOS X
- os: osx
env: SETUP_CMD='test'
#- os: osx
# env: SETUP_CMD='test'

# Do a coverage test.
- os: linux
Expand Down Expand Up @@ -132,6 +132,7 @@ install:

- git clone --depth 1 git://github.com/astropy/ci-helpers.git
- source ci-helpers/travis/setup_conda.sh
- pip install https://github.com/simonsobs/so_pysm_models/archive/master.zip

msyriac marked this conversation as resolved.
Show resolved Hide resolved
# As described above, using ci-helpers, you should be able to set up an
# environment with dependencies installed using conda and pip, but in some
Expand Down
96 changes: 96 additions & 0 deletions mapsims/cmb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import healpy as hp, numpy as np
import so_pysm_models as spm


def get_cmb_sky(
iteration_num,
nside=None, # set this if healpix is desired
shape=None, # set shape and wcs if CAR maps are desired
wcs=None,
lensed=True,
aberrated=False,
modulation=False,
has_polarization=True,
cmb_set=0, # We allow for more than one CMB map per lensing map
cmb_dir=None,
nu=None,
input_units="uK_RJ",
pixel_indices=None,
):
"""
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).
If HEALPix, it will return a numpy array of shape (nfreqs, ncomp, npix)

Parameters
----------
iteration_num : int
integer specifying which sim iteration to use
nside : int
nside of healpix map to project alms to. If None, uses
rectangular pixel geometry specified through shape and wcs.
shape : tuple of ints
shape of ndmap array (see pixell.enmap)
wcs : str
World Coordinate System for geometry of map (see pixell.enmap)
lensed : bool
Whether to load lensed or unlensed sims
aberrated : bool
Whether to load aberrated or unaberrated sims
pol : bool
If True, return ncomp=3 I,Q,U components, else just ncomp=1 I
cmb_set : int
Integer specifying which set of sims to use
cmb_dir : path
Override the default lensed alm directory path
nfreqs : int
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 numpy array if nside is specified, else
returns (nfreqs,ncomp,Ny,Nx) rectangular pixel ndmap.

"""
ncomp = 3 if has_polarization 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

sgen = spm.PrecomputedAlms(
filename,
target_nside=nside,
target_shape=shape,
target_wcs=wcs,
input_units=input_units,
has_polarization=has_polarization,
pixel_indices=pixel_indices,
)

return sgen.signal(nu=nu, modulation=modulation)


def _get_default_cmb_directory():
# FIXME: remove hard-coding to use preferred directory path system
return "/global/project/projectdirs/sobs/v4_sims/mbs/cmb"


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,
)
return filename
Binary file not shown.
Binary file added mapsims/data/test_map.fits
Binary file not shown.
Loading