Aitoff Projection module

Field of Streams Data (~700 MB)

In [1]:
import numpy as np
import pyfits
import matplotlib.pyplot as plt 
#This will not work unless you download the module at the beginning
#of this file and put it in the same directory or the executable directory
#for python on your machine
import aitoff as at
In [2]:
#Today I will create a simple image of the Field of Streams
#Using the Query from Koposvo (2012)
#Read in fits data for Fields of Stream
dat = pyfits.open("FoS.fit")
In [3]:
#RA and DEC are stored in the fits file and can be called as follows
dat[1].data['DEC']
dat[1].data['RA']
Out[3]:
array([  63.76063806,   63.64820839,   63.65113674, ...,  333.73399812,
        357.42209203,  357.30490763])
In [4]:
#First lets make a simple unprojected image
#RA,l, or other polar coordinate
binner1 = np.linspace(0.,360.,100)
#DEC, b, or other azimuthal coordinate
binner2 = np.linspace(-90.,90.,100)
img, xbins,ybins = np.histogram2d(dat[1].data['RA'],dat[1].data['DEC'],bins=(binner1,binner2))
fig, ax = plt.subplots(figsize=(12.,6.))#create figure in inches
plot = ax.imshow(img.T,origin='lower',extent=[xbins[0],xbins[-1],ybins[0],ybins[-1]],cmap=plt.cm.binary,interpolation='bilinear',aspect='auto')
fig.gca().invert_xaxis()
In [5]:
#Well that was pretty easy but let us put on slightly more detail
#and you can kinda see Sgr
#First lets make a simple unprojected image
#RA,l, or other polar coordinate
binner1 = np.linspace(0.,360.,1000)
#DEC, b, or other azimuthal coordinate
binner2 = np.linspace(-90.,90.,1000)
img, xbins,ybins = np.histogram2d(dat[1].data['RA'],dat[1].data['DEC'],bins=(binner1,binner2))
fig, ax = plt.subplots(figsize=(12.,6.))#create figure in inches
plot = ax.imshow(img.T,origin='lower',extent=[xbins[0],xbins[-1],ybins[0],ybins[-1]],
                 cmap=plt.cm.binary,interpolation='bilinear',aspect='auto',
                 vmax=120,vmin=0)#set the max and min values for the colorbar
#Add a nice little color bar
cbar = fig.colorbar(plot)
cbar.set_label('# of Stars')


#Import a module to make minor ticks
from matplotlib.ticker import AutoMinorLocator
#Set up to tell matplotlib to autoselect minor tick locations
minorLocator   = AutoMinorLocator()

#Actually tell matplotlib to find best minor tick locations
ax.xaxis.set_minor_locator(minorLocator)
ax.yaxis.set_minor_locator(minorLocator)
#Turn minor ticks on
ax.minorticks_on()
#set the width of the ticks
ax.tick_params(which='both',width=1)
#set the length of the major ticks
ax.tick_params(which='major',length=7)
#set length of the minor ticks
ax.tick_params(which='minor',length=3)
ax.set_ylim([-25.,90.])
ax.set_ylabel('DEC',fontsize=18)
ax.set_xlabel('RA',fontsize=18)
fig.gca().invert_xaxis()
In [6]:
#Now that is some Sgr Sgreams
#Now lets get really fancy and use the aitoff projection module I have created
#zero point for aitoff project in RA,l, or Lambda Sgr
# I have tested it for 0,180
lz = 180
#sampling of aitoff projection
#RA,l, or Lambda Sgr
binner1 = np.linspace(-180.,180.,1000)
#DEC, b, or B Sgr
binner2 = np.linspace(-90.,90.,1000)
ra, dec = at.project(dat[1].data['ra'],dat[1].data['DEC'],lz)
#Create density map
img, xbins,ybins = np.histogram2d(ra,dec,bins=(binner1,binner2))
In [7]:
#create a figure to plot the histogram on
fig, ax = plt.subplots(figsize=(12.,6.))#create figure in inches
plot = ax.imshow(img.T,origin='lower',extent=[xbins[0],xbins[-1],ybins[0],ybins[-1]],
                 cmap=plt.cm.binary,interpolation='bicubic',aspect='auto' #try a different interpolation method for the image
                 ,vmax=100)
#Add a nice little color bar
cbar = fig.colorbar(plot)
cbar.set_label('# of Stars')
#put a gid on the plot 
at.gridlines(lz,fig,ax)
#Actually tell matplotlib to find best minor tick locations
ax.xaxis.set_minor_locator(minorLocator)
ax.yaxis.set_minor_locator(minorLocator)
#Turn minor ticks on
ax.minorticks_on()
#set the width of the ticks
ax.tick_params(which='both',width=1)
#set the length of the major ticks
ax.tick_params(which='major',length=7)
#set length of the minor ticks
ax.tick_params(which='minor',length=3)

#remove axis labels because they are meanles in an aitoff projection
fig.gca().get_xaxis().set_visible(False)
fig.gca().get_yaxis().set_visible(False)
fig.gca().invert_xaxis()
In [8]:
#lets put a fancier color bar on too
import matplotlib as mat


#create a figure to plot the histogram on
fig, ax = plt.subplots(figsize=(12.,8.))#create figure in inches
#create a colorbar axis
cax, kw = mat.colorbar.make_axes(ax,pad=.025,shrink=1.0,location='top')


#imshow will also do RGB if you feed it a 3d or 4d array ( the last dimension being opcacity)
plot = ax.imshow(img.T,origin='lower',extent=[xbins[0],xbins[-1],ybins[0],ybins[-1]],
                 cmap=plt.cm.jet,#try a different color scheme for the image
                 interpolation='bicubic',aspect='auto' 
                 ,vmax=100)
#Add a nice little color bar
cbar = fig.colorbar(plot,cax=cax,orientation='horizontal')
cbar.set_label('# of Stars')
cbar.ax.xaxis.set_ticks_position('top')
cbar.set_ticks(np.arange(0,125,25))
cbar.ax.xaxis.set_label_position('top')
#put a gid on the plot 
at.gridlines(lz,fig,ax)
#Actually tell matplotlib to find best minor tick locations
ax.xaxis.set_minor_locator(minorLocator)
ax.yaxis.set_minor_locator(minorLocator)
#Turn minor ticks on
ax.minorticks_on()
#set the width of the ticks
ax.tick_params(which='both',width=1)
#set the length of the major ticks
ax.tick_params(which='major',length=7)
#set length of the minor ticks
ax.tick_params(which='minor',length=3)

#remove axis labels because they are meanles in an aitoff projection
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
#because it drops all axes for whatever reason
cax.get_xaxis().set_visible(True)
ax.set_xlim([180.,-180.])
ax.set_ylim([-90.,90.])
Out[8]:
(-90.0, 90.0)