Example #1
0
def reduc(files, dir='/Users/nickedwards/python/independent/'):

    cal = divide_flat(files, dir=dir)

    keys = [cal['header'][i]['OBJECT'] for i in range(len(cal['header']))]
    data = {}

    for key in keys:
        data[key] = {
            'datetime': [],
            'optimal_aperture': [],
            'xcen': [],
            'ycen': [],
            'fwhm': [],
            'aspect': [],
            'snrmax': [],
            'totflux': [],
            'totflux_aperture': [],
            'chisq': [],
            'curve_of_growth': [],
            'secz': [],
            'totfluxerr': []
        }

    dkeys = np.array(data.keys())
    dkeys = dkeys[dkeys != 'datetime']

    for i in range(len(files)):
        print files[i]
        ra = angcor(cal['header'][i]['RA']).d
        print ra
        dec = angcor(cal['header'][i]['DEC']).d
        print dec
        op = tp.optimal_aperture(cal['image'][i],
                                 cal['header'][i], [20, 30],
                                 ra=ra,
                                 dec=dec)
        key = cal['header'][i]['OBJECT']
        print key
        data[key]['optimal_aperture'] = np.append(
            data[key]['optimal_aperture'], op['optimal_aperture'])
        data[key]['xcen'] = np.append(data[key]['xcen'], op['xcen'])
        data[key]['ycen'] = np.append(data[key]['ycen'], op['ycen'])
        data[key]['fwhm'] = np.append(data[key]['fwhm'], op['fwhm'])
        data[key]['aspect'] = np.append(data[key]['aspect'], op['aspect'])
        data[key]['snrmax'] = np.append(data[key]['snrmax'], op['snrmax'])
        data[key]['totflux'] = np.append(data[key]['totflux'], op['totflux'])
        data[key]['totflux_aperture'] = np.append(
            data[key]['totflux_aperture'], op['totflux_aperture'])
        data[key]['chisq'] = np.append(data[key]['chisq'], op['chisq'])
        data[key]['curve_of_growth'] = np.append(data[key]['curve_of_growth'],
                                                 op['curve_of_growth'])
        data[key]['secz'] = np.append(data[key]['secz'], op['secz'])
        data[key]['totfluxerr'] = np.append(data[key]['totfluxerr'],
                                            op['totfluxerr'])
        datetime = cal['header'][i]['DATE'] + " " + cal['header'][i]['UT']
        datetime = dt.strptime(datetime, '%d/%m/%y %H:%M:%S')
        data[key]['datetime'] = np.append(data[key]['datetime'], datetime)

    return data
def flux_all(path=None,band='gp',extraprecision=True,extraprecisionrange=100,source='BD710031',badimindices = [],bias=None,dark=None,flat=None):

    if not path:
        path = set_path()

    if length(bias) == 1:
        bias = make_bias(path=path)

    if length(dark) == 1:
        dark = make_dark(path=path)

    if length(flat) == 1:
        flat = make_flat(path=path,band=band,bias=bias,dark=dark)
        
    files,osz = tp.get_files(dir=path, tag=source+'.'+band)
    sz = osz
    #remove faulty images
    if len(badimindices) != 0:
        for g in range(osz):
            if g in badimindices:
                del files[g]
                sz=sz-1
            
    flux = []
    
    for file in files:
        image,header = cal_image(file,plot=False,path=path,band=band,source=source,bias=bias,dark=dark,flat=flat)
        w = wcs.WCS(header)
        x,y = w.all_world2pix(float(header['TARGRA']), float(header['TARGDEC']), 1)
        position = (float(x),float(y))
        if extraprecision == True:
            for k in range(extraprecisionrange):
                if check_radii(image,header,position,rin=k+10,rout=k+15) == True:
                    op_ap,xval,yval,fwhm,aspect,snrmax,totflux,totap,chisq = \
                        tp.optimal_aperture(float(x),float(y),image,[k+10,k+15],use_old=True)
                    break
        else:
            op_ap,xval,yval,fwhm,aspect,snrmax,totflux,totap,chisq = \
                    tp.optimal_aperture(float(x),float(y),image,[10,15],use_old=True)
        #print "Final aperture: " + str(op_ap)
        phot = do_phot(image,position,radius=op_ap)
        flux = np.append(flux,phot['aperture_sum_bkgsub'])
        
    return flux
def get_fiber_flux(file,fwhm=20,threshold=100):

    image,header = qi.readimage(file,plot=False)
    mean, median, std = sigma_clipped_stats(image, sigma=3.0)

    source = daofind(image - median, fwhm=fwhm, threshold=threshold*std)
    xcen = np.int(np.round(source['xcentroid'][0]))
    ycen = np.int(np.round(source['ycentroid'][0]))

    plt.plot([xcen],[ycen],'rx',markersize=20)

    params = fitgaussian(image)
    
    y,x = params[1],params[2]

    apdict = tp.optimal_aperture(x,y,image,[150,160])
    return apdict
Example #4
0
bias = tp.master_bias(biases,outdir='./Photometry/',readnoise=False)

dark = tp.master_dark(darks,bias=bias,outdir='./Photometry/')

flat = tp.master_flat(flats,bias=bias,dark=dark,outdir='./Photometry/')

cal = (image - dark - bias)/flat
qi.display_image(cal,siglo=2,sighi=2)
plt.plot([x0],[y0],'y+',markersize=30,linewidth=1e6)
plt.xlim(0,2048)
plt.ylim(0,2048)

# define the aperture
radius,ynew,xnew,fwhm,aspect,snrmax,totflux,totap,chisq = \
    tp.optimal_aperture(x0,y0,image,skyrad=[15,20])

pref = np.array([[x0,y0],[836,1154],[645,1152], [1234,1002], [1131,1338], [377,426]])
coords0 = w.wcs_pix2world(pref,1) 
ras = coords0[:,0]
decs = coords0[:,1]

info = tp.batch_phot(targetfiles[:-1],ras,decs,bias=bias,dark=dark,flat=flat,
                     outdir='./Photometry/',skyrad=np.array([15,20]))

plt.figure(56)
plt.plot(info['jd']-np.median(info['jd']),info['flux'][:,0],'o-')

sys.exit()