def check_imgdata_convolved(): """What is the behavior when we add the PSF to plot_pvalue?""" r1 = ui.get_psf() ui.plot_pvalue(c1, c1 + g1, conv_model=r1, num=40, bins=5) tmp = ui.get_pvalue_results() # these values are different to test_plot_pvalue_imgpsf_unconvolved # assert tmp.null == pytest.approx(2391.26963100235) assert tmp.alt == pytest.approx(563.3992697080881) assert tmp.lr == pytest.approx(1827.8703612942618) assert tmp.samples.shape == (40, 1) assert tmp.stats.shape == (40, 2) assert tmp.ratios.shape == (40, ) tmp = ui.get_pvalue_plot() assert tmp.lr == pytest.approx(1827.8703612942618) assert tmp.xlabel == 'Likelihood Ratio' assert tmp.ylabel == 'Frequency' assert tmp.title == 'Likelihood Ratio Distribution' assert tmp.ratios.shape == (40, ) assert tmp.xlo.shape == (6, ) assert tmp.xhi.shape == (6, ) assert tmp.y.shape == (6, )
def center_psf(self): """Set ``xpos`` and ``ypos`` of the PSF to the dataspace center.""" import sherpa.astro.ui as sau try: ny, nx = sau.get_data().shape for par in sau.get_psf().kernel.pars: if par.name is 'xpos': par.val = (nx + 1) / 2. elif par.name is 'ypos': par.val = (ny + 1) / 2. except: raise Exception('PSF is not centered.')
def center_psf(self): """Set xpos and ypos of the PSF to the dataspace center""" import sherpa.astro.ui as sau try: ny, nx = sau.get_data().shape for par in sau.get_psf().kernel.pars: if par.name is 'xpos': par.val = (nx + 1) / 2. elif par.name is 'ypos': par.val = (ny + 1) / 2. except: logging.warning('PSF is not centered.')
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