\documentstyle[graphicx, 11pt,fleqn]{article}
\title{Observing a Variable Star -- A Recipe for Photometry
  \\COSMOS Astronomy Project,
  Summer 2004}
\author{Kathy Cooksey, UC Santa Cruz}
\date{}
%
\topmargin=-1.5cm
\textheight=23.25cm
\textwidth=16cm
\oddsidemargin=0cm
%\evensidemargin= -2cm
%
\begin{document}
\maketitle
\newcommand{\variable}{{\em SZ Her}}
\newcommand{\editor}{{\em Emacs}}
\newcommand{\prompt} [1] {{\tt monster> #1}}
\newcommand {\IRAF} [1] {{\tt cl> #1}}
\newcommand {\noao} [1] {{\tt no> #1}}
\newcommand {\digiphot} [1] {{\tt di> #1}}
\newcommand {\apphot} [1] {{\tt ap> #1}} 
\newcommand {\idl} [1] {{\tt idl> #1}}

Note: this is a recipe-in-progress, complete as possible but perhaps not
comprehenseive. Feedback is welcome.

\section { Starting IRAF and Accessing Data}
{\sc Open IRAF}\\
\prompt xiraf\\
{\bf C}hange {\bf d}irectory to the data directory from the IRAF directory
(just a note: the seemingly random bold-facing of characters is my 
attempt to show you why some commands are what they are):\\
\IRAF cd ../data/szher/jul0804\\
\\
{\sc Start IRAF photometry package}\\
Access {\bf N}ational {\bf O}ptical {\bf A}stronomy {\bf O}bservatory 
utilities:\\
\IRAF noao\\
Access digital (i.e. CCD) photometry utilities:\\
\noao digiphot\\
Access aperture photometry utilities:\\
\digiphot apphot\\
To exit any of these packages but not from IRAF completely, type `bye'. 
To exit IRAF, type `lo' ({\bf l}og {\bf o}ut).\\
\\
{\sc Configure IRAF to recognize Nickel extensions}\\
\apphot show imextn\\
Copy the extensions listed and insert `ccd' as shown below 
(I can show you how to cut and paste easily on the computer):\\
\apphot reset imextn=``oif:imh fxf:fits,fit,{\bf ccd} 
plf:pl qpf:qp stf:hhh,??h''\\
\apphot reset imtype=``fits''\\
\apphot flpr\\


\section { Renaming, Flat Fielding, \& Registering Images}
{\sc Making a simple image {\bf l}i{\bf s}t}\\
\prompt ls *.ccd {\tt >} inname\\
To make an exact {\bf c}o{\bf p}y:\\
\prompt cp inname outname\\
\\
{\sc Editing with \editor}\\
\prompt emacs -nw outname\\
In \editor{} type: \\
{\tt {\em Esc Shift} \% }\\
then you can enter the expression which you want to replace
`.ccd' with the new expression `.fits'.\\

To replace one occurance, hit {\em Enter}; to replace all occurances, 
hit `!'.  If you want to undo something in \editor, type:\\
{\tt {\em Control Shift} \_}\\
\\
{\sc Changing names}\\
\apphot imcopy @inname @outname
\\
{\sc Making a complicated image list}\\
Using information in the image {\bf h}eaders, {\bf select} images based on 
certain keywords:\\
\apphot hselect *.fits \$I ``OBJECT = `bias''' {\tt >} bias\\
\apphot hselect *.fits \$I ``OBJECT = `B flat' \&\& FILTER = 1893'' 
{\tt >} b\_flats\\
\apphot hselect *.fits \$I ``OBJECT = `V flat' \&\& FILTER = 2373'' 
{\tt >} v\_flats\\
\apphot hselect *.fits \$I ``OBJECT = `\variable' \&\& FILTER = 1893'' 
{\tt >} b\_raw\\
\apphot hselect *.fits \$I ``OBJECT = `\variable' \&\& FILTER = 2373'' 
{\tt >} v\_raw\\
Copy the {\em f}\_raw lists to {\em f}\_flatted (bad grammer, I know) and 
{\em f}\_aligned, 
where the {\em f} represents the filter letter (b or v, in our case).
Then edit these lists with \editor{} so that the extension (`.fits') is 
`f.fits' in the {\bf f}lat-fielded list ({\em f}\_flatted) and `r.fits' in the 
aligned, or {\bf r}egistered, list ({\em f}\_aligned).\\
\\
{\sc Flat Fielding}\\
Set important parameters:\\
\apphot epar imcombine
\begin{flushleft}
\begin{verse}
{\tt
  combine = median\\
  reject = minmax\\
  scale = mode\\
}
\end{verse}
\end{flushleft}
(I'm not going to explain what these parameters mean here, but feel
free to ask if you like.) Save ({\bf w}rite) and {\bf q}uit by typing
`:wq' or run immediately by typing `:go'.
If you make a mistake enter, and want to exit without saving, type `:q!'.
To run otherwise, type:\\
\apphot imcombine @b\_flats b\_flat\\
Extract the {\em mean}, or average, value from the 
{\bf im}age {\bf stat}istics:\\
\apphot imstat b\_flat\\
Then normalize the flat by dividing by the mean, with {\bf im}age
{\bf arith}metic:\\
\apphot imarith b\_flat / {\em mean}\\
and make the ``Resultant image'' b\_flat.\\
Repeat above procedure for the V-band images.\\
\\
{\sc Aligning Images}\\
Registering images takes a bit of finesse, and varies from star field to
star field, but for \variable, the following should work (99.9\% guaranteed).
We're interested in aligning the images so that the objects in which we're 
interested appear in the same location in each of our images.  Then when 
we want to know how bright each object is in each image, IRAF knows 
exactly where to locate the objects.\\
First, find a {\em reference} image, one that has a lot of counts in 
\variable{} as well as the comparison stars and has nice, circular stars.
For ambiguously good reasons, find a good reference image for each filter.
Display one image by:\\
\apphot display {\em image} 1\\
We need to determine the pixel coordinates of \variable{} and the comparison
stars. You'll have a star chart, and we'll have discussed which objects to use
as comparisons. To find the coordinates, type {\bf im}age {\bf exam},
after display the reference image:\\
\apphot imexam\\
Now the cursor will be over the image with a blinking circle.  Place it over
\variable{} and hit `a' ({\bf a}perture).  
The coordinates (and other information) will print to
the IRAF window.  Continue placing the cursor over the comparisons and typing
`a'.  When you're done, just {\bf q}uit (`q') and the cursor will return to 
normal. Open a new text file in \editor:\\
\prompt emacs -nw b\_reg.coor\\
Enter the coordinates printed to the IRAF window into the text file, one
object coordinate per line, either
by cutting and pasting or by good, old-fashioned typing.
Now prepare the IRAF utility for our needs:\\
\apphot epar imalign
\begin{flushleft}
\begin{verse}
{\tt
  boxsize = 15\\
  bigbox = 175\\
  lower = 100\\
  shiftim = yes\\
  interp = linear\\
  boundary = nearest\\
  trimima = yes\\
}
\end{verse}
\end{flushleft}
{\bf W}rite and {\bf q}uit (don't `:go' this). We want to save the stuff
that IRAF will print to the screen when we run {\em imalign}, so run it 
as follows:\\
\apphot imalign @b\_flatted {\em reference} b\_reg.coor @b\_aligned {\tt >}
b\_imalign.txt\\
Open up the {\em f}\_imalign.txt file:\\
\prompt more b\_imalign.txt\\
You can move around by hitting the {\em spacebar} to move down and `u'
to move up.  Go to the very end of the file and note the line where it 
says something like:\\
{\tt\#Trim\_Section = [10:1024,11:1024]}\\
We're interested in the numbers before the colons (10 and 11 in this case).
In this example, 10 is the number of pixels cut off in the x-direction 
and 11 in the y-direction.  We need to adjust our {\em f}\_reg.coor file
to account for this so we can use it again:\\
\prompt awk `\{print \$1-10,\$2-11\}' b\_reg.coor {\tt >} b\_reg.coor2\\
Do the same for the V-band images.


\section {Aperture Photometry and Creating a Lightcurve} 
{\sc {\bf Q}uick {\bf Phot}ometry}\\
\apphot epar qphot
\begin{flushleft}
\begin{verse}
{\tt
  image = @b\_aligned\\
  cbox = 8\\
  annulus = 15\\
  dannulus = 5\\
  aperture = 8,10,12,15\\
  coords = b\_reg.coor2\\
  output = b\_mag\\
  zmag = 19.79\\
  exposur = EXPOSURE\\
  filter = FILTER\\
  obstime = TIME\\
}
\end{verse}
\end{flushleft}
Run this (`:go' is good).  The output {\em f}\_mag is a massively unreadable
file, so let's {\bf t}e{\bf x}t {\bf dump} the fields in which we're 
interested.\\
\apphot txdump b\_mag {\tt >} b\_mag.txt\\
The {\tt Fields to be extracted} will be `image otime itime lid mag merr'.
Do the same for the V-band images, and photometry's done.\\
\\
{\sc Creating the Lightcurve}\\
Generating a plot of how \variable's brightness varies over time
(i.e. lightcurve) is a bit more involved.  We now leave the world of IRAF. \\
We need to gather the needed file with the other data which has been collected
for this project (and make sure the names reflect the date of observation):\\
\prompt cd /home/kcooksey/data/szher/jul0804\\
\prompt cp b\_mag.txt ../b\_mag.070804\\
\prompt cd ..\\
We need to order the magnitude files according to the time of observation:\\
\prompt sort -n -k 2.1,2.4 -k 2.5 b\_mag.070804 {\tt >} b\_magsorted.070804\\
Now generate the data file used to generate the lightcurve.\\
\prompt awk -f rearr.awk -v napertures=4 -v useaperture=4 b\_magsorted.070804
{\tt >} b\_lightcurve070804.dat\\
This program is tricky to explain.  It essentially accounts for the
difference in brightness between \variable{} and the comparisons to 
show how \variable{} varies, regardless of observing artifacts 
(e.g. atmosphere).
%The program `rearr.awk', {\bf rearr}anges the information in 
%{\em f}\_magsorted.070804 to make the data for the lightcurve.  
%It essentially averages the magnitudes of the comparisons in each image;
%consider this average magnitude to be one ``constant'' comparison. 
%{\em rearr.awk} calculates the difference between the ``constant'' 
%of the first image to the ``constant'' of each subsequent image. When you
%subtract this difference from the magnitude of \variable{} in the 
%respective image, you've subtracted the change in \variable's magnitude
%due to observation artifacts (e.g. atmosphere), so all you're left with 
%is the real variation in \variable's magnitude.  
This is the nature of differential photometry.\\
Once again, do the same for the V-band images.\\
We'll use an {\em I}nteractive {\em D}ata {\em L}anguage {\em pro}cedure 
(i.e. program) to generate the lightcurve.\\
\prompt idl\\
\idl .r lightcurve\\
\idl lightcurve,`v\_lightcurve070804.dat',`b\_lightcurve070804.dat'\\
This program creates three plots: v\_lightcurve070804.eps,
b\_lightcurve070804.eps, and bv\_lightcurve.eps. This last plot you should 
immediately rename (by {\bf m}o{\bf v}ing the contents to another filename):\\
\prompt mv bv\_lightcurve.eps bv\_lightcurve070804.eps\\
View these files and see all your hard work come to fruition:\\
\prompt gv bv\_lightcurve070804.eps \&\\
\\
{\sc Phase Diagram}\\
A phase diagram is another version of a lightcurve, whereby many obseravtions
are folded together.  It readily displays the shape of the lightcurve, and 
in generating the phase diagram, we learn about its period.\\
We have yet another program to generate the data for the phase diagram:\\
\prompt awk -f fold.awk -v jd=2453195.5 -v refmag=0 -v hc=0.00296 -v E=916.05 b\_lightcurve070804.dat {\tt >} b\_phase070804.dat\\
Now append, or con{\bf cat}enate, this data onto that from previous
observations:\\
\prompt cat b\_phase.dat b\_phase070804.dat {\tt >} b\_phase.dat\\
Once again (again), do the same for the V-band images. 
Open up IDL again and generate the phase diagrams:\\
\idl .r phase\\
\idl phase,`v\_phase.dat',`b\_phase.dat'\\
View the resulting plots (v\_phase.eps, b\_phase.eps, and bv\_phase.eps)
with {\bf G}host{\bf v}iew, as you did with the lightcurve.\\


\end{document}
