test funciton for healpy map read function
@@ -506,3 +506,32 @@ def test_smooth(kernel):
with pytest.raises(ValueError):
m_nest.smooth(0.2 * u.deg, "box")
+
+def test_hpxmap_read_healpy(tmp_path):
+ path = tmp_path / "tmp.fits"
+
+ npix = 12 * 1024 * 1024
+ m = [np.arange(npix), np.arange(npix)-1, np.arange(npix)-2]
+ import healpy as hp
+ hp.write_map(
+ filename=path,
+ m=m, nest=False,
+ column_names=["data map", "background map", "exposure map"],
+ overwrite=True
+ )
+ from gammapy.maps.utils import find_bintable_hdu
+ from gammapy.maps.hpx import HpxConv
+ with fits.open(path, memmap=False) as hdulist:
+ hdu_out = find_bintable_hdu(hdulist)
+ header = hdu_out.header
+ assert header["PIXTYPE"] == "HEALPIX"
+ assert header["ORDERING"] == "RING"
+ assert header["EXTNAME"] == "xtension"
+ assert header["NSIDE"] == 1024
+ format = HpxConv.identify_hpx_format(header)
+ assert format == "healpy"
+
+ m1 = Map.read(path)
+ assert m1.data.shape[0] == npix
+ diff = np.sum(m[0] - m1.data)
+ assert_allclose(diff, 0.0)
