예제 #1
0
def match(args):
    """ Match the PSF of a group of images with the PSF of a reference image.
    """
    sort_by_seeing(args)

    # Get seeing from header and calculate psf of reference image, the first one since we sorted the input
    ref_seeing = utils.get_from_header(args.input[0], args.FWHM_key)
    ref_psf = psf.main(arguments=[args.input[0], "--stars", args.input_stars[0],
                                  "--sigma_key", args.sigma,
                                  "--gain_key",  args.gain_key,  
                                  "--ron_key",   args.ron_key,  
                                  "--expt_key",  args.expt_key, 
                                  "--airm_key",  args.airm_key, 
                                  "--FWHM_key", args.FWHM_key])
 
    output_list = []
    for image, stars in zip(args.input, args.input_stars):
        output = utils.add_suffix_prefix(image, suffix=args.suffix)

        # Too small differences of seeing are not worh doing any matching
        current_seeing = utils.get_from_header(image, args.FWHM_key)
        if abs(ref_seeing - current_seeing) < args.limit:  # Not worth equating PSFs for small differences
            shutil.copy(image, output)  # copy old file into new one
        else:
            # Calculate psf of the other images
            psf_object =  psf.main(arguments=[image,
                                              "--stars",     stars,
                                              "--sigma_key", args.sigma,
                                              "--gain_key",  args.gain_key,
                                              "--ron_key",   args.ron_key,
                                              "--expt_key",  args.expt_key,
                                              "--airm_key",  args.airm_key,
                                              "--FWHM_key", args.FWHM_key])
            utils.if_exists_remove("kernel.fits", output)
            iraf.psfmatch(image, ref_psf, psf_object, "kernel.fits",
                                 convolution="psf", 
                                 filter="cosbell")                   
            iraf.psfmatch(image, ref_psf, psf_object,
                                 convolution="kernel", 
                                 kernel="kernel.fits", 
                                 output=output,
                                 verbose="no")
            utils.if_exists_remove("kernel.fits")
            mssg = "Before equating PSFs: " + str(current_seeing)
            utils.header_update_keyword(output, args.FWHM_key, ref_seeing, comment=mssg)
        output_list.append(output)
    return output_list
def convolve(lopsf, hipsf, outker, threshold, highresimg, outname, comp_kernel):
    """Match the higher-res psf to the lower-res psf and 
    ### note for optical and UV, a threshold of 0.14 was found to be ideal.
    ### for two IR ones, a threshold of 0.03 seemed to work better. 
    """
    if comp_kernel is True:
        # compute the psf matching function and save it to outker
        psfmatch(hipsf, lopsf, hipsf, outker, convolution="psf", background="none", threshold=threshold)

    # read in kernel
    k = fits.getdata(outker)
    # read in high res image to be convolved
    im, hdr = fits.getdata(highresimg, header=True)

    # convolve highresimg with the psf matching function in outker
    # to produce output image
    convimg = convolve_fft(im, k)

    fits.writeto(outname, convimg, header=hdr, clobber=True)
예제 #3
0
    os.system('ls -1 ' + img_G + ' ' + img_R + ' > inp' + ip.patchstr_sex[i] +
              '.lis')
    f = open('ker' + ip.patchstr_sex[i] + '.lis', 'w')
    f.write('ker_' + img_G + '\n')
    f.write('ker_' + img_R + '\n')
    f.close()
    os.system('rm -rfv ' + 'Comb' + ip.patchstr_sex[i] + '.fits')
    os.system('rm -rfv ' + 'm' + img_G + ' ' + 'm' + img_R)
    os.system('rm -rfv ' + 'ker_' + img_G + ' ' + 'ker_' + img_R)

    try:
        iraf.psfmatch(input='@inp' + ip.patchstr_sex[i] + '.lis',
                      referenc=img_I,
                      psfdata='psf_I' + ip.patchstr_sex[i] + '.reg',
                      kernel='@ker' + ip.patchstr_sex[i] + '.lis',
                      output='m//@inp' + ip.patchstr_sex[i] + '.lis',
                      convolu='image',
                      dnx=31,
                      dny=31,
                      pnx=15,
                      pny=15)

        dat_G = fits.getdata('m' + img_G)
        dat_R = fits.getdata('m' + img_R)
        dat_I = fits.getdata(img_I)

        fits.writeto('Comb' + ip.patchstr_sex[i] + '.fits',
                     (dat_G + dat_R + dat_I) / 3.0,
                     overwrite=True)

    except:
        dat_G = fits.getdata(img_G)
예제 #4
0
f.close()

# ----- Making PSF-matched & combining them ----- #
os.system('rm -rfv ' + 'comb.fits')
for i in np.arange(np.sum(~ref)):
    os.system('rm -rfv ' + 'm' + np.array(ic.nfits)[~ref][i])
for i in np.arange(np.sum(~ref)):
    os.system('rm -rfv ' + 'ker_' + np.array(ic.nfits)[~ref][i])

try:
    iraf.psfmatch(input='@inp.lis',
                  referenc=np.array(ic.nfits)[ref][0],
                  psfdata=np.array(ic.nfits)[ref][0].split('.')[0] +
                  '_psf.reg',
                  kernel='@ker.lis',
                  output='m//@inp.lis',
                  convolu='image',
                  dnx=31,
                  dny=31,
                  pnx=15,
                  pny=15)

    for i in np.arange(np.sum(~ref)):
        if (i == 0):
            dat_noref = fits.getdata('m' + np.array(ic.nfits)[~ref][i])
        else:
            dat_noref += fits.getdata('m' + np.array(ic.nfits)[~ref][i])
    dat_ref = fits.getdata(np.array(ic.nfits)[ref][0])

    fits.writeto('comb.fits', (dat_noref + dat_ref) / 3.0, overwrite=True)
예제 #5
0
def psf_matching(i, fil, input, psf165):
    ker = "ker%s_gal%s_ref165.fits" % (fil, i + 1)
    iraf.psfmatch(input, psf165, input, ker, convolution='psf')
    # cl> psfmatch inimage refpsf inpsf kernel convolution=psf
    return ker