def containment_fraction(self, theta, npix=1000): """Compute fraction of PSF contained inside theta.""" import sherpa.astro.ui as sau sau.dataspace2d((npix, npix)) self.set() # x_center = get_psf().kernel.pars.xpos # y_center = get_psf().kernel.pars.ypos x_center, y_center = sau.get_psf().model.center x_center, y_center = x_center + 0.5, y_center + 0.5 # shift seen on image. x, y = sau.get_data().x0, sau.get_data().x1 # Note: Here we have to use the source image, before I used # get_model_image(), which returns the PSF-convolved PSF image, # which is a factor of sqrt(2) ~ 1.4 too wide!!! p = sau.get_source_image().y.flatten() p /= np.nansum(p) mask = (x - x_center)**2 + (y - y_center)**2 < theta**2 fraction = np.nansum(p[mask]) if 0: # debug sau.get_data().y = p sau.save_data('psf_sherpa.fits', clobber=True) sau.get_data().y = mask.astype('int') sau.save_data('mask_sherpa.fits', clobber=True) return fraction
def containment_fraction(self, theta, npix=1000): """Compute fraction of PSF contained inside theta.""" import sherpa.astro.ui as sau sau.dataspace2d((npix, npix)) self.set() # x_center = get_psf().kernel.pars.xpos # y_center = get_psf().kernel.pars.ypos x_center, y_center = sau.get_psf().model.center x_center, y_center = x_center + 0.5, y_center + 0.5 # shift seen on image. x, y = sau.get_data().x0, sau.get_data().x1 # @note Here we have to use the source image, before I used # get_model_image(), which returns the PSF-convolved PSF image, # which is a factor of sqrt(2) ~ 1.4 too wide!!! p = sau.get_source_image().y.flatten() p /= np.nansum(p) mask = (x - x_center) ** 2 + (y - y_center) ** 2 < theta ** 2 fraction = np.nansum(p[mask]) if 0: # debug sau.get_data().y = p sau.save_data('psf_sherpa.fits', clobber=True) sau.get_data().y = mask.astype('int') sau.save_data('mask_sherpa.fits', clobber=True) return fraction