Photometric Calibration of broad-band data for WYSH


July 9th, 2009
Written by David Cook with large chunks taken from Cookbook written by Danny Dale.  

IDL Method

NOTE: This method will give a zeropoint in physical units (W/m^2/DN/s).  In other words
      how many Watts per square meter each count is worth.
      
Setting up input text file
Each night of observing will have its own Landolt and non-Landolt text file.  The program requires 
a text file to be filled out by the user where the name of the file will be "monthdaydayyear.text" 
for each night.  The format of the file is as follows:

NON-LANDOLT
  Night          Fits    ObjName       Filter  AM     ExpTime   Temp(F)    Counts
  oct10112007    a013    bd28          B       1.03   30          53       144843.2
  
LANDOLT
  Night          Fits    ObjName       Filter  AM     ExpTime   Counts
  apr20212009    a019    PG1633+099A   B       1.05   30        89625.8

***NOTE: Naming of the Landolt stars are picky.  Look at landolt.dat to see the exact name of the star.

Obtaining Counts
Use the procedures laid out in the Photometry section to get the counts of each standard star.  
I have made region files for each Landolt field that comes complete with labels for each star.  
These are located in: /data/broadband/calibration/regions/.  It is best to run PHOT in the same 
order for each image, it will be easier when copying the counts into *.txt.  

Using the IDL program
The program is called standardcal.pro and will calibrate both Landolt standards and the 
spectrophotometric standars used for WySH.  
When calibrating Landolt stars the program uses a text file called "landolts.dat" to read 
in the magnitude of the star, calculate its physical unit value in that filter, and is then 
divided by the corrected counts input from each nights text file.  When using spectrophotometric
standards it is the same procedure except the text file's location for each star is hard coded
into the program and is in: /data/broadband/calibration/nonlandolt/spectphotstandards/.

After each night's text file is properly filled out, run the program by:
-->idl
-->standardcal,'monthdaydayyear'               (for landolt stars)
-->standardcal,'monthdaydayyear',/nonlandolt   (for nonlandolt stars)

This will create a "monthdaydayyear".cal file for each night.  It will be formatted so that coopying
and pasting the contents into a master file is quick and easy.

Finally, copy and paste each nights *.cal file into a master file for each filter and add comments 
about each night.  Ex. if it was not photometric or high humidity.  Anything might make you think 
that the night's calibration may not be photometric.


IRAF Method

NOTE: This method gives a zeropoint in magnitudes.


1.  The following procedures have been adapted from 'A User's Guide 
    to Stellar CCD Photometry with IRAF' by Philip Massey and Lindsey 
    Davis (1992).

2.  Copy all calibration images into the appropriate directory along with the log file.

3.  The images should already have been reduced: bias, overscan, trim, and flatfield 
    corrected. 

4.  Check that your header information is correct.
    cl> imhead "image" l+
     or
    > less "image".fit

    Things to look for: 
      1)  Is your airmass entered correctly?
      2)  Is your filter entered correctly?
      3)  Is your exposure time entered correctly?
    Fix any of the above problems using hedit.  Type help hedit for more info.
    cl> hedit a010 filters "V" update+

5.  If you have short exposure times (~few seconds) you may need to correct for the 
    camera shutter opening and closing.  However, most standard star observations are 
    much longer than a few seconds so this correction is negligible.


6.  (optional) In most instances, the airmass recorded in the header is the airmass 
    at the beginning of the observation.  To change this to the 'effective
    airmass', use the task SETAIRMASS.  If the observatory is not specified
    in the header, be sure to fill in the key word "observatory" (For more
    information on this, get help on 'observatory').

    > setairmass a*.fit

     images  =               a*.fit  Input images
    (observa=                 WIRO) Observatory for images
    (intype =            beginning) Input keyword time stamp
    (outtype=            effective) Output airmass time stamp  

    (ra     =                   ra) Right acsension keyword (hours)
    (dec    =                  dec) Declination keyword (degrees)
    (equinox=             objepoch) Equinox keyword (years)
    (st     =             sidetime) Local siderial time keyword (hours)
    (ut     =                   ut) Universal time keyword (hours)
    (date   =             date-obs) Observation date keyword
    (exposur=              exptime) Exposure time keyword (seconds)
    (airmass=              airmass) Airmass keyword (output)
    (utmiddl=             utmiddle) Mid-observation UT keyword (output)
    (scale  =                 750.) The atmospheric scale height

    (show   =                  yes) Print the airmasses and mid-UT?
    (update =                  yes) Update the image header?
    (overrid=                  yes) Override previous assignments?
    (mode   =                   ql)

7.  Print out the latest Landolt paper or search online for findercharts (this should 
    already be convienently been put into a 3 ring binder) and identify/label the 
    standard stars within each field.  Also, only use stars that have more than 5 
    observations for good accuracy.  Then make region files that correspond to each 
    standard field so you can quickly identify which stars are standard stars in your 
    images.  

8.  Check to make sure that the standard stars are not saturated.  Use the IRAF task 
    IMEXAM by typing "r" over each star.  This brings up a radial profile in a tektronix 
    window.  If there is an obvious plateau towards smaller radii then the star is 
    saturated.  Record which stars are saturated or unusable for each image.  If one 
    star in an image is saturated then that star is not useable for any of the images.  

9.  Now you need to make the .mag.1 files which give photometry information to IRAF.  
    For each image you will create one .mag.1 file.  This means that for each image you 
    hit the space bar on each star without quiting the phot program.  Load the DOAPHOT 
    package which contains the phot task.  Make sure to set the zeropoint in the phot 
    parameter file to zero.  For a tutorial on phot see my "photometry process" on my 
    website: http://physics.uwyo.edu/~davec/wiro/photprocess.html.  The choice of aperture 
    is extremely crucial to determining the photometricity of the data.  The idea is that 
    no matter how big your aperture is, it is impossible to gather "all" the light.  So 
    you might as well be consistant in what fraction of the light you miss.  The method 
    is to determine the aperture individually for each star.  When doing this, you can 
    either look to see where the curve of growth for the star magnitude levels off or look 
    to see where the sky level becomes constant.  Hit space bar on each star.  MAKE SURE 
    YOU DO THIS IN THE SAME ORDER FOR EVERY IMAGE IN A FIELD.  I go from left to right.

10. Next you need to create a file which is formatted to be read into IRAF.  Load the 
    package PHOTCAL and run MKNOBSFILE.  Before running this task, you must create a file 
    called "standstars" which matches the different filters for each calibration star.  
    The list should keep the filter sequence that is in the mknobsfile parameter "idfilter".  
    In the list below frame a010 is the V image of 106_700, frame a009 is the R.  Notice
    "idfilter" parameter has the same order.  

    standstars:

    106_700 : a010 a009
    101_324 : 0027 a028

    PACKAGE = photcal
       TASK = mknobsfile

    photfile=              *.mag.1  The input list of APPHOT/DAOPHOT databases
    idfilter=                V, R   The list of filter ids  (I USED V,R)
    imsets  =           standstars  The input image set file
    observat=             nobs.out  The output observations file
    (obspara=                     ) The input observing parameters file
    (obscolu=                  V R) The format of obsparams (I USED V,R)
    (shifts =                     ) The input x and y coordinate shifts file
    (apercor=                     ) The input aperture corrections file
    (apertur=                    1) The aperture number of the extracted magnitu
    (toleran=                   5.) The tolerance in pixels for position matchin
    (allfilt=                   no) Output only objects matched in all filters
    (verify =                   no) Verify interactive user input ?
    (verbose=                  yes) Print status, warning and error messages ?
    (mode   =                   ql)

11. Edit the output of MKNOBSFILE so that each star is correctly named.  Nomenclature 
    is extremely important, since the name is used to match the instrumental magnitude 
    with the appropriate standard magnitude.  Note that the Landolt standards use an 
    underscore, not a hyphen.  If you need to check exactly what a star name will be 
    recognized check the /galphto/stellarphot/Landolts.dat file; this lists all the stars
    that will be recognized.  In addition, remove any star which has extremely large 
    errors associated with it, since it will artificially increase the errors in the 
    photometry.  Also, usually if everything was entered correctly the mags for each star 
    should be around -10 mag.

12. To determine the photometric coefficients use the task STARPHOT inthe package 
    STELLARPHOT which is in GALPHOT.  STELLARPHOT is a nonstandard IRAF package and 
    must be loaded before running.  Make the following changes to your login.cl:

    set      stellarphot=/home/camuy/galaxy/iraf/galphot/jun95/stellarphot/
    task     stellarphot=stellarphot$stellarphot.cl

    Alternatively, if you have already tasked the entire galphot.cl script, these routines 
    will already have been loaded (i.e. task galphot=galphot$galphot.cl).

    The stellarphot package contains the following scripts:
    stellarphot:
         charread - Read a file created with MKNOBSFILE (character filters)
        findcoeff - Determine the color coefficient and zeropoint (magnitudes)
           fndcen - Find the point closest to the one marked
        getcolors - Determine the color coefficient and zeropoint (colors)
    getextinction - Determine the extinction coefficient
     getstandards - Search through standard star tables 
        graphedit - Edit a table graphically (and fit a line)
       mkstandtab - Make a standard star table
          numread - Read a file created with MKNOBSFILE (numerical filters)
          plotfit - Overplot a fit line on the data (y errors)
      pltfitxyerr - Overplot a fit line on the data (x and y errors)
         starphot - Compute all photometric coefficients

    There is a help file for this package within IRAF.  Please use it.

    STARPHOT calculates the photometric coefficients to convert the instrumental
    magnitude into an apparent magnitude on some standard system.  The procedure
    calculates A0, A1, and A2 which fit into the magnitude equation:
	      M = m + A0 + A1*[color] - A2*X
    Where  M  is  the standard magnitude, m is the observed instrumental
    magnitude, X is the airmass of the observation, and the color is
    calculated from the extinction corrected instrumental magnitudes.  This is 
    the same equation that is used in the Galphot calibration package.
    If, for some reason, you do not wish to calculate A2 and/or A1, set
    the parameter compext=no, and/or compcolor=no.  STARPHOT will also calculate
    the color equation (M1-M2) = C0 + C1*(m1-m2) coefficients, if calccolor=yes.
    The photometry fitting routine first calculates a weighted average extinction
    term for all the stars observed more than three times.  This extinction
    term is then used to compute the extinction corrected instrumental magnitudes--
    which are in turn used to compute the instrumental color.  The color term is
    computed from the linear least squares fit of color vs. [M-m'].   The color
    term is then used to compute the zeropoint for each star--the average zero
    point and standard deviation are written to the coefficient file.

    First, you need to modify the parameter file for starphot as shown below.  Some 
    important things to take note of are: set "calcol" "compcol" and "compext" to no
    so that STARPHOT will not calculate a color coefficient and will ask you for 
    exctinction coeficients, make sure you have a comma inbetween the
    filters and colors in "filters" and "colorst", and set zpt options to zero.

    If your filters are labeled by numbers, you must create a file which lists
    the number --> name converstions, eg the file "numtofilt" contains:
    1 U
    2 B
    3 V
    4 R
    5 I


    If your filters are on the Johnson system (UBVRI), the Landolt '83 and '92
    tables are automatically searched.  In addition, you may include your own
    standard star tables (necessary for Gunn or Narrowband filters)--use the
    task MKSTANDTAB to create a tabular form of an ascii file.

    This is the set up for Johnson filters:

    PACKAGE = stellarphot
       TASK = starphot

    infile  =             nobs.out  infiles-- output of MKNOBSFILE
    outtable=                    z  output tables for coefficients
    outfile =                    c  output tables for star zeropoint anddeviation
    (calccol=                   no) calculate the color equations separately?
    (compcol=                   no) compute color term?
    (compext=                   no) compute extinction term?
    (filters=                  V,R) string of filters
    (colorst=                VR,VR) string of colors
    (filters=                    J) Filters are Johnson, Gunn, or NarrowBand [J|G|N]
    (standta=                     ) Standard tables other than Landolt
    (filtert=                    c) numerical or character (n|c)
    (numtofi=                     ) if filtertype=n, file with number to filter conv
    dateobs =       Aug 27/28 2008  date of observations
    (photzp =                   0.) zero point used in phot
    (resetzp=                  yes) set phot zp=0.
    nonstand=                   no  Have you included any non-standard stars? 
    nstandfi=                       file with names of nonstandard stars 
    (numtoex=                    3) min. number of observations to be an extinct. st
    (verbose=                   no) verbose output?
    (keeptab=                   no) keep intermediate tables?
    (infilel=                     )
    (outfile=                     )
    (zpfilel=                     )
    (mode   =                   q1)

    Next, run STARPHOT, it should ask you for your ext coefficients.  Here is a table 
    of values for each broad-band filters to enter:

filter  m/AM  error
   U    0.5   0.02
   B    0.25  0.02
   V    0.15  0.02
   R    0.10  0.02
   I    0.07  0.02

    The color correction will be negligible so enter zero for all and an error of 0.02.  
    Now the fit of all image's zeropoint for each filter will appear in a tektronix window. 
    Sometimes you have to move another window in front of the tektronix window to refresh it. 
    Hit "n" to move to the next filter plot then hit "enter" to exit, all with the cursor 
    in the tektronix window.

13. The 2 output files (z and c; made into z.tab and c.tab by starphot) can only be 
    viewed with the IRAF task tprint.  Look at the c.tab table and make sure that there are 
    no INDEFs, this usually indicates that a star was named improperly.  View the z.tab table 
    to make sure the numbers make physical sense.  Usually a zeropoint of 25 expected.  Make 
    the tables into txt files by typing:
    
    cl> tprint z.tab > zpt_"date".txt

14. Copy the information of the zpt_"date".txt into a zpt_master.txt file so that all of 
    the zeropoints can be tabulated read into a program later.