def assert_allclose(image1, image2, check_wcs=True, check_name=True, check_unit=True): """Assert all-close for `SkyImage`. A useful helper function to implement tests. """ from numpy.testing import assert_allclose from gammapy.utils.testing import assert_wcs_allclose if check_name: assert image1.name == image2.name if (image1.data is None) and (image2.data is None): pass elif (image1.data is not None) and (image2.data is not None): assert_allclose(image1.data, image2.data) else: raise ValueError('One image has `data==None` and the other does not.') if check_wcs is False: pass elif (image1.wcs is None) and (image2.wcs is None): pass elif (image1.wcs is not None) and (image2.wcs is not None): assert_wcs_allclose(image1.wcs, image2.wcs) else: raise ValueError('One image has `wcs==None` and the other does not.') if check_unit: assert image1.unit == image2.unit
def assert_allclose(image1, image2, check_wcs=True): """Assert all-close for `SkyImage`. A useful helper function to implement tests. """ from numpy.testing import assert_allclose from gammapy.utils.testing import assert_wcs_allclose assert image1.name == image2.name if (image1.data is None) and (image2.data is None): pass elif (image1.data is not None) and (image2.data is not None): assert_allclose(image1.data, image2.data) else: raise ValueError( 'One image has `data==None` and the other does not.') if check_wcs is False: pass elif (image1.wcs is None) and (image2.wcs is None): pass elif (image1.wcs is not None) and (image2.wcs is not None): assert_wcs_allclose(image1.wcs, image2.wcs) else: raise ValueError( 'One image has `wcs==None` and the other does not.')
def test_bin_image_main(tmpdir): """Run ``gammapy-bin-image`` and compare result to ``ctskymap``. """ event_file = "$GAMMAPY_DATA/tests/irf/hess/pa/hess_events_023523.fits.gz" reference_file = "$GAMMAPY_DATA/tests/irf/hess/pa/ctskymap.fits.gz" out_file = str(tmpdir / "gammapy_ctskymap.fits.gz") args = ["image", "bin", event_file, reference_file, out_file] run_cli(cli, args) actual = Map.read(out_file) expected = Map.read(reference_file) assert_allclose(actual.data, expected.data) assert_wcs_allclose(actual.geom.wcs, expected.geom.wcs)