Ejemplo n.º 1
0
def test_psf_photometry_discrete():
    """
    Test psf_photometry with discrete PRF model.
    """
    prf = DiscretePRF(test_psf, subsampling=1)
    f = psf_photometry(image, positions, prf)
    assert_allclose(f, fluxes, rtol=1E-6)
Ejemplo n.º 2
0
def test_psf_photometry_gaussian():
    """
    Test psf_photometry with Gaussian PSF model.
    """
    prf = GaussianPSF(gaussian_width)
    f = psf_photometry(image, positions, prf)
    assert_allclose(f, fluxes, rtol=1E-3)
    
Ejemplo n.º 3
0
def calc_fwhm(image_file):
    stddev = 1.0  # pixels
    round_sigma = (stddev * stddev)**0.5
    psf_guess = psf.IntegratedGaussianPRF(flux=1, sigma=round_sigma)
    psf_guess.flux.fixed = psf_guess.x_0.fixed = psf_guess.y_0.fixed = False
    psf_guess.x_0.sigma = True

    img = load_image(image_file)

    outtabi = psf.psf_photometry(img, intab, psf_guess, fitshape)

    pdb.set_trace()

    return
Ejemplo n.º 4
0
def compute_psf_flux(image_data, sources, \
        scatter_output_path=None, bar_output_path=None, hist_output_path=None, \
        residual_path=None):
    logger.info('Computing flux...')
    coords = zip(sources['xcentroid'], sources['ycentroid'])

    psf_gaussian = GaussianPSF(1)
    computed_fluxes = psf_photometry(image_data, coords, psf_gaussian)

    if scatter_output_path:
        logger.info('Saving scatter plot...')
        plt.close('all')
        plt.scatter(sorted(sources['flux']), sorted(computed_fluxes))
        plt.xlabel('Fluxes catalog')
        plt.ylabel('Fluxes photutils')
        plt.savefig(scatter_output_path)

    if bar_output_path:
        logger.info('Saving bar chart...')
        plt.close('all')
        plt.bar(xrange(len(computed_fluxes)), computed_fluxes)
        plt.ylabel('Flux')
        plt.savefig(bar_output_path)

    if hist_output_path:
        logger.info('Saving histogram...')
        plt.close('all')
        plt.hist(computed_fluxes, bins=50)
        plt.xlabel('Flux')
        plt.ylabel('Frequency')
        plt.savefig(hist_output_path)

    if residual_path:
        residuals = subtract_psf(np.float64(image_data.copy()), psf_gaussian, coords, computed_fluxes)

        # Plot it.
        plt.close('all')
        plt.figure(figsize=(16, 12))
        plt.imshow(residuals, cmap='hot', vmin=-1, vmax=10, interpolation='None', origin='lower')
        plt.plot(coords[0], coords[1], marker='o', markerfacecolor='None', markeredgecolor='y', linestyle='None')
        plt.xlim(0, 1024)
        plt.ylim(0, 512)
        plt.colorbar(orientation='horizontal')
        plt.savefig(residual_path)
Ejemplo n.º 5
0
CORR_PATH = sys.argv[1]
IMAGE_PATH = sys.argv[2]
OUTPUT_PATH = sys.argv[3] if len(sys.argv) > 3 else 'flux_comparison.png'

corr = fits.open(CORR_PATH)
coords = zip(corr[1].data['field_x'], corr[1].data['field_y'])
catalog_fluxes = corr[1].data['FLUX']

# Convert
factor = (u.MJy / u.sr * (0.402 * u.arcsec) ** 2 / u.pixel).to(u.mJy / u.pixel)
catalog_fluxes *= factor.value

im = fits.open(IMAGE_PATH)
data = im[0].data[2]
psf_gaussian = GaussianPSF(1)
computed_fluxes = psf_photometry(data, coords, psf_gaussian)

print len(catalog_fluxes), 'sources present in metadata'

# Check
import matplotlib.pyplot as plt

plt.scatter(catalog_fluxes, computed_fluxes)
plt.xlabel('Fluxes catalog')
plt.ylabel('Fluxes photutils')

#plt.plot(numpy.sort(computed_fluxes)/numpy.sort(catalog_fluxes))
#plt.xlabel('star #')
#plt.ylabel('computed/catalog')

plt.savefig(OUTPUT_PATH)
Ejemplo n.º 6
0
srcs = sep.extract(sim.bkg_sub_img, thresh=12*sim.bkg.globalrms)
posflux = srcs[['x','y', 'flux']]

psf_guess = psf.IntegratedGaussianPRF(flux=1, sigma=8)

psf_guess.flux.fixed = False
psf_guess.x_0.fixed = False
psf_guess.y_0.fixed = False
psf_guess.x_0.sigma = True

fitshape = (64,64)
intab = Table(names=['x_0', 'y_0', 'flux_0'], data=posflux)
#subimi = psf.subtract_psf(sim.bkg_sub_img, psf_guess, posflux)

outtabi = psf.psf_photometry(sim.bkg_sub_img, intab, psf_guess, fitshape,
    store_fit_info=True)
outtabi['flux_input'] = intab['flux_0']

# with daofind there are lots of garbage
found = daofind(sim.bkg_sub_img, threshold=5*sim.bkg.globalrms, fwhm=10,
    exclude_border=True)
intab2 = Table(names=['x_0', 'y_0', 'flux_0'], data=[found['xcentroid'],
    found['ycentroid'], found['flux']])
outtabi2 = psf.psf_photometry(sim.bkg_sub_img, intab2, psf_guess, fitshape,
    store_fit_info=True)
outtabi2['flux_input'] = intab2['flux_0']



Ejemplo n.º 7
0
CORR_PATH = sys.argv[1]
IMAGE_PATH = sys.argv[2]
OUTPUT_PATH = sys.argv[3] if len(sys.argv) > 3 else 'flux_comparison.png'

corr = fits.open(CORR_PATH)
coords = zip(corr[1].data['field_x'], corr[1].data['field_y'])
catalog_fluxes = corr[1].data['FLUX']

# Convert
factor = (u.MJy / u.sr * (0.402 * u.arcsec)**2 / u.pixel).to(u.mJy / u.pixel)
catalog_fluxes *= factor.value

im = fits.open(IMAGE_PATH)
data = im[0].data[2]
psf_gaussian = GaussianPSF(1)
computed_fluxes = psf_photometry(data, coords, psf_gaussian)

print len(catalog_fluxes), 'sources present in metadata'

# Check
import matplotlib.pyplot as plt

plt.scatter(catalog_fluxes, computed_fluxes)
plt.xlabel('Fluxes catalog')
plt.ylabel('Fluxes photutils')

#plt.plot(numpy.sort(computed_fluxes)/numpy.sort(catalog_fluxes))
#plt.xlabel('star #')
#plt.ylabel('computed/catalog')

plt.savefig(OUTPUT_PATH)