Example #1
0
def credge(arr, thresh, gain, rdnoise, b_factor, fthresh):
    """Identify cosmic rays following the van Dokkem (2001) prescription
    """

    min_limit = 0.01

    #set up the convolution kernel
    f_conv = np.array([[0, -1, 0], [-1, 4, -1], [0, -1, 0]])

    #set up the array
    shape = arr.shape
    sdata = arr

    #rebin the data
    newshape = (b_factor * shape[0], b_factor * shape[1])
    ldata = salttran.rebin_factor(sdata, newshape)

    #convolve with f_conv
    #ldata=conv2d(ldata,f_conv,mode='same')
    ldata = conv2d(ldata, f_conv)
    mask = (ldata >= 0)
    ldata = ldata * mask

    #return to the original binning
    ldata = salttran.blockave(ldata, shape)

    #create noise model
    meddata = saltstat.median_image(sdata, 5)
    noise = abs(meddata)
    noise = (gain * noise + rdnoise**2)**0.5 / gain

    #create S/N image
    odata = ldata / noise / b_factor

    #remove extended objects
    odata = odata - saltstat.median_image(odata, 5)

    #select objects
    masks = (odata > thresh)

    #remove compact bright sources
    mdata = saltstat.median_image(sdata, 5)
    fdata = mdata - saltstat.median_image(mdata, 7)
    fdata = fdata / noise

    # set a minimum value for all pixels so no divide by zero problems
    indf = np.where(fdata < min_limit)
    fdata[indf] = min_limit

    fdata = odata * masks / fdata
    maskf = (fdata > fthresh)

    #make the list of cosmic rays
    mask = masks * maskf

    #identify the cosmic rays
    crarr = mdata * mask

    return crarr
Example #2
0
def credge(arr, thresh, gain, rdnoise, b_factor, fthresh):
    """Identify cosmic rays following the van Dokkem (2001) prescription
    """

    min_limit=0.01

    #set up the convolution kernel
    f_conv=np.array([[0,-1,0],[-1,4,-1],[0,-1,0]])

    #set up the array
    shape=arr.shape
    sdata=arr

    #rebin the data
    newshape=(b_factor*shape[0],b_factor*shape[1])
    ldata=salttran.rebin_factor(sdata,newshape)

    #convolve with f_conv
    #ldata=conv2d(ldata,f_conv,mode='same')
    ldata=conv2d(ldata,f_conv)
    mask = (ldata >= 0)
    ldata = ldata * mask

    #return to the original binning
    ldata = salttran.blockave(ldata,shape)

    #create noise model
    meddata =saltstat.median_image(sdata,5)
    noise = abs(meddata)
    noise = (gain*noise+rdnoise**2)**0.5/gain

    #create S/N image
    odata = ldata / noise / b_factor

    #remove extended objects
    odata = odata - saltstat.median_image(odata,5)

    #select objects
    masks = (odata>thresh)

    #remove compact bright sources
    mdata = saltstat.median_image(sdata,5)
    fdata = mdata - saltstat.median_image(mdata,7)
    fdata = fdata / noise

    # set a minimum value for all pixels so no divide by zero problems
    indf = np.where(fdata < min_limit)
    fdata[indf]=min_limit

    fdata = odata * masks/fdata
    maskf = (fdata > fthresh)

    #make the list of cosmic rays
    mask =  masks*maskf

    #identify the cosmic rays
    crarr=mdata*mask

    return crarr
Example #3
0
def rebin(hdu, xbin, ybin):
    """Given in input SALT image (ie, multi-extension), rebin the data
       and write out the results

       hdu--an input SALT image
       xbin--the factor to rebin the x-data by
       ybin--the factor to rebing the y data by

    """
    for i in range(1,len(hdu)):
          shape=hdu[i].data.shape
          newshape=(ybin*shape[0],xbin*shape[1])
          hdu[i].data=salttran.rebin_factor(hdu[i].data,newshape)

    return hdu