## relphot outline

- load data
  - images: match photcode and time range, reset flags
  - measure: select subset matching restritions on: photcode, time, dM, Minst, Mag, dophot == 1
- iterate to find Mcal, image.flags:
- write out modified Mcal values to image table
- write out modified Mcal values to measure table
- write out modified Mrel values to average table

## relphot overview

relphot has two primary purposes:

- calculate Mcal for images / measures
- calculate Mrel for stars

relphot can also be used to determine the mosaic grid used to generate photometrically corrected flats (-grid option).

## data exclusion

relphot uses only a subset of the photometry data to calculate Mcal and Mrel. In the first stage, calculation of the Mcal values, relphot loads the photometry data from each relevant catalog and creates an internal subset catalog with the function bcatalog, excluding some of the irrelevant data. In addition, it uses flags to mark some of the data as invalid for the processing. bcatalog exclusions

- measure.photcode not equivalent to requested photcode
- measure.dophot != 1
- measure.Mcat > MAG_LIM
- measure.dM > SIGMA_LIM
- measure.Minst out of range (ImagMin - ImagMax) [optional]
- measure.t out of range (TSTART, TSTOP)

flagged data flagged image data images can be flagged by setting bits of image.code stars can be flagged by setting bits of average.code measures can be flagged by setting bits of measure.flag image.code ID_IMAGE_NOCAL : ignore, irrelevant ID_IMAGE_POOR : image measured bad ID_IMAGE_SKIP : externally known bad dMcal > VALUE FLAG_IMAGE_SCATTER clean_images fabs(Mcal) > VALUE FLAG_IMAGE_ZEROPT clean_images dMcal > VALUE FLAG_IMAGE_SCATTER clean_mosaics fabs(Mcal) > VALUE FLAG_IMAGE_ZEROPT clean_mosaics mark_images does not seem to do anything useful? average.code Ngood < MEAS_TOOFEW setMrel Ngood < MEAS_TOOFEW clean_measures ChiSq > STAR_CHISQ clean_stars dM > STAR_SCATTER clean_stars average.code (STAR_BAD) is not saved by relphot: it is set by clean_stars, clean_measures, and setMrel, but not setMrelOutput. STAR_BAD should only be internal since it depends on the photcode, but is not associated with a specific photcode in the data. Just in case, it is reset to 0 in setMrelFinal. measure.flag X,Y out of range setExclusions 3 sigma clipping clean_measures

## setting Mrel final value

setMrelFinal is used to set the final average.Mrel values. We do this in 4 stages. In each stage, we set the Mrel values for stars which have not already been set, based on the current exclusion settings. At successive stages, we relax the exclusions, allowing the more spurious objects to have a valid Mrel value to be set. In this loop, we actually run setMrelOutput twice: once to get the approximate Mrel value, then we flag the outlier measurements with clean_measure, then we redetermine the Mrel values on this basis, and mark the stars for exclusion from the next iteration.

    exclude on
     photcode       0 1 2 3
     time range     0 1 2 3
     MEAS_POOR      0 1 2 3
     MEAS_TOOFEW    0 1 2 3
     dophot == 10   0 1 2
     inst mag       0 1 2
     dophot != 1,2  0 1
     ID_IMAGE_POOR  0 1
     ID_IMAGE_SKIP  0 1
     dophot != 1    0
     measure.dM     0

for all relphot runs, Mrel is re-calculated, and measures are marked at least if they are outliers in mag or ccd area. setMrel.output needs to do a few things differently from setMrel:

- set measure.Mcal (skipped in setMrel.basic)
- set average.Mrel if N < TOO_FEW (not STAR_BAD) (optional!)
- use MAX (stats.error, stats.sigma) (optionally)
- allow STAR_BAD?

## imphotset

imphotset allows you to set certain phot.image table entries. here are the options: imphotset [-photcode code] [-name foo] [-trange (start) (stop)] -flag and value Here is a complete list of relphot configuration variable names, a quick description, and reasonable values to start with:

    --- configuration variables used by relphot ---
    MAG_LIM : float
      ignore measurements fainter than this absolute magnitude

    SIGMA_LIM : float
      ignore measurements with magnitude error larger than this value

    STAR_SCATTER : float
      mark stars as bad if their scatter is larger than this value

    IMAGE_SCATTER : float
      mark images as bad if their scatter is larger than this value

    IMAGE_OFFSET : float
      mark images as bad if the absolute value of thie zero point offset
      is larger than this number

    STAR_CHISQ : float
      mark stars as variable if their reduced chisq are larger than this value

    STAR_TOOFEW : int
      mark stars as bad if the have fewer than this number of valid measurements

    IMAGE_TOOFEW : int
      mark images as bad if the have fewer than this number of valid measurements

    IMAGE_GOOD_FRACTION : float
      mark images as bad if the have fewer than this fraction of valid measurements

    IMAGE_CATALOG : string
      name of the image catalog file

    IMAGE_CATALOG_TEMPLATE : string
      name of the template file to create the image catalog file

    CATALOG_TEMPLATE : string
      name of the template file to create the catalog file

    GSCFILE : string
      name of the GSC region table

    CATDIR : string
      directory where the database is stored

    PHOTCODE_FILE : string
      file containing photometry code information

    ZERO_PT : float
      default zero point for random data

    RELPHOT_GRID_X : int
      scale of mosaic correction grid

    RELPHOT_GRID_Y : int
      scale of mosaic correction grid

    RELPHOT_GRID_BINNING : int
      deprecated

    CAMERA_CONFIG : string
      name of the file containing descriptive information about the camera

    --- sample ConfigFile entries with typical values ---

    MAG_LIM                	 24.0
    SIGMA_LIM              	  0.05
    STAR_SCATTER           	  0.05
    IMAGE_SCATTER          	  0.05
    IMAGE_OFFSET           	  0.2
    STAR_CHISQ             	 10.0
    STAR_TOOFEW            	  3
    IMAGE_TOOFEW           	 10
    IMAGE_GOOD_FRACTION
    IMAGE_CATALOG          	 $CATDIR/Images.dat
    IMAGE_CATALOG_TEMPLATE 	 $REFSDIR/elixir/template.cat
    CATALOG_TEMPLATE       	 $REFSDIR/elixir/template.cat
    GSCFILE                	 $REFSDIR/gsc/GSCregions.tbl
    CATDIR                 	 $CATDIR
    PHOTCODE_FILE          	 $CONFDIR/camera/$CAMERA.photcode
    ZERO_PT                	 25.0
    RELPHOT_GRID_X         	 4
    RELPHOT_GRID_Y         	 8
    RELPHOT_GRID_BINNING   	 512
    CAMERA_CONFIG          	 $CONFDIR/camera/$CAMERA.config