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

OVERSCAN.SINGLE         BOOL    FALSE            # Reduce overscan to a single value?
OVERSCAN.STAT           STR     MEDIAN
OVERSCAN.BOXCAR         S32     3

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

OLDDARK                 BOOL    FALSE

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

# use the deburned image instead of the raw, if it exists
USE.DEBURNED.IMAGE      BOOL    TRUE           # use burntool-repaired image?
USE.BEST.BURNTOOL	BOOL	TRUE	       # require the best burntooled data
MASK.BURNTOOL           BOOL    FALSE           # Mask potential burntool trails
TILTYSTREAK.APPLY       BOOL    FALSE          # apply the 'tiltystreak' tool
NOISEMAP                BOOL    FALSE          # Apply read noise map

PATTERN.ROW		BOOL 	FALSE	# Do any row pattern correction at all?
PATTERN.ROW.SUBSET	METADATA	# List of chips and whether to do row pattern correction
	XY01	BOOL	FALSE
	XY02	BOOL	FALSE
	XY03	BOOL	FALSE
	XY04	BOOL	FALSE
	XY05	BOOL	FALSE
	XY06	BOOL	FALSE
	XY10	BOOL	FALSE
	XY11	BOOL	FALSE
	XY12	BOOL	FALSE
	XY13	BOOL	FALSE
	XY14	BOOL	FALSE
	XY15	STR     1111111100000000000000000000000000000000000000000000000000000000 # cols: 0
	XY16	BOOL	FALSE
	XY17	BOOL	FALSE
	XY20	BOOL	FALSE
	XY21	BOOL	FALSE
	XY22	BOOL	FALSE
	XY23	BOOL	FALSE
	XY24	BOOL	FALSE
	XY25	BOOL	FALSE
	XY26	BOOL	FALSE
	XY27	STR     1111111111111111111111111111111100000000000000000000000011111111 # cols: 0,1,2,3,7
	XY30	BOOL	FALSE
	XY31	BOOL	FALSE
	XY32	STR     0000000000000000000000001111111100000000000000000000000011111111 # cols: 3,7
	XY33	BOOL	FALSE
	XY34	BOOL	FALSE
	XY35	BOOL	FALSE
	XY36	BOOL	FALSE
	XY37	BOOL	FALSE
	XY40	BOOL	FALSE
	XY41	BOOL	FALSE
	XY42	BOOL	FALSE
	XY43	BOOL	FALSE
	XY44	BOOL	FALSE
	XY45	STR     0000000000000000000000001111111100000000000000000000000011111111 # cols: 3,7
	XY46	BOOL	FALSE
	XY47	STR     1111111100000000000000001111111100000000111111110000000011111111 # cols: 0,3,5,7
	XY50	BOOL	FALSE
	XY51	BOOL	FALSE
	XY52	BOOL	FALSE
	XY53	BOOL	FALSE
	XY54	BOOL	FALSE
	XY55	BOOL	FALSE
	XY56	BOOL	FALSE
	XY57	STR     1111111111111111111111110000000000000000000000001111111111111111 # cols: 0,1,2,6,7
	XY60	STR	0000000000000000000000000000000000000000000001000000000000000000 # cell xy55
	XY61	BOOL	FALSE
	XY62	BOOL	FALSE
	XY63	BOOL	FALSE
	XY64	BOOL	FALSE
	XY65	BOOL	FALSE
	XY66	BOOL	FALSE
	XY67	BOOL	FALSE
	XY71	BOOL	FALSE
	XY72	BOOL	FALSE
	XY73	BOOL	FALSE
	XY74	STR     0000000000000000111111110000000000000000000000000000000011111111 # cols: 2,7
	XY75	BOOL	FALSE
	XY76	BOOL	FALSE
END

PATTERN.CELL	BOOL 	FALSE		# by default, do not do any cell pattern correction
PATTERN.CELL.SUBSET	METADATA	# List of chips and whether to do cell pattern correction
	XY01	BOOL	FALSE
	XY02	BOOL	FALSE
	XY03	BOOL	FALSE
	XY04	BOOL	FALSE
	XY05	BOOL	FALSE
	XY06    STR     11010000000100000001101001000000000000000000000000000000000000000
	XY10	BOOL	FALSE
	XY11	BOOL	FALSE
	XY12	BOOL	FALSE
	XY13	BOOL	FALSE
	XY14	STR     0000000000000000000000000000000000000000000000010000000000101101
	XY15	STR     0011111100011000000001000000010000001001000111110001010000011111
	XY16	STR     0000000100000000000000000000000000000001000000000000000000000000
	XY17	BOOL	FALSE
	XY20	BOOL	FALSE
	XY21	BOOL	FALSE
	XY22	BOOL	FALSE
	XY23	BOOL	FALSE
	XY24	STR     0000000000100000000000000110100000100000001000000011100000000000
	XY25	STR     0100010000001001001011000000001000000111000110000000100000000010
	XY26	STR     0000000000000100000000000000000000001000001000000000000000000000
	XY27	BOOL	FALSE
	XY30	BOOL	FALSE
	XY31	BOOL	FALSE
	XY32	BOOL	FALSE
	XY33	BOOL	FALSE
	XY34	STR     0000000000000000000000000000000000000001000011000000101000111111
	XY35	BOOL	FALSE
	XY36	STR     0000000000000000000000000000000000010000000000000000000000000000
	XY37	STR     0000000000000000000000000000000100010001000000001011000010110110
	XY40	STR     0000000000000000000000000010110000000000000001110000001000011111
	XY41	BOOL	FALSE
	XY42	BOOL	FALSE
	XY43	STR     0000000000000000000000010000000100000000000010000100000100000100
	XY44	BOOL	FALSE
	XY45	BOOL	FALSE
	XY46	BOOL	FALSE
	XY47	BOOL	FALSE
	XY50	BOOL	FALSE
	XY51	BOOL	FALSE
	XY52	BOOL	FALSE
	XY53	BOOL	FALSE
	XY54	BOOL	FALSE
	XY55	BOOL	FALSE
	XY56	BOOL	FALSE
	XY57	BOOL	FALSE
	XY60	BOOL	FALSE
	XY61	BOOL	FALSE
	XY62	STR     0000000000000000000000000000000000001000000000000000000100001010
	XY63	BOOL	FALSE
	XY64	BOOL	FALSE
	XY65	BOOL	FALSE
	XY66	BOOL	FALSE
	XY67	BOOL	FALSE
	XY71	BOOL	FALSE
	XY72	STR     0000000000000000000000000000000000000000000000000000000000000001
	XY73	STR     0001100000000000000000000000001000000000000000000000000000000000
	XY74	BOOL	FALSE
	XY75	BOOL	FALSE
	XY76	BOOL	FALSE
END

TILTYSTREAK.BY.CLASS METADATA              # apply the 'tiltystreak' tool
APPLY.XY01 BOOL FALSE
APPLY.XY03 BOOL FALSE
APPLY.XY04 BOOL FALSE
APPLY.XY05 BOOL FALSE
APPLY.XY06 BOOL FALSE
APPLY.XY10 BOOL FALSE
APPLY.XY11 BOOL FALSE
APPLY.XY13 BOOL FALSE
APPLY.XY14 BOOL FALSE
APPLY.XY15 BOOL FALSE
APPLY.XY16 BOOL FALSE
APPLY.XY17 BOOL FALSE
APPLY.XY20 BOOL FALSE
APPLY.XY21 BOOL FALSE
APPLY.XY23 BOOL FALSE
APPLY.XY24 BOOL FALSE
APPLY.XY25 BOOL FALSE
APPLY.XY26 BOOL FALSE
APPLY.XY30 BOOL FALSE
APPLY.XY31 BOOL FALSE
APPLY.XY33 BOOL FALSE
APPLY.XY34 BOOL FALSE
APPLY.XY35 BOOL FALSE
APPLY.XY36 BOOL FALSE
APPLY.XY37 BOOL FALSE
APPLY.XY40 BOOL FALSE
APPLY.XY41 BOOL FALSE
APPLY.XY42 BOOL FALSE
APPLY.XY43 BOOL FALSE
APPLY.XY44 BOOL FALSE
APPLY.XY46 BOOL FALSE
APPLY.XY50 BOOL FALSE
APPLY.XY52 BOOL FALSE
APPLY.XY53 BOOL FALSE
APPLY.XY54 BOOL FALSE
APPLY.XY56 BOOL FALSE
APPLY.XY60 BOOL FALSE
APPLY.XY62 BOOL FALSE
APPLY.XY63 BOOL FALSE
APPLY.XY64 BOOL FALSE
APPLY.XY66 BOOL FALSE
APPLY.XY71 BOOL FALSE
APPLY.XY72 BOOL FALSE
APPLY.XY73 BOOL FALSE
APPLY.XY74 BOOL FALSE
APPLY.XY76 BOOL FALSE

APPLY.XY02 BOOL TRUE
APPLY.XY12 BOOL TRUE
APPLY.XY22 BOOL TRUE
APPLY.XY27 BOOL TRUE
APPLY.XY32 BOOL TRUE
APPLY.XY45 BOOL TRUE
APPLY.XY47 BOOL TRUE
APPLY.XY51 BOOL TRUE
APPLY.XY55 BOOL TRUE
APPLY.XY57 BOOL TRUE
APPLY.XY61 BOOL TRUE
APPLY.XY65 BOOL TRUE
APPLY.XY67 BOOL TRUE
APPLY.XY75 BOOL TRUE

OPTIONS.XY02 STR mask=0001011100010111000101110001011100010111000101110001011100010111 # cols: 3,5,6,7
OPTIONS.XY12 STR mask=0000011100000111000001110000011100000111111101111111011111110111 # col 5,6,7 (+ 0,1,2,3 for row > 4)
OPTIONS.XY22 STR mask=0001001100010011000100110001001100010011000100110001001100010011 # cols: 3,6,7
OPTIONS.XY27 STR none
OPTIONS.XY32 STR mask=0011011100110111001101110011011100110111001101110011011100110111 # cols: 2,3,5,6,7
OPTIONS.XY45 STR mask=0111111101111111011111111111111111111111111111111111111111111111 # all except 00, 01, 02
OPTIONS.XY47 STR mask=1111111001111110011111100111111001111110011111100111111001111110 # cols: 2,3,4,5,6,7 (add 00)
OPTIONS.XY51 STR mask=0011101100111011001110110011101100111011001110110011101100111011 # cols: 2,3,4,6,7
OPTIONS.XY55 STR mask=0000000011111111111111111111111111111111111111111111111111111111 # all except row 0
OPTIONS.XY57 STR none
OPTIONS.XY61 STR none
OPTIONS.XY65 STR mask=0111011101110111011101110111011101110111011101110111011101110111 # cols: 1,2,3,5,6,7
OPTIONS.XY67 STR mask=1100111111001111110011111100111100000000000000000000000000000000 # cols: 0,1,4,5,6,7 except rows 4,5,6,7
OPTIONS.XY75 STR mask=0001111100011111000111110001111100011111000111110001111100011111 # cols: 3,4,5,6,7

# OPTIONS.XY02 STR mask=00010111.00010111.00010111.00010111.00010111.00010111.00010111.00010111 # cols: 3,5,6,7
END

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

## XXX use these local variations until we are building real detrend images

DETREND.CONSTRAINTS  METADATA
  BIAS METADATA
  END
  DARK METADATA
    EXPTIME STR FPA.EXPOSURE
  END
  FLAT METADATA
    FILTER  STR FPA.FILTERID
  END
  FLATCORR METADATA
    FILTER   STR FPA.FILTERID
  END
  FRINGE METADATA
    FILTER   STR FPA.FILTERID
  END
  SHUTTER METADATA
  END
  MASK METADATA
  END	
  ASTROM METADATA
  END	
  NOISEMAP METADATA
  END	
END

# only apply the fringe for these filters
FRINGE.FILTERS  MULTI
FRINGE.FILTERS	STR y.00000

# 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    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?
  MASK.BURNTOOL    BOOL    TRUE            # Mask potential burntool trails
  PATTERN.ROW      BOOL    TRUE            # Row pattern correction
  PATTERN.CELL	   BOOL	   TRUE		   # Cell pattern correction
  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?
  CROSSTALK.MEASURE  BOOL  TRUE            # Subtract model background?
END

# Standard chip processing with tiltystreak activated
TILTY              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    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?
  MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
  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?
  BACKGROUND         BOOL    TRUE            # Subtract background?
  CROSSTALK.MEASURE  BOOL    TRUE            # Subtract model background?
  TILTYSTREAK.APPLY  BOOL    TRUE            # apply the 'tiltystreak' tool
  NOISEMAP           BOOL    TRUE            # Apply read noise map
END

# Standard chip processing with noisemap activated
NOISY                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    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?
  MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
  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?
  BACKGROUND         BOOL    TRUE            # Subtract background?
  CROSSTALK.MEASURE  BOOL    TRUE            # Subtract model background?
  TILTYSTREAK.APPLY  BOOL    FALSE           # apply the 'tiltystreak' tool
  NOISEMAP           BOOL    TRUE            # Apply read noise map
END

# Standard chip processing for areas with high stellar density
# Turn remnance masking off --- it kills all the detector
CHIP_DENSE_STARS	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
  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

# 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    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    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, 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    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

# 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    FALSE
  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    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?
  MASK.BURNTOOL    BOOL    TRUE            # Mask potential burntool trails
  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?
  BACKGROUND       BOOL    TRUE            # Subtract background?
  CROSSTALK.MEASURE  BOOL  TRUE            # Subtract model background?

  DETREND.CONSTRAINTS  METADATA
    BIAS METADATA
    END
    DARK METADATA
      DETTYPE STR DARKTEST
      EXPTIME STR FPA.EXPOSURE
    END
    FLAT METADATA
      FILTER  STR FPA.FILTERID
    END
    FLATCORR METADATA
      FILTER   STR FPA.FILTERID
    END
    FRINGE METADATA
      FILTER   STR FPA.FILTERID
    END
    SHUTTER METADATA
    END
    MASK METADATA
    END	
    ASTROM METADATA
    END	
    NOISEMAP METADATA
    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    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

# Overscan, bias, dark, shutter
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    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?

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

# Overscan, bias, dark, shutter
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    FALSE           # 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    FALSE           # 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, photom, astrom
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    FALSE           # 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    FALSE           # Fringe subtraction
  BIN1.FITS        BOOL    TRUE            # Save 1st binned chip image?
  BIN2.FITS        BOOL    TRUE            # Save 2nd binned chip image?
  FPA1.FITS        BOOL    TRUE            # Save 1st binned fpa image? 
  FPA2.FITS        BOOL    TRUE            # Save 2nd binned fpa 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
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    FALSE           # 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?
  BACKGROUND       BOOL    TRUE            # Subtract background?
  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    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, astrom
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    FALSE           # 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?
  BACKGROUND       BOOL    TRUE            # Subtract background?
  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

# 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    FALSE           # 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?
  BACKGROUND       BOOL    TRUE            # Subtract background?
  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

# 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    FALSE           # 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    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?

  DETREND.CONSTRAINTS  METADATA
    BIAS METADATA
    END
    DARK METADATA
      DETTYPE STR DARK_PREMASK
      EXPTIME STR FPA.EXPOSURE
    END
    FLAT METADATA
      DETTYPE STR FLAT_PREMASK
      FILTER  STR FPA.FILTERID
    END
    FLATCORR METADATA
      FILTER  STR FPA.FILTERID
    END
    FRINGE METADATA
      FILTER   STR FPA.FILTERID
    END
    SHUTTER METADATA
    END
    MASK METADATA
    END	
    ASTROM METADATA
    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    FALSE           # 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    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?

  DETREND.CONSTRAINTS  METADATA
    BIAS METADATA
    END
    DARK METADATA
      EXPTIME STR FPA.EXPOSURE
    END
    FLAT METADATA
      DETTYPE STR FLATTEST
      FILTER  STR FPA.FILTERID
    END
    FRINGE METADATA
      FILTER   STR FPA.FILTERID
    END
    SHUTTER METADATA
    END
    MASK METADATA
    END	
    ASTROM METADATA
    END	
  END
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    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
  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

  # GPC1 has significant dark structures: use a wide greyscale range
  PPIMAGE.JPEG1    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     VALUE
    SCALE.MIN      F32     -50.0
    SCALE.MAX      F32     +50.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

  # GPC1 has significant dark structures: use a wide greyscale range
  PPIMAGE.JPEG2    METADATA
    COLORMAP       STR     -greyscale
    SCALE.MODE     STR     VALUE
    SCALE.MIN      F32     -50.0
    SCALE.MAX      F32     +50.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.98
    SCALE.MAX      F32     1.02
  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.98
    SCALE.MAX      F32     1.02
  END
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    FALSE           # 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


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    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
  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?

  DETREND.CONSTRAINTS  METADATA
    BIAS METADATA
    END
    DARK METADATA
      DETTYPE STR DARKTEST
      EXPTIME STR FPA.EXPOSURE
    END
    FLAT METADATA
      FILTER  STR FPA.FILTERID
    END
    FLATCORR METADATA
      FILTER   STR FPA.FILTERID
    END
    FRINGE METADATA
      FILTER   STR FPA.FILTERID
    END
    SHUTTER METADATA
    END
    MASK METADATA
    END	
    ASTROM METADATA
    END	
    NOISEMAP METADATA
    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    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    TRUE            # Row pattern correction
  PATTERN.CELL	   BOOL	   TRUE		   # Cell pattern correction
  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    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?
  MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
  PATTERN.ROW        BOOL    FALSE           # Row pattern correction
  PATTERN.CELL	     BOOL    FALSE	     # Cell pattern correction
  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?
  CROSSTALK.MEASURE  BOOL    TRUE            # Subtract model 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    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?
  MASK.BURNTOOL    BOOL    TRUE            # Mask potential burntool trails
  PATTERN.ROW      BOOL    FALSE           # Row pattern correction
  PATTERN.CELL	   BOOL	   FALSE	   # Cell pattern correction
  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?
  CROSSTALK.MEASURE  BOOL  TRUE            # Subtract model 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    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?
  MASK.BURNTOOL      BOOL    TRUE            # Mask potential burntool trails
  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?
  CROSSTALK.MEASURE  BOOL    TRUE            # Subtract model 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
