# BOSS spectrum quick look

How do I take a quick look at the data using IDL, Python, etc. from files on disk?

The methods described below are applicable to BOSS data.

## BOSS Quick Look Using IDL

1. Download the “idlutils” and “idlspec2d” products, set some environment variables, and put the “pro” subdirectories of each in your path:
svn co https://svn.sdss.org/public/repo/sdss/idlutils/trunk idlutils
svn co https://svn.sdss.org/public/repo/sdss/idlutils/trunk idlspec2d


From bash shell:

export IDLUTILS_DIR=${HOME}/idlutils export IDLSPEC2D_DIR=${HOME}/idlspec2d
export IDL_PATH=+${IDLUTILS_DIR}/pro:+${IDLUTILS_DIR}/goddard/pro:+${IDLSPEC2D_DIR}/pro:${IDL_PATH}

2. Set environment variables to point to your downloaded data using this bash command, substituting the name of the directory that holds your data:
export BOSS_SPECTRO_REDUX=[YOUR DIRECTORY HERE]
export RUN2D=v5_5_12
export RUN1D=v5_5_12

3. From IDL, use “plotspec” to display spectra. For example:
IDL> plotspec, 4083, mjd=55443, 101

4. Write a spectrum to an ASCII file
IDL> writespec, 4083, mjd=55443, 101, filename='junk.dat'


Help is available for these commands with “doc_library”:

IDL> doc_library,'plotspec'


## BOSS Quick Look Using SM

The above IDL tools can be used to examining the spectra. Another approach is to use SM tools, written by Michael Strauss. Here’s how to proceed:

1. Pull the reduced spectra (spPlate and spZbest files) off the SAS, creating one directory per plate. (At Princeton, for example, these files are in /u/dss/spectro/boss, and thus have directories called /u/dss/spectro/boss/3615, and so on.)
2. Contact Michael Strauss (strauss at astro dot princeton dot edu) to obtain the SM macro file (called spectro.boss).
3. Enter SM in the directory where spectro.boss lives, and type the following:

First we remove any previous things in SM’s macro buffer:

DELETE HISTORY 0 10000


Then load the macros for BOSS spectra:

restore spectro.boss
play
xterm_l


The last is “xterm underscore ell” for landscape

Now tell SM where to find the spectra. Of course, use the proper path for your own directory structure. Princeton folks need not type this, as it is the current default.

define SPECTRO_DATA ('/u/dss/spectro/boss')


Tell the MJD of the observations you want to plot:

mjd 55098


You are now ready to look at spectra! The basic command is:

plotspec <plate> <fiber>


For plate, use one of the plates available (see above for available plates). For fiber, use any number between 501 and 1000; the spectra from the first spectrograph are not yet available due to the problems with the b1 camera.

You should see a spectrum in one panel, and then 3 smaller panels with various zooms. Superposed will be positions of emission and absorption lines, assuming the redshift given in the spZbest file. You are then put in an interactive mode where you can play with the spectra: zoom in and out, change the assumed redshift, change the smoothing (a boxcar smooth of 5 pixels is the default for plotting), and so on. See all the options by typing h at the prompt.

If you want to look at lots of spectra, use the look command:

look 3615 501 1000


will run plotspec in turn on each of the fibers 501-1000 of plate 3615.

## BOSS Quick Look Using Python

The following script is nothing fancy, and would most likely need to be updated to work with your Python distribution and data path, but gives a simple example of visualizing BOSS spectra with Python. It requires numpy, matplotlib, and pyfits. This worked for Python 2.5 under Mac OS X v10.5.8 in 2009.

#
# Example script for looking at BOSS spectra and redshift fits via Python.
#
# No warranty express or implied.
#

# Imports:
import numpy as n
import pyfits as pf
import matplotlib as mpl
mpl.use('TkAgg')
mpl.interactive(True)
from matplotlib import pyplot as p

# Set topdir:
topdir = '/data/BOSS/spectro/redux/v5_5_12/'

plate = '3621'
mjd = '55104'
spfile = topdir + plate + '/spPlate-' + plate + '-' + mjd + '.fits'
zbfile = topdir + plate + '/spZbest-' + plate + '-' + mjd + '.fits'
hdulist = pf.open(spfile)
wave = 10.**(c0 + c1 * n.arange(npix))
# Following commented-out bit was needed for some of the early redux:
flux = hdulist[0].data
ivar = hdulist[1].data
hdulist.close()
hdulist = 0
hdulist = pf.open(zbfile)
synflux = hdulist[2].data
zstruc = hdulist[1].data
hdulist.close()
hdulist = 0

i = 499
# Set starting fiber point (above), then copy and paste
# the following repeatedly to loop over spectra:
i+=1
# Following commented-out bit was needed for some of the early redux:
#p.plot(wave, (flux[i,:]-bzero) * (ivar[i,:] > 0), 'k', hold=False)
p.plot(wave, flux[i,:] * (ivar[i,:] > 0), 'k', hold=False)
p.plot(wave, synflux[i,:], 'g', hold=True)
p.xlabel('Angstroms')
p.ylabel(bunit)
p.title(zstruc[i].field('class') + ', z = ' + str(zstruc[i].field('z')))