Skip to content

Commit

Permalink
reworked README, footprint pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-switzer committed Mar 28, 2016
1 parent ffd895c commit 32ad8d0
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 89 deletions.
112 changes: 47 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,72 @@
# README #
# The LAMBDA footprint library #

This is the README for the CMB footprint module provided by LAMBDA.

## What is this repository for? ##

The CMB footprint module is designed to show where different surveys are
observing on the sky. All surveys for which we provide footprint regions
are listed in the footprint.cfg file.

## How do I get set up? ##

The code runs on both Python 2 (checken on 2.7.10) and Python 3 (checked on
3.4.3). The Python modules that are required for the code to run are
This module overplots cosmological survey regions. The survey specifications
are contained in `footprint.cfg` and rendered as markdown in `footprint.md`.

Required python libraries:
* Numpy
* Matplotlib
* Healpy
* Astropy
* Astropy (coordinate units, WCS)
* Scipy

Numpy, Matplotlib, and Healpy are fairly obvious requirements. Astropy is
needed so that human readable values can be input into the configuration
file. Additionally, it can be used to read in WCS FITS files. Scipy is only
used for the code that converts a WCS map to a Healpix map.
The code runs in both Python 2 (checked on 2.7.10) and Python 3 (checked on
3.4.3). Astropy supports a range of coordinate specifications in the
configuration file.

To add a new survey, feel free to fork and add survey rectangles and vertices
to the configuration file, or email us that information. The configuration file
format is described below. To add your own healpix file region to specify a
survey, email us and we'll make the binary available on the LAMBDA website.

As long as your PYTHONPATH environment variable points to the directory
where this module is located, the code should be able to run.
Contact: Nathan Miller ([email protected])

## Overview of the library ##
## Overview ##

There are a couple examples on how to run the code shown in the examples/
subdirectory. Additionally, a Jupyter notebook is provided that shows the
results from both of the example scripts. A background for the footprint
is needed for the code to run. Backgrounds can be added to the configuration
file, but will need to be downloaded the first time and the files can be large.
Alternatively, any Healpix map can be input.
The `examples` directory contains several plotting scripts and an ipython
notebook (rendered on github). The healpix regions are large binary files and
are hosted on the LAMBDA website. The first time you run the code, these will
be downloaded to the `maps` directory. Subsequently, the code will only update
a region if its local checksum does not match the library.

There are many different options when plotting the survey footprints. You
can plot using any projection that Healpy provides and use most of the options
that these projections provide. The coordinate system of the background map
and the coordinate system of the plot should be provided though they do have
default values ('G' and 'C' respectively). The coordinate system of each
survey in the configuration file is assumed to be in Equatorial
coordinates, though if an input map is provided instead of using the
definitions in the configuration file, a coordinate system should be provided.
There are many different options when plotting the survey footprints. You can
plot using any projection that Healpy provides and use most of the options that
these projections provide. The coordinate system of the background map and the
coordinate system of the plot should be provided though they do have default
values ('G' and 'C' respectively). The coordinate system of each survey in the
configuration file is assumed to be in Equatorial coordinates, though if an
input map is provided instead of using the definitions in the configuration
file, a coordinate system should be provided.

The input colors can be any string understood by matplotlib or an rgb triplet.
The plotted regions for single survey will have the same color but a
varying (0.5 to 1) alpha depending on the pixel value.
The plotted regions for single survey will have the same color but a varying
alpha depending on the pixel value (survey depth).

A copy of the latest configuration file is additionally stored on LAMBDA and
an option can be set to download the latest version of the configuration file
every time the code is run.

## Types of Configuration File Entries ##

There are several different ways to input surveys to the configuration
file. Here we will go over all the different types. For each types I will
list the different keys that must go in the configuration file for that entry. The
regions are specified as strings in the standard astropy [coordinate format](http://astropy.readthedocs.org/en/latest/coordinates/).
There are several different ways to add surveys to the configuration file. Here
we will go over all the different types. For each types I will list the
different keys that must go in the configuration file for that entry. The
regions are specified as strings in the standard astropy
[coordinate format](http://astropy.readthedocs.org/en/latest/coordinates/).

### Common Keys ###

These are keys that are common to all the different types of configuration file entries.

* **coord** : 'C', 'E', or 'G' describing the coordinate system of the input map or
* **coord** : 'C', 'E', or 'G' describing the coordinate system of the input map or
the coordinate system of the input values.
* **instrument** : Instrument with which this data comes from. Multiple entries can
have the same instrument.
* **survey_type** : Either 'background', 'cmb', 'cmbpol', or 'lss'. Used to separate
entries into different tables when we generate a markdown file listing all the
* **survey_type** : e.g. 'background', 'cmb', 'cmbpol', or 'lss'. Used to separate
entries into different tables when we generate a markdown file listing all the
entries in the configuration file.
* **citation** : Citation describing how we got our survey footprint for the given
experiment. Possible entries include a link to a file that we got our data form or
* **citation** : Citation describing how we got our survey footprint for the given
experiment. Possible entries include a link to a file that we got our data form or
and link to a paper from which we pulled values.


Expand All @@ -82,7 +76,7 @@ This reads in a footprint stored as a Healpix file. If the file does not
exist in the path specified when you initialize the class, it will attempt
to download the file from LAMBDA

* **handler** : hpx_file
* **handler** : `hpx_file`
* **file** : filename of the file
* **checksum** : The MD5 checksum of the file. It the checksum does not match the
checksum of the local file, it will attempt to download it from LAMBDA.
Expand Down Expand Up @@ -123,30 +117,18 @@ multiple other surveys listed in the configuration file. This is used so
that a single survey can have multiple entries for different patches, so
we can choose to plot a single patch or multiple patches without the code
thinking they are different surveys. All component maps must have the same
coordinate system because we just sum the Healpix maps together. Additionally,
coordinate system because we just sum the Healpix maps together. Additionally,
all combination maps are normalized to a maximum value of 1.

* **handler** : combination
* **components** : The names of the other entries in the configuration file that
will be combined. Names must be separated by a comma.

## Examples and Config File ##
## Config File ##

Examples are shown in the examples directory. The Jupyter (.ipynb) notebook
(https://github.com/nasa-lambda/cmb_footprint/blob/master/examples/plot_footprints.ipynb)
can be visualized by github. The output is what I get on my computer.

The entries in the config file can be seen at
The entries in the config file can be seen at
https://github.com/nasa-lambda/cmb_footprint/blob/master/footprint_config.md or
http://lambda.gsfc.nasa.gov/toolbox/footprint/configfile.cfm. These pages
are automatically generated by gen_footprint_md.py based on the entries in
the configuration file and is an easier way of seeing what surveys are
http://lambda.gsfc.nasa.gov/toolbox/footprint/configfile.cfm. These pages
are automatically generated by gen_footprint_md.py based on the entries in
the configuration file and is an easier way of seeing what surveys are
predefined.

## Contributing ##

If you want to add a footprint to the library, feel free to submit a pull request.

## Who do I talk to? ##

* Nathan Miller ([email protected])
50 changes: 26 additions & 24 deletions footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, background, nside=None, fignum=None,
self.config = ConfigHandler(config, map_path, nside=nside,
download_config=download_config)

# Could also just call load_survey which will call get_background
# Could also just call load_survey which will call get_background
if isinstance(background, str):
bgmap, coord_bg, unit2 = self.config.load_survey(background,
get_unit=True)
Expand Down Expand Up @@ -140,9 +140,9 @@ def superimpose_hpxmap(self, hpx_map, label, color='red', coord_in='C',
coord = [coord_in, self.coord_plot]

if self.partialmap:
# Colorbar is added to this and then deleted to make sure there is
# room at the bottom of the map for the labels. Margins are to make
# sure the title is not partially off the figure for a square map
# Colorbar is added to this and then deleted to make sure there is
# room at the bottom of the map for the labels. Margins are to make
# sure the title is not partially off the figure for a square map
sub = (1, 1, 1)
margins = (0.01, 0.025, 0.01, 0.03)
map_tmp = H.cartview(hpx_map, title='',
Expand All @@ -159,7 +159,7 @@ def superimpose_hpxmap(self, hpx_map, label, color='red', coord_in='C',
self.fig.delaxes(self.fig.axes[-1])

if cbar:
# First add the new colorbar axis to the figure
# First add the new colorbar axis to the figure
im0 = self.fig.axes[-1].get_images()[0]
box = self.fig.axes[0].get_position()
ax_color = pl.axes([len(self.cbs), box.y0-0.1, 0.05, 0.05])
Expand All @@ -168,7 +168,7 @@ def superimpose_hpxmap(self, hpx_map, label, color='red', coord_in='C',

self.cbs.append(ax_color)

# Readjust the location of every colorbar
# Read just the location of every colorbar
ncb = len(self.cbs)

left = 1.0 / (2.0*ncb) - 0.025
Expand Down Expand Up @@ -422,16 +422,17 @@ def superimpose_hpxmap_contour(self, hpx_map, label, color='red',
Whether to add a colorbar labeling the input map. Default = true.
frac : float, optional
The contour level will be drawn containing `frac' levels of observation time
The contour level will be drawn containing `frac' levels
of observation time.
smooth_map : float
FWHM to smooth the input map (in arcminutes)
'''

idx_nan = (hpx_map == 0)

# Smoothing makes it more likely that contours don't have holes in them,
# but it takes some time to smooth each map
# Smoothing makes it more likely that contours don't have holes,
# but it takes some time to smooth each map
if smooth_map:
hpx_map = H.smoothing(hpx_map, fwhm=np.radians(smooth_map/60.0),
verbose=False)
Expand All @@ -446,9 +447,9 @@ def superimpose_hpxmap_contour(self, hpx_map, label, color='red',
level = determine_level(hpx_map, frac)

if self.partialmap:
# Colorbar is added to this and then deleted to make sure there is
# room at the bottom of the map for the labels. Margins are to make
# sure the title is not partially off the figure for a square map
# Colorbar is added to this and then deleted to make sure there is
# room at the bottom of the map for the labels. Margins are to make
# sure the title is not partially off the figure for a square map
sub = (1, 1, 1)
margins = (0.01, 0.025, 0.01, 0.03)
map_tmp = H.cartcontour(hpx_map, 5, title='', coord=coord,
Expand All @@ -466,16 +467,16 @@ def superimpose_hpxmap_contour(self, hpx_map, label, color='red',
self.fig.delaxes(self.fig.axes[-1])

if cbar:
# Temporary axis with a Healpix map so I can get the correct color
# for the colorbar
# Temporary axis with a Healpix map so I can get the correct color
# for the colorbar
cm1 = util.get_color_map(color)
coord = [coord_in, self.coord_plot]
hpx_map = np.ones(12*32**2)
self.mapview(hpx_map, title='', coord=coord,
cbar=None, fig=self.fig.number, cmap=cm1,
notext=True, flip='astro', **self.kwds)

# First add the new colorbar axis to the figure
# First add the new colorbar axis to the figure
im0 = self.fig.axes[-1].get_images()[0]
box = self.fig.axes[0].get_position()
ax_color = pl.axes([len(self.cbs), box.y0-0.1, 0.05, 0.05])
Expand All @@ -486,7 +487,7 @@ def superimpose_hpxmap_contour(self, hpx_map, label, color='red',

self.fig.delaxes(self.fig.axes[-2])

# Readjust the location of every colorbar
# Readjust the location of every colorbar
ncb = len(self.cbs)

left = 1.0 / (2.0*ncb) - 0.025
Expand Down Expand Up @@ -525,8 +526,8 @@ def superimpose_polygon_outline(self, vertices, label, color='red',

nvertices = len(lons)

# Loop over all vertices and generate lines between adjacent vertices
# in list. This is to ensure the lines are drawn.
# Loop over all vertices and generate lines between adjacent vertices
# in list. This is to ensure the lines are drawn.
linelon = np.array([])
linelat = np.array([])
for i in range(nvertices-1):
Expand All @@ -539,8 +540,8 @@ def superimpose_polygon_outline(self, vertices, label, color='red',
color=color)

if cbar:
# Temporary axis with a Healpix map so I can get the correct color
# for the colorbar
# Temporary axis with a Healpix map so I can get the correct color
# for the colorbar
cm1 = util.get_color_map(color)
coord = [coord_in, self.coord_plot]
hpx_map = np.ones(12*32**2)
Expand All @@ -549,7 +550,7 @@ def superimpose_polygon_outline(self, vertices, label, color='red',
notext=True, flip='astro', **self.kwds)
self.fig.delaxes(self.fig.axes[-1])

# First add the new colorbar axis to the figure
# First add the new colorbar axis to the figure
im0 = self.fig.axes[-1].get_images()[0]
box = self.fig.axes[0].get_position()
ax_color = pl.axes([len(self.cbs), box.y0-0.1, 0.05, 0.05])
Expand All @@ -558,17 +559,18 @@ def superimpose_polygon_outline(self, vertices, label, color='red',

self.cbs.append(ax_color)

# Delete the temporary map
# Delete the temporary map
self.fig.delaxes(self.fig.axes[-2])

# Readjust the location of every colorbar
# Readjust the location of every colorbar
ncb = len(self.cbs)

left = 1.0 / (2.0*ncb) - 0.025
for ax_tmp in self.cbs:
ax_tmp.set_position([left, box.y0-0.1, 0.05, 0.05])
left += 1.0 / ncb


def combine_maps(hpx_maps):
'''Code to combine an array of maps.
Expand All @@ -592,6 +594,7 @@ def combine_maps(hpx_maps):

return map_comb


def determine_level(hpx_map, obs_frac, time=True):
'''Determine the contour level than contains the obs_frac of the total
observation time.
Expand Down Expand Up @@ -641,4 +644,3 @@ def determine_level(hpx_map, obs_frac, time=True):
idx1 = idx2
else:
idx0 = idx2

0 comments on commit 32ad8d0

Please sign in to comment.