Example #1
0
def psf(args):
    """ Calculate the PSF of an image.
    """
    # Read the seeing and sigma of the sky from the header
    seeing, sigma = utils.get_from_header(args.input, args.FWHM_key, args.sigma)
    
    # Do photometry on the image
    #print "photometry: \n"
    photfile_name = args.input + ".mag.1"
    utils.if_exists_remove(photfile_name)
    iraf.phot(args.input, output=photfile_name, coords=args.stars,
                     wcsin=args.coords, fwhm=seeing, 
                     sigma=sigma, datamax=args.maxval, datamin=args.minval,
                     ccdread=args.ron_key, gain=args.gain_key, exposure=args.expt_key,
                     airmass=args.airm_key, annulus=36, dannulus=18,
                     apert=18, verbose="no", verify="no", interac="no")


    # Select stars on the image                 
    #print "pstselect: \n"
    pstfile_name = args.input + ".pst.1"
    utils.if_exists_remove(pstfile_name)
    iraf.pstselect(args.input, photfile=photfile_name, pstfile=pstfile_name,
                          maxnpsf=20, fwhm=seeing, sigma=sigma,
                       datamax=args.maxval, ccdread=args.ron_key, gain=args.gain_key,
                       exposure=args.expt_key,  function="auto", nclean=1, 
                       psfrad=36, fitrad=18, maxnstar=20, verbose="no", interac="no",
                       verify="no")

    # Build psf of the stars
    #print "psf: \n"
    psffile_table = args.input + ".psf.1.fits"  # iraf keeps adding the .fits :(
    psgfile_name = args.input + ".psg.1"
    pstfile_name2 = args.input + ".pst.2"   
    utils.if_exists_remove(psffile_table,psgfile_name, pstfile_name2)
    iraf.psf( args.input, photfile=photfile_name, pstfile=pstfile_name,
                     groupfile=psgfile_name, opstfile=pstfile_name2,    
                     psfimage=psffile_table,fwhm=seeing, sigma=sigma, datamax=args.maxval, 
                     datamin=args.minval, ccdread=args.ron_key, gain=args.gain_key, 
                     exposure=args.expt_key, function="moffat25", nclean=1, 
                     psfrad=36, fitrad=18, maxnstar=20, interactive="no",
                     varorder=args.varorder, verbose="no",verify="no")

    # Use seepsf to build the image of the psf
    psffile_name = args.input + ".psf.fits" 
    utils.if_exists_remove(psffile_name)
    iraf.seepsf(psffile_table, psffile_name)
     
    return psffile_name
Example #2
0
def make_iraf_psf(fname):

    with fits.open(fname) as stp:  # Read in image info placed in header previously
        header = stp[0].header
        ra = header["RA"]
        dec = header["DEC"]
        for ext in range(len(stp)):  # Look in each header section
            try:
                header = stp[ext].header
                expnum = header["EXPNUM"]
            except:
                continue

    stamp = fits.open(fname)
    for ext in range(
        len(stamp)
    ):  # Establish size of image and location of source in image (source should be centered in cutout)
        try:
            world_coords = wcs.WCS(stamp[ext].header)
            image_coords = world_coords.sky2xy(float(ra), float(dec))
            image_size = stamp[ext].data.shape
        except:
            continue

    # Some cutouts are split over multiple CCDs, meaning the source may not actually be in some of these small image 'pieces'
    if 0 < image_coords[0] < image_size[0] and 0 < image_coords[1] < image_size[1]:

        ccdnum = stamp[ext].header.get("EXTNO", None)

        psf_file = storage.get_file(expnum, ccd=ccdnum, ext="psf.fits")  # Get psf file for image from storage

        iraf.noao()
        iraf.digiphot()
        iraf.daophot(_doprint=0)
        psf_image = psf_file.replace("psf", "seepsf")

        # Seepsf creates psf_image
        iraf.seepsf(psf_file, psf_image, xpsf=image_coords[0], ypsf=image_coords[1])
        os.unlink(psf_file)

        return psf_image

    else:
        return None
Example #3
0
def apply_psf(args, phot_file, pst_file):
    with tempfile.NamedTemporaryFile(suffix=".psf.1.fits") as fd0:
        psffile_table = fd0.name

    with tempfile.NamedTemporaryFile(suffix=".psf") as fd1:
        psf_name = fd1.name

    with tempfile.NamedTemporaryFile(suffix=".psg.1") as fd2:
        psg_name = fd2.name

    with tempfile.NamedTemporaryFile(suffix=".pst.2") as fd3:
        pst2_name = fd3.name

    hdr = args.image.header  # for short
    seeing, sigma = utils.get_from_header(args.image.im_name, hdr.seeingk, hdr.sigmak)
    iraf.psf(
        args.image.im_name,
        photfile=phot_file,
        pstfile=pst_file,
        groupfile=psg_name,
        opstfile=pst2_name,
        psfimage=psffile_table,
        fwhm=seeing,
        sigma=sigma,
        ccdread=hdr.ccdronk,
        gain=hdr.gaink,
        exposure=hdr.exptimek,
        function="auto",
        nclean=1,
        psfrad=6 * seeing,
        fitrad=5 * seeing,
        interactive="no",
        varorder=-1,
        verbose="no",
        verify="no",
    )

    # Use seepsf to make an image of the PSF
    iraf.seepsf(psffile_table, psf_name)
    print "\n PSF file: ", psf_name
    return psf_name
Example #4
0
def get_star_data(asteroid_id, mag, expnum, header):
    """
    From ossos psf fitted image, calculate mean of the flux of each row of the rotated PSF
    """

    # calculate mean psf
    uri = storage.get_uri(expnum.strip('p'), header[_CCD].split('d')[1])
    ossos_psf = '{}.psf.fits'.format(uri.strip('.fits'))
    local_psf = '{}{}.psf.fits'.format(expnum, header[_CCD].split('d')[1])
    local_file_path = '{}/{}'.format(_STAMPS_DIR, local_psf)
    storage.copy(ossos_psf, local_file_path)

    # pvwcs = wcs.WCS(header)
    # x, y = pvwcs.sky2xy(asteroid_id['ra'].values, asteroid_id['dec'].values)
    x = asteroid_id[_XMID_HEADER].values[0]
    y = asteroid_id[_YMID_HEADER].values[0]

    # run seepsf on the mean psf image
    iraf.set(uparm="./")
    iraf.digiphot(_doprint=0)
    iraf.apphot(_doprint=0)
    iraf.daophot(_doprint=0)
    iraf.seepsf(local_file_path, local_psf, xpsf=x, ypsf=y, magnitude=mag)

    with fits.open(local_psf) as hdulist:
        data = hdulist[0].data

    th = math.degrees(asteroid_id[_THETA_HEADER].values[0])
    data_rot = rotate(data, th)
    data_rot = np.ma.masked_where(data_rot == 0, data_rot)

    data_mean = np.ma.mean(data_rot, axis=1)

    os.unlink(local_psf)
    os.unlink(local_file_path)

    return data_mean[np.nonzero(np.ma.fix_invalid(data_mean, fill_value=0))[0]]
Example #5
0
            ds9 = os.system("ps -U" + str(os.getuid()) + "|grep -v grep | grep ds9")
            if option.interactive and ds9 != 0:
                pid = subprocess.Popen(['ds9']).pid
                time.sleep(2)
                ds9 = 0

            fwhm0 = option.fwhm
            while True:
                result, fwhm = ecpsf(img, fwhm0, option.threshold, option.psfstars,
                                     option.distance, option.interactive, ds9, psffun,
                                     fixaperture, _catalog, option.datamax, option.show)
                print '\n### ' + str(result)
                if option.show:
#                    lsc.util.marksn2(img + '.fits', img + '.sn2.fits', 1, '')
                    iraf.delete('tmp.psf.fit?', verify=False)
                    iraf.seepsf(img + '.psf', '_psf.psf')
                    iraf.surface('_psf.psf')
                    aa = raw_input('>>>good psf [[y]/n] ? ')
                    if not aa or aa.lower()[0] == 'y':
                        break
                    if aa.lower()[0] == 'n':
                        result = 0
                        bb = raw_input('If you want to try again, type the new FWHM to try here. Otherwise press enter to continue. ')
                        if bb: fwhm0 = float(bb)
                        else: break
                else: 
                    break

            iraf.delete("tmp.*", verify="no")
            iraf.delete("_psf.*", verify="no")
            print  "********** Completed in ", int(time.time() - start_time), "sec"
        sys.stdout = open(fn[:-5] + '.psf2.out', 'w')
        iraf.psf(fn[:-5]+'.sub.11',photfile=fn[:-5]+'.mag.1',pstfile=fn[:-5]+'.pst.1',psfimage=fn[:-5]+'.psf.2', \
            opstfile=fn[:-5]+'.pst.2', groupfile=fn[:-5]+'.psg.2',verify='no',interactive='no')
        iraf.allstar(fn[:-5],photfile=fn[:-5]+'.psg.2',psfimage=fn[:-5]+'.psf.2',allstarfile=fn[:-5]+'.als.2',rejfile=fn[:-5]+ \
            '.arj.2',subimage=fn[:-5]+'.sub.2',verify='no',verbos='no')
        iraf.substar(fn[:-5],photfile=fn[:-5]+'.als.2',exfile=fn[:-5]+'.pst.2',psfimage=fn[:-5]+'.psf.2',subimage=fn[:-5]+ \
            '.sub.22',verify='no',verbose='no')

        sys.stdout = open(fn[:-5] + '.psf3.out', 'w')
        iraf.psf(fn[:-5]+'.sub.22',photfile=fn[:-5]+'.mag.1',pstfile=fn[:-5]+'.pst.2',psfimage=fn[:-5]+'.psf.3',opstfile \
            =fn[:-5]+'.pst.3', groupfile=fn[:-5]+'.psg.3',verify='no',interactive='no')
    except iraf.IrafError, e:
        sys.stdout = original
        print fn
        print e
        os.system('mv test.cat ' + fn[:-5] + '.cat')
        continue

    sys.stdout = original
    iraf.seepsf(fn[:-5] + '.psf.1', fn[:-5] + '.psf1')
    iraf.seepsf(fn[:-5] + '.psf.2', fn[:-5] + '.psf2')
    iraf.seepsf(fn[:-5] + '.psf.3', fn[:-5] + '.psf3')

    shutil.copy(fn[:-5] + '.psf1.fits', psf_dir)
    shutil.copy(fn[:-5] + '.psf2.fits', psf_dir)
    shutil.copy(fn[:-5] + '.psf3.fits', psf_dir)

    os.system('mv test.cat ' + fn[:-5] + '.cat')
    os.system('rm *.fits')
#	os.system('rm '+fn[:-5]+'*')
Example #7
0
                if _catalog:
                    break
        if '.fits' in img: img = img[:-5]
        if os.path.exists(img + '.sn2.fits') and not option.redo:
            print img + ': psf already calculated'
        else:
            fwhm0 = option.fwhm
            while True:
                result, fwhm = ecpsf(img, fwhm0, option.threshold, option.psfstars,
                                     option.distance, option.interactive, psffun,
                                     fixaperture, _catalog, option.datamax, option.show)
                print '\n### ' + str(result)
                if option.show:
#                    lsc.util.marksn2(img + '.fits', img + '.sn2.fits', 1, '')
                    iraf.delete('tmp.psf.fit?', verify=False)
                    iraf.seepsf(img + '.psf', '_psf.psf')
                    iraf.surface('_psf.psf')
                    aa = raw_input('>>>good psf [[y]/n] ? ')
                    if not aa or aa.lower()[0] == 'y':
                        break
                    if aa.lower()[0] == 'n':
                        result = 0
                        bb = raw_input('If you want to try again, type the new FWHM to try here. Otherwise press enter to continue. ')
                        if bb: fwhm0 = float(bb)
                        else: break
                else: 
                    break

            iraf.delete("tmp.*", verify="no")
            iraf.delete("_psf.*", verify="no")
            print  "********** Completed in ", int(time.time() - start_time), "sec"
Example #8
0
 psftemp = '_temppsf.fits'
 if args.no_iraf:
     lsc.myloopdef.seepsf(
         imgtarg_path.replace('.fits', '.psf.fits'),
         psftarg)
     lsc.myloopdef.seepsf(
         imgtemp_path.replace('.fits', '.psf.fits'),
         psftemp)
 else:
     iraf.noao()
     iraf.digiphot()
     iraf.daophot(_doprint=0)
     os.system('rm {0} {1}'.format(
         psftarg, psftemp))
     iraf.seepsf(
         imgtarg_path.replace('.fits', '.psf.fits'),
         psftarg)
     iraf.seepsf(
         imgtemp_path.replace('.fits', '.psf.fits'),
         psftemp)
 try:
     print 'Passing images to PyZOGY'
     run_subtraction(
         imgtarg,
         imgtemp,
         psftarg,
         psftemp,
         science_mask=targmask,
         reference_mask=tempmask,
         science_saturation=sat_targ,
         reference_saturation=sat_temp,
Example #9
0
                        if args.afssc:
                            substamplist, xpix1, ypix1, xpix2, ypix2 = crossmatchtwofiles(imgtarg, imgtemp)
                            _afssc = ' -cmp ' + str(substamplist) + ' -afssc 1 '
                        else:
                            _afssc = ''

                        if args.difftype == '1':
                            #do subtraction
                            iraf.noao()
                            iraf.digiphot()
                            iraf.daophot(_doprint=0)
                            psftarg = '_targpsf.fits'
                            psftemp = '_temppsf.fits'
                            os.system('rm {0} {1}'.format(psftarg, psftemp))
                            iraf.seepsf(imgtarg_path.replace('.fits','.psf.fits'), psftarg)
                            iraf.seepsf(imgtemp_path.replace('.fits','.psf.fits'), psftemp)
                            try:
                                print 'Passing images to PyZOGY'
                                run_subtraction(imgtarg, imgtemp, psftarg, psftemp,
                                                           science_mask='_targmask.fits',
                                                           reference_mask='_tempmask.fits',
                                                           science_saturation=sat_targ,
                                                           reference_saturation=sat_temp,
                                                           n_stamps=1,
                                                           output=imgout,
                                                           normalization=args.normalize,
                                                           show=args.show,
                                                           use_mask_for_gain=args.use_mask)
                            except Exception as e:
                                print e
Example #10
0
                    psfstars,
                    option.distance,
                    option.interactive,
                    psffun,
                    fixaperture,
                    catalog,
                    option.datamin,
                    option.datamax,
                    option.show,
                    make_sn2,
                    max_apercorr=option.max_apercorr)
                print '\n### ' + str(result)
                if option.show:
                    #                    lsc.util.marksn2(img + '.fits', img + '.sn2.fits', 1, '')
                    iraf.delete('tmp.psf.fit?', verify=False)
                    iraf.seepsf(img.replace('.fits', '.psf'), '_psf.psf')
                    iraf.surface('_psf.psf')
                    aa = raw_input('>>>good psf [[y]/n] ? ')
                    if not aa or aa.lower()[0] == 'y':
                        break
                    if aa.lower()[0] == 'n':
                        result = 0
                        bb = raw_input(
                            'If you want to try again, type the new FWHM to try here. Otherwise press enter to continue. '
                        )
                        if bb: fwhm0 = float(bb)
                        else: break
                else:
                    break

            iraf.delete("tmp.*", verify="no")
Example #11
0
    pstfile = open(FitsFileName+'.pst.1', 'a+r')
    pstfile.write("#N ID    XCENTER   YCENTER   MAG         MSKY                                  \\\n")
    pstfile.write("#U ##    pixels    pixels    magnitudes  counts                                \\\n")
    pstfile.write("#F %-9d  %-10.3f   %-10.3f   %-12.3f     %-15.7g                                 \n")
    pstfile.write("#\n")
    np.savetxt(pstfile,g.take([-1,0,1,2,3],axis=1),fmt=['%-9d','%-10.3f','%-10.3f','%-12.3f','%-15.7g'])
    pstfile.close()

    iraf.daopars.setParam('matchra',fwhm)
    iraf.daopars.setParam('psfrad',4*fwhm+1)
    iraf.daopars.setParam('fitrad',fwhm)
    iraf.daopars.setParam('sannulu',2*fwhm)
    iraf.daopars.setParam('wsannul',4*fwhm)
    iraf.psf.setParam('image',FitsFileName)
    iraf.psf(mode='h')
    iraf.seepsf(psfimage=FitsFileName+'.psf.1.fits',image=base+'psfim'+ext+'.fits',magnitu='18.0')
    iraf.allstar.setParam('image',FitsFileName)
    iraf.allstar(mode='h',verbose='no')

    if os.path.exists(base+'allstartmp') == True: os.remove(base+'allstartmp')
    iraf.txdump(textfile=FitsFileName+'.als.1',fields='xcenter,ycenter,mag,merr,id',expr='mag\
    != INDEF && merr != INDEF', Stdout=base+'allstartmp')
    outmags = np.loadtxt(base+'allstartmp')
    if os.path.exists(base+'allstartmp') == True: os.remove(base+'allstartmp')

    if int(ext) <= 4:
        shifty = 0.0
        shiftx = (float(ext) - 1.)*sx
    else:
        shifty = sy
        shiftx = (float(ext) - 5.)*sx
Example #12
0
        pstregfl.close()
        os.system("/usr/local/bin//ds9 " + flnm + '.sub.0.fits' +
                  " -regions " + flnm + ".pst.1.reg" + " &")
        tfs = time.time()
        iraf.psf(image=flnm + '.sub.0.fits',
                 photfile=flnm + '.sub.0.mag',
                 pstfile=flnm + '.pst.1',
                 psfimage=flnm + '.psf.fits',
                 opstfile=flnm + '.pst.2',
                 groupfile=flnm + '.grf.psg',
                 interactive="no",
                 showplots="no",
                 verify="no")
        tfe = time.time()
        times[runnm + '_psf'] = tfe - tfs
        iraf.seepsf(psfimage=flnm + '.psf.fits',
                    image=flnm + '.image_of_psf.fits')

    if i == 0:
        shutil.copy(runnm + '.mag',
                    runnm + '.tot.mag')  # formatting reasons only
    else:
        print "========================================="
        print "...merging phot lists"
        print "========================================="
        iraf.pfmerge(inphotfi=str(flnm + '.sub.' + str(i - 1) + '.als' + ',' +
                                  runnm + '.mag'),
                     outphotf=runnm + '.tot.mag')
        iraf.prenumber(runnm + '.tot.mag')

    print "========================================="
    print "...running allstar for", runnm + '.fits'
Example #13
0
                    catalog = option.catalog
                else:
                    for system in ['sloan', 'apass', 'landolt']:
                        #catalog = lsc.util.getcatalog(img, system)
                        catalog = lsc.util.getcatalog(img.split('/')[-1], system)
                        if catalog:
                            break
            while True:
                result, fwhm = lsc.lscpsfdef.ecpsf(img_for_psf, fwhm0, option.threshold, psfstars,
                                                   option.distance, option.interactive, psffun, fixaperture,
                                                   catalog, option.datamin, option.datamax, option.show, make_sn2)
                print '\n### ' + str(result)
                if option.show:
#                    lsc.util.marksn2(img + '.fits', img + '.sn2.fits', 1, '')
                    iraf.delete('tmp.psf.fit?', verify=False)
                    iraf.seepsf(img.replace('.fits', '.psf'), '_psf.psf')
                    iraf.surface('_psf.psf')
                    aa = raw_input('>>>good psf [[y]/n] ? ')
                    if not aa or aa.lower()[0] == 'y':
                        break
                    if aa.lower()[0] == 'n':
                        result = 0
                        bb = raw_input('If you want to try again, type the new FWHM to try here. Otherwise press enter to continue. ')
                        if bb: fwhm0 = float(bb)
                        else: break
                else: 
                    break

            iraf.delete("tmp.*", verify="no")
            iraf.delete("_psf.*", verify="no")
            print  "********** Completed in ", int(time.time() - start_time), "sec"
def doaphot_psf_photometry(path, imageFile, extent, extension):

    data, image, hdulist, size, mid_point = load_image_data(
        imageFile, extent, extension=extension)
    # garbage collect data and image
    data = None
    image = None

    # import IRAF packages
    iraf.digiphot(_doprint=0)
    iraf.daophot(_doprint=0)

    # dao_params.txt must be created manually using daoedit in iraf/pyraf for 5 stars
    dao_params = extract_dao_params(
        imageFile.strip(".fits") + "_dao_params.txt")

    sky = dao_params[0]
    sky_sigma = dao_params[1]
    fwhm = dao_params[2]
    datamin = dao_params[3]
    aperature_radius = dao_params[4]
    annulus_inner_radius = dao_params[5]
    annulus_outer_radius = dao_params[6]

    # get datapars
    datapars = extract_header_info(hdulist)

    datamax = datapars[0]
    ccdread = datapars[1]
    gain = datapars[2]
    readnoise = datapars[3]
    epadu = datapars[4]
    exposure = datapars[5]
    airmass = datapars[6]
    filter = datapars[7]
    obstime = datapars[8]
    itime = datapars[9]
    xairmass = datapars[10]
    ifilter = datapars[11]
    otime = datapars[12]

    # set datapars
    iraf.datapars.unlearn()
    iraf.datapars.setParam('fwhmpsf', fwhm)
    iraf.datapars.setParam('sigma', sky_sigma)
    iraf.datapars.setParam('datamin', datamin)
    iraf.datapars.setParam('datamax', datamax)
    iraf.datapars.setParam('ccdread', ccdread)
    iraf.datapars.setParam('gain', gain)
    iraf.datapars.setParam('readnoise', readnoise)
    iraf.datapars.setParam('epadu', epadu)
    iraf.datapars.setParam('exposure', exposure)
    iraf.datapars.setParam('airmass', airmass)
    iraf.datapars.setParam('filter', filter)
    iraf.datapars.setParam('obstime', obstime)
    iraf.datapars.setParam('itime', itime)
    iraf.datapars.setParam('xairmass', xairmass)
    iraf.datapars.setParam('ifilter', ifilter)
    iraf.datapars.setParam('otime', otime)

    # set photpars
    iraf.photpars.unlearn()
    iraf.photpars.setParam('apertures', aperature_radius)
    zp_estimate = iraf.photpars.getParam('zmag')
    # set centerpars
    iraf.centerpars.unlearn()
    iraf.centerpars.setParam('calgorithm', 'centroid')
    iraf.centerpars.setParam('cbox', 5.)

    # set fitskypars
    iraf.fitskypars.unlearn()
    iraf.fitskypars.setParam('annulus', annulus_inner_radius)
    iraf.fitskypars.setParam('dannulus', annulus_outer_radius)

    # run phot
    run_phot(imageFile, imageFile + ".quality.coo")

    # set daopars
    iraf.daopars.unlearn()
    iraf.daopars.setParam('function', 'auto')
    iraf.daopars.setParam('psfrad', 2 * int(fwhm) + 1)
    iraf.daopars.setParam('fitrad', fwhm)

    # select a psf/prf star
    # taking whatever the default selection is, can't see a way to pass coords of desired
    # stars, if could would use those in dao_params.txt
    # An alternative is to reorder the objects so those in dao_params.txt are at top of
    # sources table, assuming those are the defaults selected here.
    iraf.pstselect.unlearn()
    iraf.pstselect.setParam('maxnpsf', 5)
    iraf.pstselect(image=imageFile,
                   photfile=imageFile + ".mags.1",
                   pstfile=imageFile + ".pst.1",
                   interactive='no')

    # fit the psf
    iraf.psf.unlearn()
    iraf.psf(image=imageFile, \
             photfile=imageFile+".mags.1",\
             pstfile=imageFile+".pst.1",\
             psfimage=imageFile+".psf.1.fits",\
             opstfile=imageFile+".pst.2",\
             groupfile=imageFile+".psg.1",\
             interactive='no')
    # check the psf
    # perhaps pass it through ML and visualise
    # save visualisation for later manual checks
    iraf.seepsf.unlearn()
    iraf.seepsf(psfimage=imageFile + ".psf.1.fits",
                image=imageFile + ".psf.1s.fits")

    hdulist_psf = fits.open(imageFile + ".psf.1s.fits")
    #print "[*] plotting PSF for visual check."
    #plt.imshow(hdulist_psf[0].data, interpolation="nearest",cmap="hot")
    #plt.axis("off")
    #plt.show()

    # perform photometry
    run_allstar(imageFile, imageFile + ".psf.1.fits")
    return zp_estimate, imageFile + ".psf.1.fits"
def doaphot_psf_photometry(path, imageFile, extent, extension):
    
    data, image, hdulist, size, mid_point = load_image_data(imageFile, extent, extension=extension)
    # garbage collect data and image
    data = None
    image = None
    
    # import IRAF packages
    iraf.digiphot(_doprint=0)
    iraf.daophot(_doprint=0)

    # dao_params.txt must be created manually using daoedit in iraf/pyraf for 5 stars
    dao_params = extract_dao_params(imageFile.strip(".fits")+"_dao_params.txt")
    
    sky                  = dao_params[0]
    sky_sigma            = dao_params[1]
    fwhm                 = dao_params[2]
    datamin              = dao_params[3]
    aperature_radius     = dao_params[4]
    annulus_inner_radius = dao_params[5]
    annulus_outer_radius = dao_params[6]
    
    # get datapars
    datapars = extract_header_info(hdulist)
    
    datamax   = datapars[0]
    ccdread   = datapars[1]
    gain      = datapars[2]
    readnoise = datapars[3]
    epadu     = datapars[4]
    exposure  = datapars[5]
    airmass   = datapars[6]
    filter    = datapars[7]
    obstime   = datapars[8]
    itime     = datapars[9]
    xairmass  = datapars[10]
    ifilter   = datapars[11]
    otime     = datapars[12]
    
    # set datapars
    iraf.datapars.unlearn()
    iraf.datapars.setParam('fwhmpsf',fwhm)
    iraf.datapars.setParam('sigma',sky_sigma)
    iraf.datapars.setParam('datamin',datamin)
    iraf.datapars.setParam('datamax',datamax)
    iraf.datapars.setParam('ccdread',ccdread)
    iraf.datapars.setParam('gain',gain)
    iraf.datapars.setParam('readnoise',readnoise)
    iraf.datapars.setParam('epadu',epadu)
    iraf.datapars.setParam('exposure',exposure)
    iraf.datapars.setParam('airmass',airmass)
    iraf.datapars.setParam('filter',filter)
    iraf.datapars.setParam('obstime',obstime)
    iraf.datapars.setParam('itime',itime)
    iraf.datapars.setParam('xairmass',xairmass)
    iraf.datapars.setParam('ifilter',ifilter)
    iraf.datapars.setParam('otime',otime)
    
    # set photpars
    iraf.photpars.unlearn()
    iraf.photpars.setParam('apertures',aperature_radius)
    zp_estimate = iraf.photpars.getParam('zmag')
    # set centerpars
    iraf.centerpars.unlearn()
    iraf.centerpars.setParam('calgorithm','centroid')
    iraf.centerpars.setParam('cbox',5.)
    
    # set fitskypars
    iraf.fitskypars.unlearn()
    iraf.fitskypars.setParam('annulus',annulus_inner_radius)
    iraf.fitskypars.setParam('dannulus',annulus_outer_radius)
    
    # run phot
    run_phot(imageFile, imageFile+".quality.coo")
    
    # set daopars
    iraf.daopars.unlearn()
    iraf.daopars.setParam('function','auto')
    iraf.daopars.setParam('psfrad', 2*int(fwhm)+1)
    iraf.daopars.setParam('fitrad', fwhm)
    
    # select a psf/prf star
    # taking whatever the default selection is, can't see a way to pass coords of desired
    # stars, if could would use those in dao_params.txt
    # An alternative is to reorder the objects so those in dao_params.txt are at top of
    # sources table, assuming those are the defaults selected here.
    iraf.pstselect.unlearn()
    iraf.pstselect.setParam('maxnpsf',5)
    iraf.pstselect(image=imageFile,photfile=imageFile+".mags.1",pstfile=imageFile+".pst.1",interactive='no')
    
    # fit the psf
    iraf.psf.unlearn()
    iraf.psf(image=imageFile, \
             photfile=imageFile+".mags.1",\
             pstfile=imageFile+".pst.1",\
             psfimage=imageFile+".psf.1.fits",\
             opstfile=imageFile+".pst.2",\
             groupfile=imageFile+".psg.1",\
             interactive='no')
    # check the psf
    # perhaps pass it through ML and visualise
    # save visualisation for later manual checks
    iraf.seepsf.unlearn()
    iraf.seepsf(psfimage=imageFile+".psf.1.fits", image=imageFile+".psf.1s.fits")
             
    hdulist_psf = fits.open(imageFile+".psf.1s.fits")
    #print "[*] plotting PSF for visual check."
    #plt.imshow(hdulist_psf[0].data, interpolation="nearest",cmap="hot")
    #plt.axis("off")
    #plt.show()
             
    # perform photometry
    run_allstar(imageFile,imageFile+".psf.1.fits")
    return zp_estimate, imageFile+".psf.1.fits"