def test_psf_king_write(psf_king, tmpdir): filename = str(tmpdir / "king.fits") psf_king.write(filename) psf_king2 = PSFKing.read(filename) assert_quantity_allclose(psf_king2.energy, psf_king.energy) assert_quantity_allclose(psf_king2.offset, psf_king.offset) assert_quantity_allclose(psf_king2.gamma, psf_king.gamma) assert_quantity_allclose(psf_king2.sigma, psf_king.sigma)
def test_psf_king_write(psf_king, tmp_path): psf_king.write(tmp_path / "tmp.fits") psf_king2 = PSFKing.read(tmp_path / "tmp.fits") assert_quantity_allclose(psf_king2.energy, psf_king.energy) assert_quantity_allclose(psf_king2.offset, psf_king.offset) assert_quantity_allclose(psf_king2.gamma, psf_king.gamma) assert_quantity_allclose(psf_king2.sigma, psf_king.sigma)
def test_psf_king_write(psf_king, tmp_path): psf_king.write(tmp_path / "tmp.fits") psf_king2 = PSFKing.read(tmp_path / "tmp.fits") assert_quantity_allclose(psf_king2.energy_axis_true.edges, psf_king.energy_axis_true.edges) assert_quantity_allclose(psf_king2.offset_axis.center, psf_king.offset_axis.center) assert_quantity_allclose(psf_king2.gamma, psf_king.gamma) assert_quantity_allclose(psf_king2.sigma, psf_king.sigma)
def test_psf_king_write(psf_king, tmp_path): psf_king.write(tmp_path / "tmp.fits") psf_king2 = PSFKing.read(tmp_path / "tmp.fits") assert_allclose(psf_king2.axes["energy_true"].edges, psf_king.axes["energy_true"].edges) assert_allclose(psf_king2.axes["offset"].center, psf_king.axes["offset"].center) assert_allclose(psf_king2.data["gamma"], psf_king.data["gamma"]) assert_allclose(psf_king2.data["sigma"], psf_king.data["sigma"])
def load(self): """Load HDU as appropriate class. TODO: this should probably go via an extensible registry. """ hdu_class = self.hdu_class filename = self.path() hdu = self.hdu_name if hdu_class == "events": from gammapy.data import EventList return EventList.read(filename, hdu=hdu) elif hdu_class == "gti": from gammapy.data import GTI return GTI.read(filename, hdu=hdu) elif hdu_class == "aeff_2d": from gammapy.irf import EffectiveAreaTable2D return EffectiveAreaTable2D.read(filename, hdu=hdu) elif hdu_class == "edisp_2d": from gammapy.irf import EnergyDispersion2D return EnergyDispersion2D.read(filename, hdu=hdu) elif hdu_class == "psf_table": from gammapy.irf import PSF3D return PSF3D.read(filename, hdu=hdu) elif hdu_class == "psf_3gauss": from gammapy.irf import EnergyDependentMultiGaussPSF return EnergyDependentMultiGaussPSF.read(filename, hdu=hdu) elif hdu_class == "psf_king": from gammapy.irf import PSFKing return PSFKing.read(filename, hdu=hdu) elif hdu_class == "bkg_2d": from gammapy.irf import Background2D return Background2D.read(filename, hdu=hdu) elif hdu_class == "bkg_3d": from gammapy.irf import Background3D return Background3D.read(filename, hdu=hdu) else: raise ValueError(f"Invalid hdu_class: {hdu_class}")
def load_psf(chain='hd', tool='gammapy'): """Load a test PSF.""" if chain == 'hd': filename = '$GAMMAPY_EXTRA/datasets/hess-crab4-hd-hap-prod2-input/run023400-023599/run023523/hess_psf_king_023523.fits.gz' if tool == 'gammalib': filename += '[PSF_2D_KING]' elif chain == 'pa': filename = '$GAMMAPY_EXTRA/datasets/hess-crab4-pa/run23400-23599/run23523/psf_king_23523.fits.gz' else: raise ValueError('Invalid chain: {}'.format(chain)) print('Reading {}'.format(filename)) if tool == 'gammapy': return PSFKing.read(filename) elif tool == 'gammalib': from gammalib import GCTAPsfKing return GCTAPsfKing(filename) else: raise ValueError('Invalid tool: {}'.format(tool))
def psf_king(): return PSFKing.read("$GAMMAPY_DATA/tests/hess_psf_king_023523.fits.gz")
def psf_king(): filename = "$GAMMAPY_DATA/tests/hess-crab4-hd-hap-prod2/run023400-023599/run023523/hess_psf_king_023523.fits.gz" return PSFKing.read(filename)