### ppImage recipe configuration file
### Here we have turned on our 'best guess' defaults for a simple camera
### Camera-specific options may be turned on by recipes in the camera configuration

# List of tasks to perform
NONLIN             BOOL    FALSE           # Non-linearity correction; not implemented
OVERSCAN           BOOL    TRUE            # Overscan subtraction
NOISEMAP           BOOL    FALSE           # Apply read noise map
BIAS               BOOL    TRUE            # Bias subtraction
DARK               BOOL    TRUE            # Dark subtraction
REMNANCE           BOOL    FALSE           # Remnance masking
SHUTTER            BOOL    FALSE           # Shutter correction
FLAT               BOOL    TRUE            # Flat-field normalisation
MASK               BOOL    FALSE           # Mask bad pixels
MASK.BUILD         BOOL    FALSE           # Build internal mask image
MASK.SATURATED     BOOL    TRUE            # Mask the saturated pixels
MASK.LOW           BOOL    TRUE            # Mask pixels below valid range
MASK.BURNTOOL      BOOL    FALSE           # Mask potential burntool trails
VARIANCE.BUILD     BOOL    FALSE           # Build internal variance image
PATTERN.ROW        BOOL    FALSE           # Row pattern correction
PATTERN.ROW.SUBSET METADATA		   # Menu of chips and/or cells for row pattern correction
END
PATTERN.CELL       BOOL    FALSE           # Cell pattern correction
PATTERN.CELL.SUBSET METADATA		   # Menu of chips and/or cells for cell pattern correction
END
PATTERN.SUBSET	   METADATA
END
FRINGE             BOOL    FALSE           # Fringe subtraction
PHOTOM             BOOL    FALSE           # Source identification and photometry
ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
BACKGROUND         BOOL    FALSE           # Subtract model background?
CHECK.CTE          BOOL    FALSE           # measure CTE errors?
USE.DEBURNED.IMAGE BOOL    FALSE           # use burntool-repaired image?
USE.BEST.BURNTOOL  BOOL    FALSE           # require the best burntooled data
TILTYSTREAK.APPLY  BOOL    FALSE           # apply the 'tiltystreak' tool

GAIN.OVERRIDE		BOOL	TRUE		# Override a non-finite gain?

TILTYSTREAK.BY.CLASS METADATA              # apply the 'tiltystreak' tool
END

# output data formats to save
BASE.FITS          BOOL    FALSE           # Save base detrended image?
BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
CHIP.FITS          BOOL    TRUE            # Save chip-mosaic-ed image? 
CHIP.MASK.FITS     BOOL    FALSE           # Save chip-mosaic-ed image? 
CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
FPA1.FITS          BOOL    FALSE           # Save 1st binned fpa image? 
FPA2.FITS          BOOL    FALSE           # Save 2nd binned fpa image? 
BIN1.FITS          BOOL    FALSE           # Save 1st binned chip image?
BIN2.FITS          BOOL    FALSE           # Save 2nd binned chip image?
BIN1.JPEG          BOOL    FALSE           # Save 1st binned jpeg?
BIN2.JPEG          BOOL    FALSE           # Save 2nd binned jpeg?

# crosstalk measurements : only valid for GPC1 for now
CROSSTALK.MEASURE  BOOL    FALSE           # Subtract model background?
CROSSTALK.CORRECT  BOOL    FALSE           # Subtract model background?

# apply the cell parity flips to the cells?
APPLY.CELL.PARITY  BOOL    FALSE

## if we use multithreaded detrending, detrend this number of rows per thread
SCAN.ROWS        S32     100

# Which regions identified by burntool to mask. 0x01 : only unfit trails, 0x02 "up" trails, 0x04 "down" trails
BURNTOOL.TRAILS     U16 0x07

# Non-linearity correction
NONLIN.SOURCE           STR     CHIP.NAME       # How to determine the source
NONLIN.DATA             STR     nonlin.dat      # Filename for lookup table

# Normalization class
NORM.CLASS              STR     FPA             # How to find the per-class normalizations

OLDDARK		BOOL	FALSE		# Use old-style darks?

# examples of other possible non-linearity correction representations
#@NONLIN.DATA           F32     0.0 1.001 0.001 # A polynomial
#NONLIN.DATA            METADATA                # Source of non-linearity data
#       ccd00           STR     nonlin00.dat    # A lookup table 
#       @ccd01          F32     0.0 1.001 0.001 # A polynomial
#END

# Overscan subtraction
OVERSCAN.SINGLE         BOOL    TRUE            # Reduce overscan to a single value?
OVERSCAN.FIT            STR     NONE            # NONE | POLYNOMIAL | SPLINE
OVERSCAN.ORDER          S32     5               # Order of polynomial fit
OVERSCAN.STAT           STR     MEAN            # MEAN | MEDIAN
OVERSCAN.BOXCAR		S32	0		# Boxcar smoothing radius
OVERSCAN.GAUSS		F32	0.0		# Gaussian smoothing sigma
OVERSCAN.CONSTANT	BOOL	FALSE		# Apply a known, fixed value?
OVERSCAN.VALUE	        F32	0.0		# value to apply, if requested

# Pattern subtraction options
PATTERN.ROW.ORDER      S32     2               # Polynomial order for row pattern
PATTERN.ROW.ITER       S32     4               # Rejection iterations for row pattern
PATTERN.ROW.REJ        F32     2.5             # Rejection threshold for row pattern
PATTERN.ROW.THRESH     F32     20.0            # Ignore threshold for row pattern
PATTERN.ROW.MEAN       STR     SAMPLE_MEAN     # Statistic for mean for row pattern
PATTERN.ROW.STDEV      STR     SAMPLE_STDEV    # Statistic for standard deviation for row pattern
PATTERN.CELL.BG	       STR     ROBUST_MEDIAN   # Statistic for background for cell pattern
PATTERN.CELL.MEAN      STR     SAMPLE_MEDIAN   # Statistic for mean for cell pattern

# Fringe subtraction options
FRINGE.ITER     S32     10              # Number of rejection iterations for fringe solution
FRINGE.REJ      F32     2.0             # Rejection threshold for fringe solution
FRINGE.KEEP     F32     0.5             # Minimum fraction to keep in fringe solution

# Remnance detection options
REMNANCE.SIZE		S32	30		# Size for remnance detection
REMNANCE.THRESH		F32	2.0		# Threshold for remnance detection

# binned output image options
BIN1.XBIN               S32      4
BIN1.YBIN               S32      4
BIN2.XBIN               S32     16
BIN2.YBIN               S32     16

CTE.XBIN                S32     20
CTE.YBIN                S32     20

PPIMAGE.JPEG1  METADATA
  COLORMAP      STR     -greyscale
  SCALE.MODE    STR     RANGE
  SCALE.MIN     F32      -5.0
  SCALE.MAX     F32     +10.0
END

PPIMAGE.JPEG2  METADATA
  COLORMAP      STR     -greyscale
  SCALE.MODE    STR     RANGE
  SCALE.MIN     STR      -5.0
  SCALE.MAX     STR     +10.0
END

FRINGE.FILTERS  MULTI
FRINGE.FILTERS  STR UNDEF

GAIN.OVERRIDE	BOOL	FALSE		# Override a non-finite gain?

DETREND.CONSTRAINTS  METADATA
END

################################################################################
# Diffferent processing options, which may be loaded symbolically
################################################################################

# Standard chip processing
CHIP	METADATA
  BASE.FITS          BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS          BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    TRUE            # Flat-field normalisation
  MASK               BOOL    TRUE            # Mask bad pixels
  FRINGE             BOOL    TRUE            # Fringe subtraction
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM             BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BACKGROUND         BOOL    TRUE            # Subtract background?
END

# Standard chip processing with tiltystreak options (define by camera)
TILTY	METADATA
  BASE.FITS          BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS          BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    TRUE            # Flat-field normalisation
  MASK               BOOL    TRUE            # Mask bad pixels
  FRINGE             BOOL    TRUE            # Fringe subtraction
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM             BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BACKGROUND         BOOL    TRUE            # Subtract background?
END

# Standard chip processing with noisemap options (define by camera)
NOISY	METADATA
  BASE.FITS          BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS          BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    TRUE            # Flat-field normalisation
  MASK               BOOL    TRUE            # Mask bad pixels
  FRINGE             BOOL    TRUE            # Fringe subtraction
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM             BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BACKGROUND         BOOL    TRUE            # Subtract background?
END

# Standard chip processing for areas with high stellar density
CHIP_DENSE_STARS	METADATA
END

# Overscan subtraction only
QUICKMOSAIC        METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL  FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  FPA1.FITS        BOOL    TRUE            # Save 1st binned fpa image? 
  FPA2.FITS        BOOL    TRUE            # Save 2nd binned fpa image? 
END

# No operation except rebinning
PPIMAGE_BIN        METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD	   BOOL	   FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# No operation except rebinning and potential normalisation
PPIMAGE_N          METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD	   BOOL	   FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Overscan subtraction only
PPIMAGE_O            METADATA
  BASE.FITS          BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS     BOOL    TRUE            # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS          BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    FALSE           # Bias subtraction
  DARK               BOOL    FALSE           # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    FALSE           # Flat-field normalisation
  MASK               BOOL    FALSE           # Mask bad pixels
  MASK.BUILD	     BOOL    FALSE	   # Build internal mask?
  FRINGE             BOOL    FALSE           # Fringe subtraction
  PHOTOM             BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
END

# Bias subtraction only
PPIMAGE_B          METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Dark subtraction only
PPIMAGE_D          METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Dark subtraction only
PPIMAGE_M          METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    TRUE            # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Shutter correction only
PPIMAGE_S          METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    TRUE            # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Flat-fielding only
PPIMAGE_F          METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Fringe correction only
PPIMAGE_R          METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    TRUE            # Mask bad pixels
  MASK.BUILD       BOOL    TRUE		   # Build internal mask?
  FRINGE           BOOL    TRUE            # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Photometry only
PPIMAGE_P          METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Photometry & Astrometry
PPIMAGE_A          METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astromtery per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Overscan, bias
PPIMAGE_OB         METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    TRUE            # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Overscan, bias, dark
PPIMAGE_OBD        METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    TRUE            # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    TRUE            # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Overscan, bias, dark -- search for DARK_PREMASK
PPIMAGE_DARKMASK_PROCESS METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    TRUE            # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    TRUE            # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?

  DETREND.CONSTRAINTS  METADATA
    DARK METADATA
      DETTYPE STR DARK_PREMASK
      EXPTIME STR FPA.EXPOSURE
    END
  END   
END

# Chip processing with DARKTEST 
CHIP_DARKTEST METADATA
  BASE.FITS          BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS          BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    TRUE            # Flat-field normalisation
  MASK               BOOL    TRUE            # Mask bad pixels
  FRINGE             BOOL    TRUE            # Fringe subtraction
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM             BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BACKGROUND         BOOL    TRUE            # Subtract background?

  DETREND.CONSTRAINTS  METADATA
    DARK METADATA
      DETTYPE STR DARKTEST
      EXPTIME STR FPA.EXPOSURE
    END
  END   
END

# Overscan, bias, dark, shutter
PPIMAGE_OBDS       METADATA
  BASE.FITS          BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS     BOOL    TRUE            # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    TRUE            # Save base detrended image?
  CHIP.FITS          BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    FALSE           # Flat-field normalisation
  MASK               BOOL    FALSE           # Mask bad pixels
  MASK.BUILD         BOOL    FALSE	     # Build internal mask?
  FRINGE             BOOL    FALSE           # Fringe subtraction
  PHOTOM             BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
END

# used for the pre-mask version of flat-field processing
PPIMAGE_FLATPROC_PREMASK     METADATA
  BASE.FITS          BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS     BOOL    TRUE            # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    TRUE            # Save base detrended image?
  CHIP.FITS          BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    FALSE           # Flat-field normalisation
  MASK               BOOL    FALSE           # Mask bad pixels
  MASK.BUILD         BOOL    FALSE	     # Build internal mask?
  FRINGE             BOOL    FALSE           # Fringe subtraction
  PHOTOM             BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
  MASK.SATURATED     BOOL    FALSE           # DO NOT Mask the saturated pixels

  DETREND.CONSTRAINTS  METADATA
    DARK METADATA
      DETTYPE STR DARK_PREMASK
    END
  END   
END

# Overscan, bias, dark, shutter, flat-field
PPIMAGE_OBDSF      METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    TRUE            # Save base detrended image?
  BASE.VARIANCE.FITS BOOL  TRUE            # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE            # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Overscan, bias, dark, shutter, flat-field -- use FLAT_PREMASK
PPIMAGE_FLATMASK_PROCESS      METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    TRUE            # Save base detrended image?
  BASE.VARIANCE.FITS BOOL  TRUE            # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE            # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?

  DETREND.CONSTRAINTS  METADATA
    DARK METADATA
      DETTYPE STR DARK_PREMASK
      EXPTIME STR FPA.EXPOSURE
    END
    FLAT METADATA
      DETTYPE STR FLAT_PREMASK
      FILTER  STR FPA.FILTERID
    END
  END   
END

# Overscan, bias, dark, shutter, flat-field, fringe
PPIMAGE_OBDSFR     METADATA
  BASE.FITS        BOOL    TRUE            # Save base detrended image?
  BASE.MASK.FITS   BOOL    TRUE            # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    TRUE            # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE            # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE	   # Build internal mask?
  FRINGE           BOOL    TRUE            # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
END

# Overscan, bias, dark, shutter, flat-field, fringe
PPIMAGE_DET_ONLY   METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE            # Flat-field normalisation
  MASK             BOOL    TRUE            # Mask bad pixels
  MASK.BUILD       BOOL    TRUE 	   # Build internal mask?
  FRINGE           BOOL    TRUE            # Fringe subtraction
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
END

# Overscan, bias, dark, shutter, flat-field, fringe, photom
PPIMAGE_OBDSFRP    METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE            # Flat-field normalisation
  MASK             BOOL    TRUE            # Mask bad pixels
  MASK.BUILD       BOOL    TRUE 	   # Build internal mask?
  FRINGE           BOOL    TRUE            # Fringe subtraction
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
END

# Overscan, bias, dark, shutter, flat-field, fringe, photom
PPIMAGE_FLATCORR    METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE            # Flat-field normalisation
  MASK             BOOL    TRUE            # Mask bad pixels
  MASK.BUILD       BOOL    TRUE 	   # Build internal mask?
  FRINGE           BOOL    TRUE            # Fringe subtraction
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?

  DETREND.CONSTRAINTS  METADATA
    FLAT METADATA
      DETTYPE STR FLAT_RAW
    END
  END   
END

# Overscan, bias, dark, shutter, flat-field, fringe, photom
PPIMAGE_FLATTEST   METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE            # Flat-field normalisation
  MASK             BOOL    TRUE            # Mask bad pixels
  MASK.BUILD       BOOL    TRUE 	   # Build internal mask?
  FRINGE           BOOL    TRUE            # Fringe subtraction
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?

  DETREND.CONSTRAINTS  METADATA
    FLAT METADATA
      DETTYPE STR FLATTEST
    END
  END   
END

# Overscan, bias, dark, shutter, flat-field, fringe, photom, astrom
PPIMAGE_OBDSFRA    METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE            # Flat-field normalisation
  MASK             BOOL    TRUE            # Mask bad pixels
  MASK.BUILD       BOOL    TRUE 	   # Build internal mask?
  FRINGE           BOOL    TRUE            # Fringe subtraction
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
END

# Overscan, bias, dark, shutter, flat-field, fringe, photom, astrom
PPIMAGE_MASKPHOT   METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    TRUE            # Mask bad pixels
  MASK.BUILD       BOOL    TRUE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
END

# Save JPEG from BIN1
PPIMAGE_JPEG       METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    TRUE            # Save 2nd binned jpeg?
END

# Save JPEG from BIN1
PPIMAGE_J1         METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    FALSE           # Save 2nd binned jpeg?
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned
END

# Save JPEG from BIN2
PPIMAGE_J2         METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    TRUE            # Save 2nd binned jpeg?
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned
END

# Overscan, bias, photometry, astrometry (for, eg, summit ISP analysis)
PPIMAGE_OA         METADATA
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    TRUE          # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    TRUE          # Save 2nd binned jpeg?
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
END

# Overscan, bias, photometry (for quick analysis)
PPIMAGE_OP         METADATA
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    TRUE            # Save 2nd binned jpeg?
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
END

# Photometry and astrometry only (for pre-reduced data)
PPIMAGE_PA         METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    TRUE            # Save 2nd binned jpeg?
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
END

# JPEG images for different types of residual images
# Save JPEG from BIN1 for bias
PPIMAGE_J1_RESID_B      METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    FALSE           # Save 2nd binned jpeg?
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned

  PPIMAGE.JPEG1    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     VALUE
    SCALE.MIN      F32     -5.0
    SCALE.MAX      F32     +5.0
  END
END

# Save JPEG from BIN2 for bias
PPIMAGE_J2_RESID_B        METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    TRUE            # Save 2nd binned jpeg?
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned

  PPIMAGE.JPEG2    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     VALUE
    SCALE.MIN      F32     -5.0
    SCALE.MAX      F32     +5.0
  END
END

# Save JPEG from BIN1 for flat
PPIMAGE_J1_RESID_F      METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    FALSE           # Save 2nd binned jpeg?
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned

  PPIMAGE.JPEG1    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     FRACTION
    SCALE.MIN      F32     0.95
    SCALE.MAX      F32     1.05
  END
END

# Save JPEG from BIN2 for flat
PPIMAGE_J2_RESID_F        METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    TRUE            # Save 2nd binned jpeg?
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned
		   
  PPIMAGE.JPEG2    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     FRACTION
    SCALE.MIN      F32     0.95
    SCALE.MAX      F32     1.05
  END
END

# Save JPEG from BIN1 for flat
PPIMAGE_J1_RESID_R      METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    FALSE           # Save 2nd binned jpeg?
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned
		   
  PPIMAGE.JPEG1    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     RANGE
    SCALE.MIN      F32     -2.0
    SCALE.MAX      F32     +3.0
  END
END

# Save JPEG from BIN2 for flat
PPIMAGE_J2_RESID_R        METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    TRUE            # Save 2nd binned jpeg?
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned
		   
  PPIMAGE.JPEG2    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     RANGE
    SCALE.MIN      F32     -2.0
    SCALE.MAX      F32     +3.0
  END
END

# JPEG images for different types of positive images
# Save JPEG from BIN1 for bias
PPIMAGE_J1_IMAGE_B      METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    FALSE           # Save 2nd binned jpeg?
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned
		   
  PPIMAGE.JPEG1    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     RANGE
    SCALE.MIN      F32     -5.0
    SCALE.MAX      F32     +5.0
  END
END

# Save JPEG from BIN2 for bias
PPIMAGE_J2_IMAGE_B        METADATA
  OVERSCAN        BOOL    FALSE           # Overscan subtraction
  BIAS            BOOL    FALSE           # Bias subtraction
  DARK            BOOL    FALSE           # Dark subtraction
  SHUTTER         BOOL    FALSE           # Shutter correction
  FLAT            BOOL    FALSE           # Flat-field normalisation
  MASK            BOOL    FALSE           # Mask bad pixels
  MASK.BUILD      BOOL    FALSE 	  # Build internal mask?
  FRINGE          BOOL    FALSE           # Fringe subtraction
  PHOTOM          BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP     BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC   BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS       BOOL    FALSE           # Save base image?
  BASE.MASK.FITS  BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL   FALSE           # Save base detrended image?
  CHIP.FITS       BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS  BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL   FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS       BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS       BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG       BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG       BOOL    TRUE            # Save 2nd binned jpeg?
  BIN1.XBIN       S32     1               # Image is already binned
  BIN1.YBIN       S32     1               # Image is already binned
  BIN2.XBIN       S32     1               # Image is already binned
  BIN2.YBIN       S32     1               # Image is already binned

  PPIMAGE.JPEG2  METADATA
    COLORMAP      STR     -greyscale
    SCALE.MODE    STR     RANGE
    SCALE.MIN     F32     -5.0
    SCALE.MAX     F32     +5.0
  END
END

# Save JPEG from BIN1 for flat
PPIMAGE_J1_IMAGE_F      METADATA
  OVERSCAN        BOOL    FALSE           # Overscan subtraction
  BIAS            BOOL    FALSE           # Bias subtraction
  DARK            BOOL    FALSE           # Dark subtraction
  SHUTTER         BOOL    FALSE           # Shutter correction
  FLAT            BOOL    FALSE           # Flat-field normalisation
  MASK            BOOL    FALSE           # Mask bad pixels
  MASK.BUILD      BOOL    FALSE 	  # Build internal mask?
  FRINGE          BOOL    FALSE           # Fringe subtraction
  PHOTOM          BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP     BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC   BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS       BOOL    FALSE           # Save base image?
  BASE.MASK.FITS  BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL   FALSE           # Save base detrended image?
  CHIP.FITS       BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS  BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL   FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS       BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS       BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG       BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG       BOOL    FALSE           # Save 2nd binned jpeg?
  BIN1.XBIN       S32     1               # Image is already binned
  BIN1.YBIN       S32     1               # Image is already binned
  BIN2.XBIN       S32     1               # Image is already binned
  BIN2.YBIN       S32     1               # Image is already binned

  PPIMAGE.JPEG1  METADATA
    COLORMAP      STR     -greyscale
    SCALE.MODE    STR     RANGE
    SCALE.MIN     F32     -5.0
    SCALE.MAX     F32     +5.0
  END
END

# Save JPEG from BIN2 for flat
PPIMAGE_J2_IMAGE_F        METADATA
  OVERSCAN        BOOL    FALSE           # Overscan subtraction
  BIAS            BOOL    FALSE           # Bias subtraction
  DARK            BOOL    FALSE           # Dark subtraction
  SHUTTER         BOOL    FALSE           # Shutter correction
  FLAT            BOOL    FALSE           # Flat-field normalisation
  MASK            BOOL    FALSE           # Mask bad pixels
  MASK.BUILD      BOOL    FALSE 	  # Build internal mask?
  FRINGE          BOOL    FALSE           # Fringe subtraction
  PHOTOM          BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP     BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC   BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS       BOOL    FALSE           # Save base image?
  BASE.MASK.FITS  BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL   FALSE           # Save base detrended image?
  CHIP.FITS       BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS  BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL   FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS       BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS       BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG       BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG       BOOL    TRUE            # Save 2nd binned jpeg?
  BIN1.XBIN       S32     1               # Image is already binned
  BIN1.YBIN       S32     1               # Image is already binned
  BIN2.XBIN       S32     1               # Image is already binned
  BIN2.YBIN       S32     1               # Image is already binned

  PPIMAGE.JPEG2  METADATA
    COLORMAP      STR     -greyscale
    SCALE.MODE    STR     RANGE
    SCALE.MIN     F32     -5.0
    SCALE.MAX     F32     +5.0
  END
END

# Save JPEG from BIN1 for flat
PPIMAGE_J1_IMAGE_R      METADATA
  OVERSCAN        BOOL    FALSE           # Overscan subtraction
  BIAS            BOOL    FALSE           # Bias subtraction
  DARK            BOOL    FALSE           # Dark subtraction
  SHUTTER         BOOL    FALSE           # Shutter correction
  FLAT            BOOL    FALSE           # Flat-field normalisation
  MASK            BOOL    FALSE           # Mask bad pixels
  MASK.BUILD      BOOL    FALSE 	  # Build internal mask?
  FRINGE          BOOL    FALSE           # Fringe subtraction
  PHOTOM          BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP     BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC   BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS       BOOL    FALSE           # Save base image?
  BASE.MASK.FITS  BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL   FALSE           # Save base detrended image?
  CHIP.FITS       BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS  BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL   FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS       BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS       BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG       BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG       BOOL    FALSE           # Save 2nd binned jpeg?
  BIN1.XBIN       S32     1               # Image is already binned
  BIN1.YBIN       S32     1               # Image is already binned
  BIN2.XBIN       S32     1               # Image is already binned
  BIN2.YBIN       S32     1               # Image is already binned

  PPIMAGE.JPEG1  METADATA
    COLORMAP      STR     -greyscale
    SCALE.MODE    STR     RANGE
    SCALE.MIN     F32     -2.0
    SCALE.MAX     F32     +3.0
  END
END

# Save JPEG from BIN2 for flat
PPIMAGE_J2_IMAGE_R        METADATA
  OVERSCAN        BOOL    FALSE           # Overscan subtraction
  BIAS            BOOL    FALSE           # Bias subtraction
  DARK            BOOL    FALSE           # Dark subtraction
  SHUTTER         BOOL    FALSE           # Shutter correction
  FLAT            BOOL    FALSE           # Flat-field normalisation
  MASK            BOOL    FALSE           # Mask bad pixels
  MASK.BUILD      BOOL    FALSE 	  # Build internal mask?
  FRINGE          BOOL    FALSE           # Fringe subtraction
  PHOTOM          BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP     BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC   BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS       BOOL    FALSE           # Save base image?
  BASE.MASK.FITS  BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL   FALSE           # Save base detrended image?
  CHIP.FITS       BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS  BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL   FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS       BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS       BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG       BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG       BOOL    TRUE            # Save 2nd binned jpeg?
  BIN1.XBIN       S32     1               # Image is already binned
  BIN1.YBIN       S32     1               # Image is already binned
  BIN2.XBIN       S32     1               # Image is already binned
  BIN2.YBIN       S32     1               # Image is already binned

  PPIMAGE.JPEG2  METADATA
    COLORMAP      STR     -greyscale
    SCALE.MODE    STR     RANGE
    SCALE.MIN     F32     -2.0
    SCALE.MAX     F32     +3.0
  END
END

# Save JPEG from BIN1 for mask
PPIMAGE_J1_IMAGE_M        METADATA
  OVERSCAN        BOOL    FALSE           # Overscan subtraction
  BIAS            BOOL    FALSE           # Bias subtraction
  DARK            BOOL    FALSE           # Dark subtraction
  SHUTTER         BOOL    FALSE           # Shutter correction
  FLAT            BOOL    FALSE           # Flat-field normalisation
  MASK            BOOL    FALSE           # Mask bad pixels
  MASK.BUILD      BOOL    FALSE 	  # Build internal mask?
  FRINGE          BOOL    FALSE           # Fringe subtraction
  PHOTOM          BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP     BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC   BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS       BOOL    FALSE           # Save base image?
  BASE.MASK.FITS  BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL   FALSE           # Save base detrended image?
  CHIP.FITS       BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS  BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL   FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS       BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS       BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG       BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG       BOOL    FALSE           # Save 2nd binned jpeg?
  BIN1.XBIN       S32     1               # Image is already binned
  BIN1.YBIN       S32     1               # Image is already binned
  BIN2.XBIN       S32     1               # Image is already binned
  BIN2.YBIN       S32     1               # Image is already binned

  PPIMAGE.JPEG1    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     FRACTION
    SCALE.MIN      F32     0.90
    SCALE.MAX      F32     1.10
  END
END

# Save JPEG from BIN2 for mask
PPIMAGE_J2_IMAGE_M        METADATA
  OVERSCAN        BOOL    FALSE           # Overscan subtraction
  BIAS            BOOL    FALSE           # Bias subtraction
  DARK            BOOL    FALSE           # Dark subtraction
  SHUTTER         BOOL    FALSE           # Shutter correction
  FLAT            BOOL    FALSE           # Flat-field normalisation
  MASK            BOOL    FALSE           # Mask bad pixels
  MASK.BUILD      BOOL    FALSE 	  # Build internal mask?
  FRINGE          BOOL    FALSE           # Fringe subtraction
  PHOTOM          BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP     BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC   BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS       BOOL    FALSE           # Save base image?
  BASE.MASK.FITS  BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL   FALSE           # Save base detrended image?
  CHIP.FITS       BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS  BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL   FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS       BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS       BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG       BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG       BOOL    TRUE            # Save 2nd binned jpeg?
  BIN1.XBIN       S32     1               # Image is already binned
  BIN1.YBIN       S32     1               # Image is already binned
  BIN2.XBIN       S32     1               # Image is already binned
  BIN2.YBIN       S32     1               # Image is already binned

  PPIMAGE.JPEG2    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     FRACTION
    SCALE.MIN      F32     0.95
    SCALE.MAX      F32     1.05
  END
END

# Save JPEG from BIN1 for mask
PPIMAGE_J1_RESID_M        METADATA
  OVERSCAN        BOOL    FALSE           # Overscan subtraction
  BIAS            BOOL    FALSE           # Bias subtraction
  DARK            BOOL    FALSE           # Dark subtraction
  SHUTTER         BOOL    FALSE           # Shutter correction
  FLAT            BOOL    FALSE           # Flat-field normalisation
  MASK            BOOL    FALSE           # Mask bad pixels
  MASK.BUILD      BOOL    FALSE 	  # Build internal mask?
  FRINGE          BOOL    FALSE           # Fringe subtraction
  PHOTOM          BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP     BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC   BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS       BOOL    FALSE           # Save base image?
  BASE.MASK.FITS  BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL   FALSE           # Save base detrended image?
  CHIP.FITS       BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS  BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL   FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS       BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS       BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG       BOOL    TRUE            # Save 1st binned jpeg?
  BIN2.JPEG       BOOL    FALSE           # Save 2nd binned jpeg?
  BIN1.XBIN       S32     1               # Image is already binned
  BIN1.YBIN       S32     1               # Image is already binned
  BIN2.XBIN       S32     1               # Image is already binned
  BIN2.YBIN       S32     1               # Image is already binned

  PPIMAGE.JPEG1    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     FRACTION
    SCALE.MIN      F32     0.95
    SCALE.MAX      F32     1.05
  END
END

# Save JPEG from BIN2 for mask
PPIMAGE_J2_RESID_M        METADATA
  OVERSCAN        BOOL    FALSE           # Overscan subtraction
  BIAS            BOOL    FALSE           # Bias subtraction
  DARK            BOOL    FALSE           # Dark subtraction
  SHUTTER         BOOL    FALSE           # Shutter correction
  FLAT            BOOL    FALSE           # Flat-field normalisation
  MASK            BOOL    FALSE           # Mask bad pixels
  MASK.BUILD      BOOL    FALSE 	  # Build internal mask?
  FRINGE          BOOL    FALSE           # Fringe subtraction
  PHOTOM          BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP     BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC   BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS       BOOL    FALSE           # Save base image?
  BASE.MASK.FITS  BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL   FALSE           # Save base detrended image?
  CHIP.FITS       BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS  BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL   FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS       BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS       BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG       BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG       BOOL    TRUE            # Save 2nd binned jpeg?
  BIN1.XBIN       S32     1               # Image is already binned
  BIN1.YBIN       S32     1               # Image is already binned
  BIN2.XBIN       S32     1               # Image is already binned
  BIN2.YBIN       S32     1               # Image is already binned

  PPIMAGE.JPEG2    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     FRACTION
    SCALE.MIN      F32     0.95
    SCALE.MAX      F32     1.05
  END
END

# JPEG images for different types of residual images
# Save JPEG from BIN1 for bias
PPIMAGE_MOSAIC     METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    FALSE           # Save 2nd binned jpeg?
  FPA1.FITS        BOOL    TRUE            # Save 1st binned fpa image? 
  FPA2.FITS        BOOL    FALSE           # Save 2nd binned fpa image? 
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned
END

# generate chip-mosaiced image
PPIMAGE_CHIPMOSAIC     METADATA
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    FALSE           # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    FALSE           # Flat-field normalisation
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  MASK             BOOL    FALSE           # Mask bad pixels
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BASE.FITS        BOOL    FALSE           # Save base image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    FALSE           # Save chip-mosaic-ed image? 
  BIN1.FITS        BOOL    FALSE           # Save 1st binned chip image?
  BIN2.FITS        BOOL    FALSE           # Save 2nd binned chip image?
  BIN1.JPEG        BOOL    FALSE           # Save 1st binned jpeg?
  BIN2.JPEG        BOOL    FALSE           # Save 2nd binned jpeg?
  FPA1.FITS        BOOL    FALSE            # Save 1st binned fpa image? 
  FPA2.FITS        BOOL    FALSE           # Save 2nd binned fpa image? 
  BIN1.XBIN        S32     1               # Image is already binned
  BIN1.YBIN        S32     1               # Image is already binned
  BIN2.XBIN        S32     1               # Image is already binned
  BIN2.YBIN        S32     1               # Image is already binned
END

# generate CTE map image
PPIMAGE_CTEMAP     METADATA
  BASE.FITS        BOOL    TRUE            # Save base image?
  BASE.MASK.FITS   BOOL    TRUE            # Save base detrended image?
  BASE.VARIANCE.FITS BOOL  TRUE            # Save base detrended image?
  CHIP.FITS        BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    FALSE           # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL  FALSE           # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    FALSE           # Overscan subtraction
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    TRUE            # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE            # Flat-field normalisation
  MASK             BOOL    FALSE           # Mask bad pixels
  MASK.BUILD       BOOL    FALSE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PHOTOM           BOOL    FALSE           # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
  CHECK.CTE        BOOL    TRUE            # measure CTE errors?

  DETREND.CONSTRAINTS  METADATA
    DARK METADATA
      DETTYPE STR DARK_PREMASK
      EXPTIME STR FPA.EXPOSURE
    END
    FLAT METADATA
      DETTYPE STR FLAT_PREMASK
      FILTER  STR FPA.FILTERID
    END
  END   
END

# For SDSS cameras
PPIMAGE_OA_SOFT   METADATA
END

PPIMAGE_OP_SOFT   METADATA
END

#For PR images
PR_DARKTEST_NOSUB	METADATA
  BASE.FITS          BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS          BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    TRUE            # Flat-field normalisation
  MASK               BOOL    TRUE            # Mask bad pixels
  MASK.BUILD         BOOL    TRUE 	     # Build internal mask?
  FRINGE             BOOL    TRUE            # Fringe subtraction
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM             BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BACKGROUND         BOOL    FALSE            # Subtract background?

  DETREND.CONSTRAINTS  METADATA
    DARK METADATA
      DETTYPE STR DARKTEST
      EXPTIME STR FPA.EXPOSURE
    END
  END   
END

PR               METADATA
  BASE.FITS          BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS          BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    TRUE            # Flat-field normalisation
  MASK               BOOL    TRUE            # Mask bad pixels
  MASK.BUILD         BOOL    TRUE 	     # Build internal mask?
  FRINGE             BOOL    TRUE            # Fringe subtraction
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM             BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BACKGROUND         BOOL    FALSE            # Subtract background?
END

PR_NOPATTERN      METADATA
  BASE.FITS        BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS   BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS        BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS   BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN         BOOL    TRUE            # Overscan subtraction
  BIAS             BOOL    FALSE           # Bias subtraction
  DARK             BOOL    TRUE            # Dark subtraction
  REMNANCE         BOOL    FALSE           # Remnance masking
  SHUTTER          BOOL    FALSE           # Shutter correction
  FLAT             BOOL    TRUE            # Flat-field normalisation
  MASK             BOOL    TRUE            # Mask bad pixels
  MASK.BUILD       BOOL    TRUE 	   # Build internal mask?
  FRINGE           BOOL    FALSE           # Fringe subtraction
  PATTERN.ROW      BOOL    FALSE           # Subtract pattern noise
  PATTERN.CELL     BOOL    FALSE           # Subtract pattern noise
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM           BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP      BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC    BOOL    FALSE           # Astrometry for mosaic?
  BACKGROUND       BOOL    FALSE            # Subtract background?
  CROSSTALK.MEASURE  BOOL  TRUE            # Subtract model background?
END

# Standard chip processing without any background removal
CHIP_PRESERVE_BG	METADATA
  BASE.FITS          BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS          BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    TRUE            # Flat-field normalisation
  MASK               BOOL    TRUE            # Mask bad pixels
  MASK.BUILD         BOOL    TRUE 	     # Build internal mask?
  PATTERN.ROW        BOOL    FALSE           # Subtract pattern noise
  PATTERN.CELL       BOOL    FALSE           # Subtract pattern noise
  FRINGE             BOOL    TRUE            # Fringe subtraction
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM             BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BACKGROUND         BOOL    FALSE           # Subtract background?
END

# Standard chip processing
CHIP_NOPATTERN	METADATA
  BASE.FITS          BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS          BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    TRUE            # Flat-field normalisation
  MASK               BOOL    TRUE            # Mask bad pixels
  MASK.BUILD         BOOL    TRUE 	     # Build internal mask?
  FRINGE             BOOL    TRUE            # Fringe subtraction
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM             BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BACKGROUND         BOOL    TRUE            # Subtract background?
END

# Standard chip processing for old pre-run5 data
CHIP_PATTERN	METADATA
  BASE.FITS          BOOL    FALSE           # Save base detrended image?
  BASE.MASK.FITS     BOOL    FALSE           # Save base detrended image?
  BASE.VARIANCE.FITS BOOL    FALSE           # Save base detrended image?
  CHIP.FITS          BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.MASK.FITS     BOOL    TRUE            # Save chip-mosaic-ed image? 
  CHIP.VARIANCE.FITS BOOL    TRUE            # Save chip-mosaic-ed image? 
  OVERSCAN           BOOL    TRUE            # Overscan subtraction
  BIAS               BOOL    TRUE            # Bias subtraction
  DARK               BOOL    TRUE            # Dark subtraction
  SHUTTER            BOOL    FALSE           # Shutter correction
  FLAT               BOOL    TRUE            # Flat-field normalisation
  MASK               BOOL    TRUE            # Mask bad pixels
  MASK.BUILD         BOOL    TRUE 	     # Build internal mask?
  FRINGE             BOOL    TRUE            # Fringe subtraction
  BIN1.FITS          BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS          BOOL    TRUE            # Save 2nd binned chip image?
  PHOTOM             BOOL    TRUE            # Source identification and photometry
  ASTROM.CHIP        BOOL    FALSE           # Astrometry per chip?
  ASTROM.MOSAIC      BOOL    FALSE           # Astrometry for mosaic?
  BACKGROUND         BOOL    TRUE            # Subtract background?
  PATTERN.ROW      BOOL    TRUE           # Subtract pattern noise
  PATTERN.CELL     BOOL    FALSE           # Subtract pattern noise

  PATTERN.ROW.SUBSET	METADATA	# List of chips and whether to do row pattern correction
	XY01	BOOL	TRUE
	XY02	BOOL	TRUE
	XY03	BOOL	TRUE
	XY04	BOOL	TRUE
	XY05	BOOL	TRUE
	XY06	BOOL	TRUE
	XY10	BOOL	TRUE
	XY11	BOOL	TRUE
	XY12	BOOL	TRUE
	XY13	BOOL	TRUE
	XY14	BOOL	TRUE
	XY15	BOOL	TRUE
	XY16	BOOL	TRUE
	XY17	BOOL	TRUE
	XY20	BOOL	TRUE
	XY21	BOOL	TRUE
	XY22	BOOL	TRUE
	XY23	BOOL	TRUE
	XY24	BOOL	TRUE
	XY25	BOOL	TRUE
	XY26	BOOL	TRUE
	XY27	BOOL	TRUE
	XY30	BOOL	TRUE
	XY31	BOOL	TRUE
	XY32	BOOL	TRUE
	XY33	BOOL	TRUE
	XY34	BOOL	TRUE
	XY35	BOOL	TRUE
	XY36	BOOL	TRUE
	XY37	BOOL	TRUE
	XY40	BOOL	TRUE
	XY41	BOOL	TRUE
	XY42	BOOL	TRUE
	XY43	BOOL	TRUE
	XY44	BOOL	TRUE
	XY45	BOOL	TRUE
	XY46	BOOL	TRUE
	XY47	BOOL	TRUE
	XY50	BOOL	TRUE
	XY51	BOOL	TRUE
	XY52	BOOL	TRUE
	XY53	BOOL	TRUE
	XY54	BOOL	TRUE
	XY55	BOOL	TRUE
	XY56	BOOL	TRUE
	XY57	BOOL	TRUE
	XY60	BOOL	TRUE
	XY61	BOOL	TRUE
	XY62	BOOL	TRUE
	XY63	BOOL	TRUE
	XY64	BOOL	TRUE
	XY65	BOOL	TRUE
	XY66	BOOL	TRUE
	XY67	BOOL	TRUE
	XY71	BOOL	TRUE
	XY72	BOOL	TRUE
	XY73	BOOL	TRUE
	XY74	BOOL	TRUE
	XY75	BOOL	TRUE
	XY76	BOOL	TRUE
  END
END
