purpose: Creates a master dark from a set of dark frames.
description: First the individual input frames are corrected for bias and bad pixels, after that the frames are combined to create the (preliminary) master. Both processes are controlled by the keyword AVMODE, which is a two--digit integer. If the first digit is 0, the bias correction is performed by just subtracting a master bias image. If the first digit is 1, the bias correction is performed using the scaled master bias. The scaling is done as follows: Each of the sections of the master bias is divided by its median and multiplied by the median of the corresponding pre-/overscan region of the input frame. If the first digit is 2, the master bias is also scaled, but each of the sections of the master bias is divided by the median of its corresponding pre-/overscan region and multiplied by the median of the pre-/overscan region of the input frame.
The second digit of AVMODE controls the averaging process. If it is 0, the generated master is the average of the means of the input frames and hence constant, if it is 1, the master frame is calculated as the mean, if it is 2 as the median of the stack of input frames.
Iteratively each input frame is compared with the master frame for large deviations. If one frame differs too much it is removed from the set of input frames and a new master is produced. As soon as no frame has to be rejected the final master frame has been found. The rejection limits are given by the THRESH parameter.
The median process is modified in that way that instead of the median the mean of all values in an interval centered on the median is taken. Each input frame is bad pixel corrected in advance.
A master frame is generated only if MIN_COUNT raw frames are remaining for the averaging process. This ensures a minimum quality of the product.
At the end, the new master frame is compared with the certified master frame from the calibration database.