def cosmetics(flat1, flat2 = None, mask=None, lowercut=6.0, uppercut=6.0, siglev=2.0):
    """Find cosmetic defects in a detector using two flat field images.

    Two arrays representing flat fields of different exposure times are
    required. Cosmetic defects are selected as points that deviate
    significantly of the expected normal distribution of pixels in
    the ratio between `flat2` and `flat1`.

    The median of the ratio array is computed and subtracted to it.

    The standard deviation of the distribution of pixels is computed
    obtaining the percentiles nearest the pixel values corresponding to
    `nsig` in the normal CDF. The standar deviation is then the distance
    between the pixel values divided by two times `nsig`.
    The ratio image is then normalized with this standard deviation.

    The values in the ratio above `uppercut` are flagged as hot pixels,
    and those below '-lowercut` are flagged as dead pixels in the output mask.

    :parameter flat1: an array representing a flat illuminated exposure.
    :parameter flat2: an array representing a flat illuminated exposure.
    :parameter mask: an integer array representing initial mask.
    :parameter lowercut: values bellow this sigma level are flagged as dead pixels.
    :parameter uppercut: values above this sigma level are flagged as hot pixels.
    :parameter siglev: level to estimate the standard deviation.
    :returns: the updated mask

    """

    if flat2 is None:
        flat1, flat2 = flat2, flat1
        flat1 = numpy.ones_like(flat2)

    if type(mask) is not numpy.ndarray:
        mask=numpy.zeros(flat1.shape,dtype='int')

    ratio, mask = comp_ratio(flat1, flat2, mask)
    fratio1 = ratio[~mask]
    central = numpy.median(fratio1)
    std = robust_std(fratio1, central, siglev)
    mask_u = ratio > central + uppercut * std
    mask_d = ratio < central - lowercut * std
    mask_final = mask_u | mask_d | mask
    return mask_final
def cosmetics ( flat1 , flat2 = None , mask = None , lowercut = 6.0 , uppercut = 6.0 , siglev = 2.0 ) : if flat2 is None : flat1 , flat2 = flat2 , flat1 flat1 = numpy . ones_like ( flat2 ) if type ( mask ) is not numpy . ndarray : mask = numpy . zeros ( flat1 . shape , dtype = 'int' ) ratio , mask = comp_ratio ( flat1 , flat2 , mask ) fratio1 = ratio [ ~ mask ] central = numpy . median ( fratio1 ) std = robust_std ( fratio1 , central , siglev ) mask_u = ratio > central + uppercut * std mask_d = ratio < central - lowercut * std mask_final = mask_u | mask_d | mask return mask_final
Find cosmetic defects in a detector using two flat field images.

    Two arrays representing flat fields of different exposure times are
    required. Cosmetic defects are selected as points that deviate
    significantly of the expected normal distribution of pixels in
    the ratio between `flat2` and `flat1`.

    The median of the ratio array is computed and subtracted to it.

    The standard deviation of the distribution of pixels is computed
    obtaining the percentiles nearest the pixel values corresponding to
    `nsig` in the normal CDF. The standar deviation is then the distance
    between the pixel values divided by two times `nsig`.
    The ratio image is then normalized with this standard deviation.

    The values in the ratio above `uppercut` are flagged as hot pixels,
    and those below '-lowercut` are flagged as dead pixels in the output mask.

    :parameter flat1: an array representing a flat illuminated exposure.
    :parameter flat2: an array representing a flat illuminated exposure.
    :parameter mask: an integer array representing initial mask.
    :parameter lowercut: values bellow this sigma level are flagged as dead pixels.
    :parameter uppercut: values above this sigma level are flagged as hot pixels.
    :parameter siglev: level to estimate the standard deviation.
    :returns: the updated mask