SDSS Bootcamp

Python exercises

Download data 'a.fits' and 'a.csv' from http://astronomy.nmsu.edu/sdss_bootcamp/

Note: Some of these commands are not necessary for python (instead of a notebook or ipython)

Import the packages we need to run this. You need astropy and matplotlib on your computer. These can be installed through Anaconda

In [2]:
from astropy.io import ascii
from astropy.io import fits
import matplotlib.pyplot as plt
%matplotlib inline

Read in your data

In [3]:
a=ascii.read('a.csv')
f=fits.open('a.fits')
data=f[1].data

Lets start plotting!

In [4]:
plt.plot(a['snr'])
plt.show()
In [5]:
plt.plot(a['snr'],'ro')
plt.show()
In [6]:
plt.plot(a['snr'],'c+')
plt.show()
In [7]:
plt.plot(a['snr'],'m+')
plt.show()
In [24]:
plt.plot(a['snr'],'k^')
plt.show()

Get some more information about our data. What is each column called?

In [25]:
print data.columns
ColDefs(
    name = 'apogee_id'; format = '32A'
    name = 'glon'; format = '1D'
    name = 'glat'; format = '1D'
    name = 'snr'; format = '1E'
    name = 'vhelio_avg'; format = '1E'
    name = 'vscatter'; format = '1E'
    name = 'teff'; format = '1E'
    name = 'logg'; format = '1E'
    name = 'param_m_h'; format = '1E'
    name = 'param_alpha_m'; format = '1E'
)

Now plot two quantities versus each other

In [26]:
plt.plot(a['glon'],a['vhelio_avg'])
plt.show()
In [28]:
plt.plot(a['glon'],a['vhelio_avg'], 'go')
plt.show()

You can add labels to your plot

In [29]:
plt.plot(a['glon'],a['vhelio_avg'], 'go')
plt.xlabel('Galactic longitude')
plt.ylabel('Heliocentric radial velocity')
plt.show()
In [32]:
fig=plt.figure()
ax1=fig.add_subplot(1,2,1)
ax2=fig.add_subplot(1,2,2)
ax1.plot(a['glon'],a['vhelio_avg'],'go')
ax2.plot(a['glat'],a['vhelio_avg'],'go')
ax1.set_xlabel('galactic longitude')
ax2.set_xlabel('galactic latitude')
ax1.set_ylabel('vhelio')
ax2.set_ylabel('vhelio')
plt.show()
In [33]:
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
ax.scatter(a['glon'],a['vhelio_avg'])
Out[33]:
<matplotlib.collections.PathCollection at 0x11196b810>

Make the same plot but use 'scatter' instead of 'plot'. It will do the same thing.

In [35]:
fig=plt.figure()
ax=plt.axes()
ax.scatter(a['glon'],a['vhelio_avg'],c=a['snr'],vmin=80,vmax=200,s=200)
Out[35]:
<matplotlib.collections.PathCollection at 0x110b86a10>

Make the same plot but with different plot sizes depending on galactic latitude

In [36]:
fig=plt.figure()
ax=plt.axes()
ax.scatter(a['glon'],a['vhelio_avg'],c=a['snr'],vmin=80,vmax=200,s=(a['glat']-0.15)/0.15*100.+20)
Out[36]:
<matplotlib.collections.PathCollection at 0x110968c90>