CIRSI, PKS 1343
Rough outline of reduction procedure
29 Feb 2000

Use PKS data (runs 15483 to 15522) in /data/H_cass19d/cirsi/aef2/A/PKS1343,
and domeflat observations (runs 15584 to 15591) in ../DFLATS.


1) Make flatfield per chip

  Median combine domeflat observations taken with lamp on (loops 2 to 15).

  Median combine domeflat observations taken with lamp off (loops 2 to 15).

  Subtract combined lamp off from combined lamp on to make flatfield per chip.


2) Make gain map / bad pixel map per chip

  Divide each flatfield by its mode to make gain map per chip.

  Identify bad pixels and set to 0.0 in gain map.
    Pixels with gain < 0.7 or gain > 1.3 set to 0.0.
    Pixels > 5 sigma deviant from local background in gain map set to 0.0.

3) Combine loops
  Combine loops (for each chip each run)
    Scale images by their modes (multiplicative scaling)
    Reject points (clip > 5 sigma from median assuming photon noise)
    Take unweighted mean

  Calculate skyflat (for each chip all runs)
    Scale images by their modes (multiplicative scaling)
    Calculate median image

  Calculate bad pixel / gain map
    Divide flatfield by its mode    
    Set pixels < 0.7 and pixels > 1.3 to 0.0 (bad pixels)

  Comments: 
    Twilight flats are better but still need to reduce existing data
      for which don't have twilight flats

    After normalizing the flatfield, should a smoothed version be subtracted
      out before looking for deviant points?


2) First pass sky subtraction (process each loop separately)

  Calculate sky frame from median of 4 nearest frames in run sequence.

  Do reset correction by subtracting row mode from each row and column mode
    from each column, working quadrant by quadrant.  For chip 1 and 3, the
    rows are corrected first, and for chip 2 and 4 columns are corrected first.

  Combine loops as described above


3) Determine offsets between dither frames in each dither set

  Obtain first guess of dither offsets from RA / DEC keywords in header

  Run sextractor to output segmentation images

  Cross-correlate segmentation images and measure centroid of peak

  Hasn't failed yet (used on NTT and AXAF fields)


4) First pass coaddition

  Create weight map from gain map * NLOOP.  Should weights factor in 
    image variance, sky level, airmass, etc?

  Register images and weight maps using modified bilinear interpolation.

  Coadd registered frames using a weighted, clipped mean.  The clipping
    algorithm depends on the number of valid pixels at each point in
    the stack.  For fewer than 5 pixels, points > 5 sigma from median are 
    rejected assuming photon noise, and if more than 5 values, points are
    rejected using measured standard deviation (median absolute deviation
    from median)

  Subpixel shifting is probably okay for du Pont data, but not in general.


5) Produce object masks to use in second pass

  Run sextractor on combined dither sets to produce segmentation image

  Grow object masks by multiplicative scaling of detection isophote

  Unregister object masks to obtain masks for each frame.


6) Second pass sky subtraction (process each loop separately)

  Calculate sky frame from weighted, clipped mean of 10 nearest frames in run 
    sequence, using object masks from combined dither set.  Weights are
    from gain map and exposure time (NLOOPS).  The clipping algorithm depends
    on number of valid pixels in stack at each point as described above.

  Do reset correction by subtracting row mode from each row and column mode
    from each column, working quadrant by quadrant.  For chip 1 and 3, the
    rows are corrected first, and for chip 2 and 4 columns are corrected first.

  Combine loops as described above.


7) Second pass coaddition 

  Same as first pass, but using second pass sky subtracted frames.


8) Astrometry

  Run initwcs.c to set rough WCS from telescope RA, DEC, and chip number.

  Run match.pl to produce x y RA DEC list, and use IRAF ccmap to read list
    and write FITS header.

  Or, use skycatgaia to slide APM until it lines up with objects in image
    and let gaia set WCS.


9) Make tile

  Run ESO drizzle program
