示例#1
0
def plotTestImage(imageArray):
    interval = ZScaleInterval()
    limits = interval.get_limits(imageArray)
    sources = locateStarsInImage(imageArray)
    positions = np.transpose((sources['xcentroid'], sources['ycentroid']))
    apertures = CircularAperture(positions, r=4.)
    norm = ImageNormalize(stretch=SqrtStretch())
    plt.imshow(imageArray,
               cmap='Greys',
               origin='lower',
               norm=norm,
               interpolation='nearest',
               vmin=limits[0],
               vmax=limits[1])
    apertures.plot(color='red', lw=1.5, alpha=0.5)
    plt.show()
示例#2
0
def compute_eff_radii(image, plot=False):
    max_pix_rad = np.min(image.shape) // 2
    radius = np.arange(3, max_pix_rad, 3)
    fake_image = np.zeros_like(image)
    fake_image[max_pix_rad // 2:(3 * max_pix_rad) // 2,
               max_pix_rad // 2:(3 * max_pix_rad) //
               2] = image[max_pix_rad // 2:(3 * max_pix_rad) // 2,
                          max_pix_rad // 2:(3 * max_pix_rad) // 2]
    com_x, com_y = centroid_2dg(fake_image)
    aperture_sum = []
    for rad_i in radius:
        aperture = CircularAperture((com_x, com_y), r=rad_i)
        phot_table = aperture_photometry(image, aperture)
        aperture_sum.append(phot_table['aperture_sum'].value)
    aperture_sum = np.array(aperture_sum).squeeze()
    norm_aperture_sum = aperture_sum / aperture_sum[-1]
    half_mass_rad = np.interp(0.5, norm_aperture_sum, radius)
    half_mass_aperture = CircularAperture((com_x, com_y), r=half_mass_rad)
    two_half_mass_aperture = CircularAperture((com_x, com_y),
                                              r=2 * half_mass_rad)
    half_mass_table = aperture_photometry(image, half_mass_aperture)
    two_half_mass_table = aperture_photometry(image, two_half_mass_aperture)
    if plot:
        fig = plt.figure()
        plt.imshow(np.log10(image))
        plt.colorbar(label='log(image)')
        plt.plot(com_x, com_y, '+', markersize=8, color='c')
        half_mass_aperture.plot(color='r', lw=2, label=r'Half mass rad')
        two_half_mass_aperture.plot(color='orange',
                                    lw=2,
                                    label=r'Two half mass rad')
        plt.annotate(
            'Tot mass={:.2}\nHalf mass={:.2}\nTwoHalf mass={:.2}'.format(
                float(aperture_sum[-1]),
                float(half_mass_table['aperture_sum'].value),
                float(two_half_mass_table['aperture_sum'].value)),
            xy=(.1, 1),
            xycoords='axes fraction',
            va='bottom')
        plt.legend()
        plt.close()
        return half_mass_aperture, two_half_mass_aperture, fig
    else:
        return half_mass_aperture, two_half_mass_aperture
示例#3
0
 def compute_circular_aperture(self, centre, radius, flux_return=False,
                               plot=False):
     from photutils.aperture import CircularAperture#, aperture_photometry
     aperture = CircularAperture(centre, r=radius)
     aperture_mask = aperture.to_mask()
     aperture_mask = np.array(
         aperture_mask.to_image(self.wcs.celestial.array_shape), dtype=bool)
     
     if flux_return:
         integrated_flux = np.nansum(self.flux[:, aperture_mask], axis=1)
         integrated_no_cov = np.nansum(self.flux_error[:, aperture_mask]**2, axis=1)
         ## Accounting for covariance errors
         if aperture_mask[aperture_mask].size<100:
             integrated_flux_cov = integrated_no_cov*(
                 1+1.62*np.log10(aperture_mask[aperture_mask].size))
             integrated_flux_err = np.sqrt(integrated_flux_cov)
         else:
             integrated_flux_cov = integrated_no_cov*4.2
             integrated_flux_err = np.sqrt(integrated_flux_cov)
     else:
         integrated_flux = None
         integrated_flux_err = None
     if plot:
         fig = plt.figure()
         ax = fig.add_subplot(111)
         ax.imshow(self.flux[self.wl.size//2, :, :], cmap='gist_earth_r')            
         aperture.plot(lw=1, color='r')
         ax.annotate(r'$R_e={:4.3}~(Kpc)$'.format(self.eff_radius_physical),
                     xy=(.9,.95), xycoords='axes fraction', va='top', ha='right')            
         ax.annotate(r'$R_e={:4.3}~(arcsec)$'.format(self.eff_radius),
                     xy=(.9,.9), xycoords='axes fraction', va='top', ha='right')
         aperture.plot(lw=1, color='r')
         ax.annotate(r'$R_e={:4.3}~(pix)$'.format(self.eff_radius_pix),
                     xy=(.9,.85), xycoords='axes fraction', va='top', ha='right')
         ax.annotate(r'$R_a={:4.3}~(pix)$'.format(radius),
                     xy=(.9,.80), xycoords='axes fraction', va='top', ha='right',
                     color='r')
         aperture.plot(lw=1, color='r')
         # plt.savefig('bpt_apertures/'+name_i+'.png')
         plt.show()
         plt.close()
         return aperture, aperture_mask, integrated_flux, integrated_flux_err, fig 
     else:           
         return aperture, aperture_mask, integrated_flux, integrated_flux_err    
示例#4
0
        flux_companion = aperture_photometry(data[0], [aperture, annulus])
        bkg_mean = flux_companion['aperture_sum_1'] / annulus.area
        bkg_sum_in_companion = bkg_mean * aperture.area

        print(flux_companion)
        print("bkg_mean =", bkg_mean[0], "\naperture.area =", aperture.area,
              "\nannulus.area =", annulus.area)
        print("bkg_sum_in_companion =", bkg_sum_in_companion[0])
        flux_companion_origin = flux_companion[
            'aperture_sum_0'] - bkg_sum_in_companion
        print("flux companion origin =", flux_companion_origin[0])

        norm = simple_norm(data, 'sqrt', percent=99)
        plt.imshow(data[0], norm=norm, interpolation='nearest')
        ap_patches = aperture.plot(color='white',
                                   lw=2,
                                   label='Photometry aperture')
        ann_patches = annulus.plot(color='red',
                                   lw=2,
                                   label='Background annulus')
        #handles=(ap_patches[0],ann_patches[0])
        plt.legend(loc=(0.17, 0.05),
                   facecolor='#458989',
                   labelcolor='white',
                   prop={
                       'weight': 'bold',
                       'size': 11
                   })
        plt.xlim(20, 170)
        plt.ylim(20, 256)
        #plt.savefig('./Origin_Companion_Flux.png')
示例#5
0
r_out = r_in + 15
annulus = CircularAnnulus(positions, r_in=r_in, r_out=r_out)

# plot image with apertures
y_or_n = input('Do you wish to display the image and appertures? ')
if (y_or_n[0] == 'y') or (y_or_n[0] == 'Y'):
    plt.figure(1)
    plt.clf()

    # label the sources
    mylabels = sources['id']
    for idx, txt in enumerate(mylabels):
        plt.annotate(txt, (positions[idx, 0], positions[idx, 1]))

    plt.imshow(np.log(imdata), cmap='Greys')
    apertures.plot(color='red', lw=1.5, alpha=0.5)
    annulus.plot(color='green', lw=1.5, alpha=0.5)
    plt.show()

# sum signal in source apertures
aper_ann = [apertures, annulus]
phot_table = aperture_photometry(imdata, aper_ann)

# Find the background per pixel from the annulus
print('\nMean background per pixel:')
phot_table['mean_bkg'] = phot_table['aperture_sum_1'] / annulus.area
phot_table['id', 'mean_bkg'].pprint()

# Compute the background signal contribution to the aperture
bkg_signal = phot_table['mean_bkg'] * apertures.area
source_counts = phot_table['aperture_sum_0'] - bkg_signal