Ejemplo n.º 1
0
def do_Circ_phot(pos, FWHM, ap_min=3., ap_factor=1.5, rin=None, rout=None, \
                   sky_nsigma=3., sky_iter=10):
    '''
    In rigorous manner, we should use
    error = sqrt (flux / epadu + area * stdev**2 + area**2 * stdev**2 / nsky)
    as in http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?phot .
    Here flux == aperture_sum - sky, i.e., flux from image_reduc.
        stdev should include sky error AND ronoise.
    '''
    if rin == None:
        rin  = 4 * FWHM
    if rout == None:
        rout = 6 * FWHM
    N = len(pos)
    if pos.ndim == 1:
        N = 1
    an       = CircAn(pos, r_in=rin, r_out=rout)
    ap_size  = np.max([ap_min, ap_factor*FWHM])
    aperture = CircAp(pos, r=ap_size)
    flux     = aperture.do_photometry(image_reduc, method='exact')[0]
    # do phot and get sum from aperture. [0] is sum and [1] is error.
#For test:
#N=len(pos_star_fit)
#an       = CircAn(pos_star_fit, r_in=4*FWHM_moffat, r_out=6*FWHM_moffat)
#ap_size  = 1.5*FWHM_moffat
#aperture = CircAp(pos_star_fit, r=ap_size)
#flux     = aperture.do_photometry(image_reduc, method='exact')[0]
    flux_ss  = np.zeros(N)
    error    = np.zeros(N)
    for i in range(0, N):
        mask_an    = (an.to_mask(method='center'))[i]
        #   cf: test = mask_an.cutout(image_reduc) <-- will make cutout image.
        sky_an     = mask_an.apply(image_reduc)
        all_sky    = sky_an[np.nonzero(sky_an)]
        # only annulus region will be saved as np.ndarray
        msky, stdev, nsky, nrej = sky_fit(all_sky, method='Mode', mode_option='sex')
        area       = aperture.area()
        flux_ss[i] = flux[i] - msky*area  # sky subtracted flux
        error[i]   = np.sqrt( flux_ss[i]/gain \
                           + area * stdev**2 \
                           + area**2 * stdev**2 / nsky )
# To know rejected number, uncomment the following.
#        plt.imshow(sky_an, cmap='gray_r', vmin=-20)
#        plt.colorbar()
#        plt.show()
#        mask_ap  = (aperture.to_mask(method='exact'))[i]
#        star_ap  = mask_ap.apply(image_reduc)
#        plt.imshow(star_ap)
#        plt.colorbar()
#        plt.show()
#        plt.cla()
        if pos.ndim > 1:
            print('\t[{x:7.2f}, {y:7.2f}], {nsky:3d} {nrej:3d} {msky:7.2f} {stdev:7.2f} {flux:7.1f} {ferr:3.1f}'.format(\
                          x=pos[i][0], y=pos[i][1], \
                          nsky=nsky, nrej=nrej, msky=msky, stdev=stdev,\
                          flux=flux_ss[i], ferr=error[i]))
    return flux_ss, error
Ejemplo n.º 2
0
if len(DAOfound) == 0:
    print('No star was founded using DAOStarFinder\n' * 3)
else:
    # Use the object "found" for aperture photometry:
    print(len(DAOfound), 'stars were founded')
    #print('DAOfound \n', DAOfound)
    DAOfound.pprint(max_width=1800)
    # save XY coordinates:
    DAOfound.write(dir_name + f_name[:-5] + '_DAOStarFinder.csv',
                   overwrite=True,
                   format='ascii.fast_csv')
    DAOcoord = (DAOfound['xcentroid'], DAOfound['ycentroid'])

    # Save apertures as circular, 4 pixel radius, at each (X, Y)
    DAOapert = CircAp(DAOcoord, r=4.)
    #print('DAOapert\n ', DAOapert)

    DAOimgXY = np.array(DAOcoord)
    #print('DAOimgXY \n', DAOimgXY)

    plt.figure(figsize=(12, 12))
    ax = plt.gca()
    im = plt.imshow(img, vmax=0.35, origin='lower')
    DAOapert.plot(color='red', lw=2., alpha=0.7)
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", size="3%", pad=0.05)
    plt.colorbar(im, cax=cax)
    plt.show()

#%%
        print('No star was founded using DAOStarFinder\n' * 3)
    else:
        # Use the object "found" for aperture photometry:
        N_stars = len(DAOfound)
        print(N_stars, 'star(s) is(are) founded')
        #print('DAOfound \n', DAOfound)
        #DAOfound.pprint(max_width=1800)
        # save XY coordinates:
        DAOfound.write(f_name[:-4] + '_DAOStarFinder.csv',
                       overwrite=True,
                       format='ascii.fast_csv')
        DAOcoord = (DAOfound['xcentroid'], DAOfound['ycentroid'])
        DAOannul = CircAn(positions=DAOcoord, r_in=4 * FWHM, r_out=6 * FWHM)

        # Save apertures as circular, 4 pixel radius, at each (X, Y)
        DAOapert = CircAp(DAOcoord, r=4.)
        #print('DAOapert\n ', DAOapert)

        DAOimgXY = np.array(DAOcoord)
        #print('DAOimgXY \n', DAOimgXY)

        plt.figure(figsize=(16, 12))
        ax = plt.gca()
        im = plt.imshow(img, vmax=thresh * 4, origin='lower')
        DAOannul.plot(color='red', lw=2., alpha=0.7)
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size="3%", pad=0.05)
        plt.colorbar(im, cax=cax)
        plt.savefig(f_name[:-4] +
                    '_DAOstarfinder_Annulus_result_all_stars.png',
                    overwrite=True)
        print('No star was founded using DAOStarFinder\n' * 3)
    else:
        # Use the object "found" for aperture photometry:
        N_stars = len(DAOfound)
        print(N_stars, 'star(s) is(are) founded')
        #print('DAOfound \n', DAOfound)
        #DAOfound.pprint(max_width=1800)
        # save XY coordinates:
        DAOfound.write(f_name[:-4] + '_DAOStarFinder.csv',
                       overwrite=True,
                       format='ascii.fast_csv')
        DAOcoord = (DAOfound['xcentroid'], DAOfound['ycentroid'])
        DAOannul = CircAn(positions=DAOcoord, r_in=4 * FWHM, r_out=6 * FWHM)

        # Save apertures as circular, 4 pixel radius, at each (X, Y)
        DAOapert = CircAp(DAOcoord, r=2.0 * FWHM)
        #print('DAOapert\n ', DAOapert)

        DAOimgXY = np.array(DAOcoord)
        #print('DAOimgXY \n', DAOimgXY)

        plt.figure(figsize=(16, 12))
        ax = plt.gca()
        im = plt.imshow(img, vmax=thresh * 4, origin='lower')
        DAOannul.plot(color='red', lw=2., alpha=0.7)
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size="3%", pad=0.05)
        plt.colorbar(im, cax=cax)
        plt.savefig(f_name[:-4] +
                    '_DAOstarfinder_Annulus_result_all_stars.png',
                    overwrite=True)
Ejemplo n.º 5
0
from photutils import DAOStarFinder
from photutils import CircularAperture as CircAp

find = DAOStarFinder(
    fwhm=FWHM,
    threshold=thresh,
    sharplo=0.2,
    sharphi=1.0,  # default values 
    roundlo=-1.0,
    roundhi=1.0,  # default values
    sigma_radius=1.5,  # default values
    ratio=1.0,  # 1.0: circular gaussian
    exclude_border=True)  # To exclude sources near edges

# The DAOStarFinder object ("find") gets at least one input: the image.
# Then it returns the astropy table which contains the aperture photometry results:
found = find(img)

# Use the object "found" for aperture photometry:
# save XY coordinates:
coord = (found['xcentroid'], found['ycentroid'])

# Save apertures as circular, 4 pixel radius, at each (X, Y)
apert = CircAp(coord, r=4.)

# Draw image and overplot apertures:
plt.figure(figsize=(10, 10))
plt.imshow(img, vmax=6550)
apert.plot(color='red', lw=2., alpha=0.7)
plt.colorbar()
plt.show()