Guest User

Untitled

a guest
Oct 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 93.93 KB | None | 0 0
  1. ______________________________________________ test_mapbase_create[0.1-10.0-hpx-skydir4-axes4] ______________________________________________
  2.  
  3. binsz = 0.1, width = 10.0, map_type = 'hpx', skydir = <SkyCoord (ICRS): (ra, dec) in deg
  4. ( 0., 30.)>
  5. axes = [<gammapy.maps.geom.MapAxis object at 0x118027c50>]
  6.  
  7. @pytest.mark.parametrize(('binsz', 'width', 'map_type', 'skydir', 'axes'),
  8. mapbase_args)
  9. def test_mapbase_create(binsz, width, map_type, skydir, axes):
  10. m = MapBase.create(binsz=binsz, width=width, map_type=map_type,
  11. > skydir=skydir, axes=axes)
  12.  
  13. gammapy/maps/tests/test_base.py:31:
  14. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  15. gammapy/maps/base.py:100: in create
  16. return HpxMap.create(**kwargs)
  17. gammapy/maps/hpxmap.py:78: in create
  18. return HpxMapND(hpx, dtype=dtype)
  19. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  20.  
  21. self = <gammapy.maps.hpxcube.HpxMapND object at 0x1181acdd8>, hpx = <gammapy.maps.hpx.HpxGeom object at 0x118147748>
  22. data = array([[ nan, nan, nan, ..., nan, nan, nan],
  23. [ nan, nan, nan, ..., nan, nan, nan],
  24. [ nan, nan, nan, ..., nan, nan, nan]], dtype=float32)
  25. dtype = 'float32'
  26.  
  27. def __init__(self, hpx, data=None, dtype='float32'):
  28.  
  29. shape = tuple([np.max(hpx.npix)] + [ax.nbin for ax in hpx.axes])
  30. if data is None:
  31.  
  32. if hpx.npix.size > 1:
  33. data = np.nan * np.ones(shape, dtype=dtype).T
  34. pix = hpx.get_pixels(local=True)
  35. > data[pix[::-1]] = 0.0
  36. E IndexError: index 6155 is out of bounds for axis 1 with size 6155
  37.  
  38. gammapy/maps/hpxcube.py:41: IndexError
  39. ______________________________________________ test_mapbase_create[0.1-10.0-hpx-skydir5-axes5] ______________________________________________
  40.  
  41. binsz = 0.1, width = 10.0, map_type = 'hpx', skydir = <SkyCoord (ICRS): (ra, dec) in deg
  42. ( 0., 30.)>
  43. axes = [<gammapy.maps.geom.MapAxis object at 0x118027c50>, <gammapy.maps.geom.MapAxis object at 0x118027da0>]
  44.  
  45. @pytest.mark.parametrize(('binsz', 'width', 'map_type', 'skydir', 'axes'),
  46. mapbase_args)
  47. def test_mapbase_create(binsz, width, map_type, skydir, axes):
  48. m = MapBase.create(binsz=binsz, width=width, map_type=map_type,
  49. > skydir=skydir, axes=axes)
  50.  
  51. gammapy/maps/tests/test_base.py:31:
  52. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  53. gammapy/maps/base.py:100: in create
  54. return HpxMap.create(**kwargs)
  55. gammapy/maps/hpxmap.py:78: in create
  56. return HpxMapND(hpx, dtype=dtype)
  57. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  58.  
  59. self = <gammapy.maps.hpxcube.HpxMapND object at 0x11843fef0>, hpx = <gammapy.maps.hpx.HpxGeom object at 0x1143d5b00>
  60. data = array([[[ nan, nan, nan, ..., nan, nan, nan],
  61. [ nan, nan, nan, ..., nan, nan, nan],
  62. [ nan, ...
  63. [ nan, nan, nan, ..., nan, nan, nan],
  64. [ nan, nan, nan, ..., nan, nan, nan]]], dtype=float32)
  65. dtype = 'float32'
  66.  
  67. def __init__(self, hpx, data=None, dtype='float32'):
  68.  
  69. shape = tuple([np.max(hpx.npix)] + [ax.nbin for ax in hpx.axes])
  70. if data is None:
  71.  
  72. if hpx.npix.size > 1:
  73. data = np.nan * np.ones(shape, dtype=dtype).T
  74. pix = hpx.get_pixels(local=True)
  75. > data[pix[::-1]] = 0.0
  76. E IndexError: index 6155 is out of bounds for axis 2 with size 6155
  77.  
  78. gammapy/maps/hpxcube.py:41: IndexError
  79. _________________________________________________________ test_hpx_global_to_local __________________________________________________________
  80.  
  81. def test_hpx_global_to_local():
  82. ax0 = np.linspace(0., 1., 3)
  83. ax1 = np.linspace(0., 1., 3)
  84.  
  85. # 2D All-sky
  86. hpx = HpxGeom(16, False, 'GAL')
  87. assert_allclose(hpx[0], np.array([0]))
  88. assert_allclose(hpx[633], np.array([633]))
  89. assert_allclose(hpx[0, 633], np.array([0, 633]))
  90. assert_allclose(hpx[np.array([0, 633])], np.array([0, 633]))
  91.  
  92. # 3D All-sky
  93. hpx = HpxGeom(16, False, 'GAL', axes=[ax0])
  94. assert_allclose(hpx[(np.array([177, 177]), np.array([0, 1]))],
  95. np.array([177, 177 + 3072]))
  96.  
  97. # 2D Partial-sky
  98. hpx = HpxGeom(64, False, 'GAL', region='DISK(110.,75.,2.)')
  99. > assert_allclose(hpx[0, 633, 706], np.array([-1, 0, 2]))
  100. E AssertionError:
  101. E Not equal to tolerance rtol=1e-07, atol=0
  102. E
  103. E (mismatch 33.33333333333333%)
  104. E x: array([-1, 0, 0], dtype=int32)
  105. E y: array([-1, 0, 2])
  106.  
  107. gammapy/maps/tests/test_hpx.py:87: AssertionError
  108. _______________________________________ test_hpxgeom_get_pixels[8-False-GAL-DISK(110.,75.,10.)-None] ________________________________________
  109.  
  110. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = None
  111.  
  112. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  113. hpx_test_geoms)
  114. def test_hpxgeom_get_pixels(nside, nested, coordsys, region, axes):
  115.  
  116. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  117. pix = geom.get_pixels(local=False)
  118. pix_local = geom.get_pixels(local=True)
  119. > assert_allclose(pix, geom.local_to_global(pix_local))
  120. E AssertionError:
  121. E Not equal to tolerance rtol=1e-07, atol=0
  122. E
  123. E (mismatch 66.66666666666666%)
  124. E x: array([[ 6, 1, 0, 5, 14, 15, 29, 16, 7, 28, 46, 27]])
  125. E y: array([[14, 5, 6, 5, 14, 28, 46, 28, 14, 28, 46, 28]])
  126.  
  127. gammapy/maps/tests/test_hpx.py:175: AssertionError
  128. _______________________________________ test_hpxgeom_get_pixels[8-False-GAL-DISK(110.,75.,10.)-axes5] _______________________________________
  129.  
  130. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = [<gammapy.maps.geom.MapAxis object at 0x11808cc50>]
  131.  
  132. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  133. hpx_test_geoms)
  134. def test_hpxgeom_get_pixels(nside, nested, coordsys, region, axes):
  135.  
  136. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  137. pix = geom.get_pixels(local=False)
  138. pix_local = geom.get_pixels(local=True)
  139. > assert_allclose(pix, geom.local_to_global(pix_local))
  140. E AssertionError:
  141. E Not equal to tolerance rtol=1e-07, atol=0
  142. E
  143. E (mismatch 33.33333333333333%)
  144. E x: array([[ 6, 1, 0, 5, 14, 15, 29, 16, 7, 28, 46, 27, 6, 1, 0, 5, 14,
  145. E 15, 29, 16, 7, 28, 46, 27, 6, 1, 0, 5, 14, 15, 29, 16, 7, 28,
  146. E 46, 27],...
  147. E y: array([[14, 5, 6, 5, 14, 28, 46, 28, 14, 28, 46, 28, 14, 5, 6, 5, 14,
  148. E 28, 46, 28, 14, 28, 46, 28, 14, 5, 6, 5, 14, 28, 46, 28, 14, 28,
  149. E 46, 28],...
  150.  
  151. gammapy/maps/tests/test_hpx.py:175: AssertionError
  152. ____________________________________ test_hpxgeom_get_pixels[nside6-False-GAL-DISK(110.,75.,10.)-axes6] _____________________________________
  153.  
  154. nside = [8, 16, 32], nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  155. axes = [<gammapy.maps.geom.MapAxis object at 0x11808cc88>]
  156.  
  157. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  158. hpx_test_geoms)
  159. def test_hpxgeom_get_pixels(nside, nested, coordsys, region, axes):
  160.  
  161. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  162. pix = geom.get_pixels(local=False)
  163. > pix_local = geom.get_pixels(local=True)
  164.  
  165. gammapy/maps/tests/test_hpx.py:174:
  166. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  167. gammapy/maps/hpx.py:1363: in get_pixels
  168. return self.global_to_local(pix)
  169. gammapy/maps/hpx.py:536: in global_to_local
  170. retval = unravel_hpx_index(retval, self._npix)
  171. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  172.  
  173. idx = array([ 4, 3, 0, 3, 9, 9, 12, 6, 4, 6, 12, 6, 35,
  174. 16, 12, 15, 35, 37, 39, 37, 17,...67, 76, 140, 48, 48, 48, 48, 48, 48,
  175. 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48], dtype=int32)
  176. npix = array([ 12, 36, 119])
  177.  
  178. def unravel_hpx_index(idx, npix):
  179. """Convert flattened global map index to an index tuple.
  180.  
  181. Parameters
  182. ----------
  183. idx : `~numpy.ndarray`
  184. Flat index.
  185. npix : `~numpy.ndarray`
  186. Number of pixels in each band.
  187.  
  188. Returns
  189. -------
  190. idx : tuple of `~numpy.ndarray`
  191. Index array for each dimension of the map.
  192. """
  193. if npix.size == 1:
  194. return tuple([idx])
  195.  
  196. dpix = np.zeros(npix.size, dtype='i')
  197. dpix[1:] = np.cumsum(npix.flat[:-1])
  198. bidx = np.searchsorted(np.cumsum(npix.flat), idx + 1)
  199. > pix = idx - dpix[bidx]
  200. E IndexError: index 3 is out of bounds for axis 1 with size 3
  201.  
  202. gammapy/maps/hpx.py:101: IndexError
  203. ____________________________________ test_hpxgeom_get_pixels[nside7-False-GAL-DISK(110.,75.,10.)-axes7] _____________________________________
  204.  
  205. nside = [[8, 16, 32], [8, 8, 16]], nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  206. axes = [<gammapy.maps.geom.MapAxis object at 0x11808ccc0>, <gammapy.maps.geom.MapAxis object at 0x11808ccf8>]
  207.  
  208. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  209. hpx_test_geoms)
  210. def test_hpxgeom_get_pixels(nside, nested, coordsys, region, axes):
  211.  
  212. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  213. pix = geom.get_pixels(local=False)
  214. > pix_local = geom.get_pixels(local=True)
  215.  
  216. gammapy/maps/tests/test_hpx.py:174:
  217. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  218. gammapy/maps/hpx.py:1363: in get_pixels
  219. return self.global_to_local(pix)
  220. gammapy/maps/hpx.py:536: in global_to_local
  221. retval = unravel_hpx_index(retval, self._npix)
  222. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  223.  
  224. idx = array([ 4, 3, 0, 3, 4, 5, 12, 6, 4, 9, 10, 9, 33,
  225. 12, 12, 12, 16, 37, 39, 37, 17,... 191, 191, 212, 191, 212, 212, 214, 215, 216, 217, 220, 218, 220,
  226. 220, 227, 220, 227, 220, 218], dtype=int32)
  227. npix = array([[ 12, 36, 119],
  228. [ 12, 12, 36]])
  229.  
  230. def unravel_hpx_index(idx, npix):
  231. """Convert flattened global map index to an index tuple.
  232.  
  233. Parameters
  234. ----------
  235. idx : `~numpy.ndarray`
  236. Flat index.
  237. npix : `~numpy.ndarray`
  238. Number of pixels in each band.
  239.  
  240. Returns
  241. -------
  242. idx : tuple of `~numpy.ndarray`
  243. Index array for each dimension of the map.
  244. """
  245. if npix.size == 1:
  246. return tuple([idx])
  247.  
  248. dpix = np.zeros(npix.size, dtype='i')
  249. dpix[1:] = np.cumsum(npix.flat[:-1])
  250. bidx = np.searchsorted(np.cumsum(npix.flat), idx + 1)
  251. > pix = idx - dpix[bidx]
  252. E IndexError: index 6 is out of bounds for axis 1 with size 6
  253.  
  254. gammapy/maps/hpx.py:101: IndexError
  255. __________________________________________ test_hpxgeom_coord_to_idx[nside2-False-GAL-None-axes2] ___________________________________________
  256.  
  257. nside = array([2, 4, 8, 2, 4, 8, 2, 4, 8, 2, 4, 8, 2, 4, 8, 2, 4, 8, 2, 4, 8, 2, 4,
  258. 8, 2, 4, 8]), nested = False, coordsys = 'GAL'
  259. region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x11808cba8>]
  260.  
  261. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  262. hpx_test_geoms)
  263. def test_hpxgeom_coord_to_idx(nside, nested, coordsys, region, axes):
  264. from astropy_healpix import healpy as hp
  265.  
  266. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  267. lon = np.array([112.5, 135., 105.])
  268. lat = np.array([75.3, 75.3, 74.6])
  269. coords = make_test_coords(geom, lon, lat)
  270. zidx = [ax.coord_to_idx(t) for t, ax in zip(coords[2:], geom.axes)]
  271.  
  272. if geom.nside.size > 1:
  273. nside = geom.nside[zidx]
  274. else:
  275. nside = geom.nside
  276.  
  277. phi, theta = lonlat_to_colat(coords[0], coords[1])
  278. > idx = geom.coord_to_idx(coords)
  279.  
  280. gammapy/maps/tests/test_hpx.py:200:
  281. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  282. gammapy/maps/geom.py:808: in coord_to_idx
  283. pix = self.coord_to_pix(coords)
  284. gammapy/maps/hpx.py:612: in coord_to_pix
  285. pix = hp.ang2pix(nside, theta, phi, nest=self.nest)
  286. ../astropy-healpix/astropy_healpix/healpy.py:105: in ang2pix
  287. return lonlat_to_healpix(lon, lat, nside, order='nested' if nest else 'ring')
  288. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  289.  
  290. lon = array([ 1.96349541, 1.96349541, 1.96349541, 2.35619449, 2.35619449,
  291. 2.35619449, 1.83259571, 1.83259571, ... 1.96349541,
  292. 1.96349541, 2.35619449, 2.35619449, 2.35619449, 1.83259571,
  293. 1.83259571, 1.83259571])
  294. lat = array([ 1.31423293, 1.31423293, 1.31423293, 1.31423293, 1.31423293,
  295. 1.31423293, 1.31423293, 1.31423293, ... 1.30201562,
  296. 1.30201562, 1.30201562, 1.30201562, 1.30201562, 1.30201562,
  297. 1.30201562, 1.30201562])
  298. nside = array([2, 4, 8, 2, 4, 8, 2, 4, 8, 2, 4, 8, 2, 4, 8, 2, 4, 8, 2, 4, 8, 2, 4,
  299. 8, 2, 4, 8]), return_offsets = False
  300. order = 'ring'
  301.  
  302. def lonlat_to_healpix(lon, lat, nside, return_offsets=False, order='ring'):
  303. """
  304. Convert longitudes/latitudes to HEALPix indices
  305.  
  306. Parameters
  307. ----------
  308. lon, lat : :class:`~astropy.units.Quantity`
  309. The longitude and latitude values as :class:`~astropy.units.Quantity`
  310. instances with angle units.
  311. nside : int
  312. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  313. order : { 'nested' | 'ring' }
  314. Order of HEALPix pixels
  315. return_offsets : bool, optional
  316. If `True`, the returned values are the HEALPix pixel indices as well as
  317. ``dx`` and ``dy``, the fractional positions inside the pixels. If
  318. `False` (the default), only the HEALPix pixel indices is returned.
  319.  
  320. Returns
  321. -------
  322. healpix_index : int or `~numpy.ndarray`
  323. The HEALPix indices
  324. dx, dy : `~numpy.ndarray`
  325. Offsets inside the HEALPix pixel in the range [0:1], where 0.5 is the
  326. center of the HEALPix pixels
  327. """
  328.  
  329. lon = lon.to(u.rad).value
  330. lat = lat.to(u.rad).value
  331.  
  332. lon, lat = np.broadcast_arrays(lon, lat)
  333.  
  334. shape = np.shape(lon)
  335.  
  336. lon = lon.astype(float).ravel()
  337. lat = lat.astype(float).ravel()
  338.  
  339. > nside = int(nside)
  340. E TypeError: only length-1 arrays can be converted to Python scalars
  341.  
  342. ../astropy-healpix/astropy_healpix/core.py:341: TypeError
  343. ___________________________________ test_hpxgeom_coord_to_idx[nside6-False-GAL-DISK(110.,75.,10.)-axes6] ____________________________________
  344.  
  345. nside = array([ 8, 16, 32, 8, 16, 32, 8, 16, 32, 8, 16, 32, 8, 16, 32, 8, 16,
  346. 32, 8, 16, 32, 8, 16, 32, 8, 16, 32])
  347. nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = [<gammapy.maps.geom.MapAxis object at 0x11808cc88>]
  348.  
  349. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  350. hpx_test_geoms)
  351. def test_hpxgeom_coord_to_idx(nside, nested, coordsys, region, axes):
  352. from astropy_healpix import healpy as hp
  353.  
  354. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  355. lon = np.array([112.5, 135., 105.])
  356. lat = np.array([75.3, 75.3, 74.6])
  357. coords = make_test_coords(geom, lon, lat)
  358. zidx = [ax.coord_to_idx(t) for t, ax in zip(coords[2:], geom.axes)]
  359.  
  360. if geom.nside.size > 1:
  361. nside = geom.nside[zidx]
  362. else:
  363. nside = geom.nside
  364.  
  365. phi, theta = lonlat_to_colat(coords[0], coords[1])
  366. > idx = geom.coord_to_idx(coords)
  367.  
  368. gammapy/maps/tests/test_hpx.py:200:
  369. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  370. gammapy/maps/geom.py:808: in coord_to_idx
  371. pix = self.coord_to_pix(coords)
  372. gammapy/maps/hpx.py:612: in coord_to_pix
  373. pix = hp.ang2pix(nside, theta, phi, nest=self.nest)
  374. ../astropy-healpix/astropy_healpix/healpy.py:105: in ang2pix
  375. return lonlat_to_healpix(lon, lat, nside, order='nested' if nest else 'ring')
  376. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  377.  
  378. lon = array([ 1.96349541, 1.96349541, 1.96349541, 2.35619449, 2.35619449,
  379. 2.35619449, 1.83259571, 1.83259571, ... 1.96349541,
  380. 1.96349541, 2.35619449, 2.35619449, 2.35619449, 1.83259571,
  381. 1.83259571, 1.83259571])
  382. lat = array([ 1.31423293, 1.31423293, 1.31423293, 1.31423293, 1.31423293,
  383. 1.31423293, 1.31423293, 1.31423293, ... 1.30201562,
  384. 1.30201562, 1.30201562, 1.30201562, 1.30201562, 1.30201562,
  385. 1.30201562, 1.30201562])
  386. nside = array([ 8, 16, 32, 8, 16, 32, 8, 16, 32, 8, 16, 32, 8, 16, 32, 8, 16,
  387. 32, 8, 16, 32, 8, 16, 32, 8, 16, 32])
  388. return_offsets = False, order = 'ring'
  389.  
  390. def lonlat_to_healpix(lon, lat, nside, return_offsets=False, order='ring'):
  391. """
  392. Convert longitudes/latitudes to HEALPix indices
  393.  
  394. Parameters
  395. ----------
  396. lon, lat : :class:`~astropy.units.Quantity`
  397. The longitude and latitude values as :class:`~astropy.units.Quantity`
  398. instances with angle units.
  399. nside : int
  400. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  401. order : { 'nested' | 'ring' }
  402. Order of HEALPix pixels
  403. return_offsets : bool, optional
  404. If `True`, the returned values are the HEALPix pixel indices as well as
  405. ``dx`` and ``dy``, the fractional positions inside the pixels. If
  406. `False` (the default), only the HEALPix pixel indices is returned.
  407.  
  408. Returns
  409. -------
  410. healpix_index : int or `~numpy.ndarray`
  411. The HEALPix indices
  412. dx, dy : `~numpy.ndarray`
  413. Offsets inside the HEALPix pixel in the range [0:1], where 0.5 is the
  414. center of the HEALPix pixels
  415. """
  416.  
  417. lon = lon.to(u.rad).value
  418. lat = lat.to(u.rad).value
  419.  
  420. lon, lat = np.broadcast_arrays(lon, lat)
  421.  
  422. shape = np.shape(lon)
  423.  
  424. lon = lon.astype(float).ravel()
  425. lat = lat.astype(float).ravel()
  426.  
  427. > nside = int(nside)
  428. E TypeError: only length-1 arrays can be converted to Python scalars
  429.  
  430. ../astropy-healpix/astropy_healpix/core.py:341: TypeError
  431. ___________________________________ test_hpxgeom_coord_to_idx[nside7-False-GAL-DISK(110.,75.,10.)-axes7] ____________________________________
  432.  
  433. nside = array([ 8, 16, 32, 8, 8, 16, 8, 16, 32, 8, 8, 16, 8, 16, 32, 8, 8,
  434. 16, 8, 16, 32, 8, 8, 16, 8, 16, ... 8, 16, 8, 16, 32, 8,
  435. 8, 16, 8, 16, 32, 8, 8, 16, 8, 16, 32, 8, 8, 16, 8, 16, 32,
  436. 8, 8, 16])
  437. nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  438. axes = [<gammapy.maps.geom.MapAxis object at 0x11808ccc0>, <gammapy.maps.geom.MapAxis object at 0x11808ccf8>]
  439.  
  440. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  441. hpx_test_geoms)
  442. def test_hpxgeom_coord_to_idx(nside, nested, coordsys, region, axes):
  443. from astropy_healpix import healpy as hp
  444.  
  445. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  446. lon = np.array([112.5, 135., 105.])
  447. lat = np.array([75.3, 75.3, 74.6])
  448. coords = make_test_coords(geom, lon, lat)
  449. zidx = [ax.coord_to_idx(t) for t, ax in zip(coords[2:], geom.axes)]
  450.  
  451. if geom.nside.size > 1:
  452. nside = geom.nside[zidx]
  453. else:
  454. nside = geom.nside
  455.  
  456. phi, theta = lonlat_to_colat(coords[0], coords[1])
  457. > idx = geom.coord_to_idx(coords)
  458.  
  459. gammapy/maps/tests/test_hpx.py:200:
  460. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  461. gammapy/maps/geom.py:808: in coord_to_idx
  462. pix = self.coord_to_pix(coords)
  463. gammapy/maps/hpx.py:612: in coord_to_pix
  464. pix = hp.ang2pix(nside, theta, phi, nest=self.nest)
  465. ../astropy-healpix/astropy_healpix/healpy.py:105: in ang2pix
  466. return lonlat_to_healpix(lon, lat, nside, order='nested' if nest else 'ring')
  467. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  468.  
  469. lon = array([ 1.96349541, 1.96349541, 1.96349541, 1.96349541, 1.96349541,
  470. 1.96349541, 2.35619449, 2.35619449, ...619449, 2.35619449, 2.35619449, 1.83259571, 1.83259571,
  471. 1.83259571, 1.83259571, 1.83259571, 1.83259571])
  472. lat = array([ 1.31423293, 1.31423293, 1.31423293, 1.31423293, 1.31423293,
  473. 1.31423293, 1.31423293, 1.31423293, ...201562, 1.30201562, 1.30201562, 1.30201562, 1.30201562,
  474. 1.30201562, 1.30201562, 1.30201562, 1.30201562])
  475. nside = array([ 8, 16, 32, 8, 8, 16, 8, 16, 32, 8, 8, 16, 8, 16, 32, 8, 8,
  476. 16, 8, 16, 32, 8, 8, 16, 8, 16, ... 8, 16, 8, 16, 32, 8,
  477. 8, 16, 8, 16, 32, 8, 8, 16, 8, 16, 32, 8, 8, 16, 8, 16, 32,
  478. 8, 8, 16])
  479. return_offsets = False, order = 'ring'
  480.  
  481. def lonlat_to_healpix(lon, lat, nside, return_offsets=False, order='ring'):
  482. """
  483. Convert longitudes/latitudes to HEALPix indices
  484.  
  485. Parameters
  486. ----------
  487. lon, lat : :class:`~astropy.units.Quantity`
  488. The longitude and latitude values as :class:`~astropy.units.Quantity`
  489. instances with angle units.
  490. nside : int
  491. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  492. order : { 'nested' | 'ring' }
  493. Order of HEALPix pixels
  494. return_offsets : bool, optional
  495. If `True`, the returned values are the HEALPix pixel indices as well as
  496. ``dx`` and ``dy``, the fractional positions inside the pixels. If
  497. `False` (the default), only the HEALPix pixel indices is returned.
  498.  
  499. Returns
  500. -------
  501. healpix_index : int or `~numpy.ndarray`
  502. The HEALPix indices
  503. dx, dy : `~numpy.ndarray`
  504. Offsets inside the HEALPix pixel in the range [0:1], where 0.5 is the
  505. center of the HEALPix pixels
  506. """
  507.  
  508. lon = lon.to(u.rad).value
  509. lat = lat.to(u.rad).value
  510.  
  511. lon, lat = np.broadcast_arrays(lon, lat)
  512.  
  513. shape = np.shape(lon)
  514.  
  515. lon = lon.astype(float).ravel()
  516. lat = lat.astype(float).ravel()
  517.  
  518. > nside = int(nside)
  519. E TypeError: only length-1 arrays can be converted to Python scalars
  520.  
  521. ../astropy-healpix/astropy_healpix/core.py:341: TypeError
  522. __________________________________________________________ test_hpxgeom_get_coords __________________________________________________________
  523.  
  524. def test_hpxgeom_get_coords():
  525. ax0 = np.linspace(0., 3., 4)
  526.  
  527. # 2D all-sky
  528. hpx = HpxGeom(16, False, 'GAL')
  529. c = hpx.get_coords()
  530. assert_allclose(c[0][:3], np.array([45., 135., 225.]))
  531. assert_allclose(c[1][:3], np.array([87.075819, 87.075819, 87.075819]))
  532.  
  533. # 3D all-sky
  534. hpx = HpxGeom(16, False, 'GAL', axes=[ax0])
  535. c = hpx.get_coords()
  536. assert_allclose(c[0][:3], np.array([45., 135., 225.]))
  537. assert_allclose(c[1][:3], np.array([87.075819, 87.075819, 87.075819]))
  538. assert_allclose(c[2][:3], np.array([0.5, 0.5, 0.5]))
  539.  
  540. # 2D partial-sky
  541. hpx = HpxGeom(64, False, 'GAL', region='DISK(110.,75.,2.)')
  542. c = hpx.get_coords()
  543. > assert_allclose(c[0][:3], np.array([107.5, 112.5, 106.57894737]))
  544. E AssertionError:
  545. E Not equal to tolerance rtol=1e-07, atol=0
  546. E
  547. E (mismatch 100.0%)
  548. E x: array([ 110.25 , 111.315789, 107.5 ])
  549. E y: array([ 107.5 , 112.5 , 106.578947])
  550.  
  551. gammapy/maps/tests/test_hpx.py:322: AssertionError
  552. _______________________________________________ test_hpxgeom_contains[8-False-GAL-None-axes1] _______________________________________________
  553.  
  554. nside = 8, nested = False, coordsys = 'GAL', region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x11808cb70>]
  555.  
  556. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  557. hpx_test_geoms)
  558. def test_hpxgeom_contains(nside, nested, coordsys, region, axes):
  559. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  560. coords = geom.get_coords()
  561. assert_allclose(geom.contains(coords), np.ones(
  562. coords[0].shape, dtype=bool))
  563.  
  564. if axes is not None:
  565.  
  566. coords = [c[0] for c in coords[:2]] + \
  567. [ax.edges[-1] + 1.0 for ax in axes]
  568. > assert_allclose(geom.contains(coords), np.zeros((1,), dtype=bool))
  569.  
  570. gammapy/maps/tests/test_hpx.py:353:
  571. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  572. gammapy/maps/hpx.py:1374: in contains
  573. idx = self.coord_to_idx(coords)
  574. gammapy/maps/geom.py:809: in coord_to_idx
  575. return self.pix_to_idx(pix)
  576. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  577.  
  578. self = <gammapy.maps.hpx.HpxGeom object at 0x118538d30>, pix = (0, array([ 2.50111111]))
  579.  
  580. def pix_to_idx(self, pix):
  581.  
  582. # FIXME: Correctly apply bounds on non-spatial pixel
  583. # coordinates
  584. idx = list(pix_tuple_to_idx(pix))
  585. idx_local = self.global_to_local(idx)
  586. for i, _ in enumerate(idx):
  587. > idx[i][(idx_local[i] < 0) | (idx[i] < 0)] = -1
  588. E IndexError: too many indices for array
  589.  
  590. gammapy/maps/hpx.py:654: IndexError
  591. ____________________________________________ test_hpxgeom_contains[nside2-False-GAL-None-axes2] _____________________________________________
  592.  
  593. nside = [2, 4, 8], nested = False, coordsys = 'GAL', region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x11808cba8>]
  594.  
  595. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  596. hpx_test_geoms)
  597. def test_hpxgeom_contains(nside, nested, coordsys, region, axes):
  598. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  599. > coords = geom.get_coords()
  600.  
  601. gammapy/maps/tests/test_hpx.py:345:
  602. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  603. gammapy/maps/hpx.py:1370: in get_coords
  604. return self.pix_to_coord(pix)
  605. gammapy/maps/hpx.py:637: in pix_to_coord
  606. theta, phi = hp.pix2ang(nside, ipix, nest=self.nest)
  607. ../astropy-healpix/astropy_healpix/healpy.py:98: in pix2ang
  608. lon, lat = healpix_to_lonlat(ipix, nside, order='nested' if nest else 'ring')
  609. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  610.  
  611. healpix_index = array([ 0, 1, 2, ..., 765, 766, 767]), nside = array([2, 2, 2, ..., 8, 8, 8]), dx = None, dy = None, order = 'ring'
  612.  
  613. def healpix_to_lonlat(healpix_index, nside, dx=None, dy=None, order='ring'):
  614. """
  615. Convert HEALPix indices (optionally with offsets) to longitudes/latitudes.
  616.  
  617. If no offsets (``dx`` and ``dy``) are provided, the coordinates will default
  618. to those at the center of the HEALPix pixels.
  619.  
  620. Parameters
  621. ----------
  622. healpix_index : int or `~numpy.ndarray`
  623. HEALPix indices (as a scalar or array)
  624. nside : int
  625. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  626. dx, dy : float or `~numpy.ndarray`, optional
  627. Offsets inside the HEALPix pixel, which must be in the range [0:1],
  628. where 0.5 is the center of the HEALPix pixels (as scalars or arrays)
  629. order : { 'nested' | 'ring' }, optional
  630. Order of HEALPix pixels
  631.  
  632. Returns
  633. -------
  634. lon : :class:`~astropy.coordinates.Longitude`
  635. The longitude values
  636. lat : :class:`~astropy.coordinates.Latitude`
  637. The latitude values
  638. """
  639.  
  640. if (dx is None and dy is not None) or (dx is not None and dy is None):
  641. raise ValueError('Either both or neither dx and dy must be specified')
  642.  
  643. healpix_index = np.asarray(healpix_index, dtype=np.int64)
  644.  
  645. if dx is None and dy is not None:
  646. dx = 0.5
  647. elif dx is not None and dy is None:
  648. dy = 0.5
  649.  
  650. if dx is not None:
  651. dx = np.asarray(dx, dtype=np.float)
  652. dy = np.asarray(dy, dtype=np.float)
  653. _validate_offset('x', dx)
  654. _validate_offset('y', dy)
  655. healpix_index, dx, dy = np.broadcast_arrays(healpix_index, dx, dy)
  656. dx = dx.ravel()
  657. dy = dy.ravel()
  658.  
  659. shape = healpix_index.shape
  660. healpix_index = healpix_index.ravel()
  661. > nside = int(nside)
  662. E TypeError: only length-1 arrays can be converted to Python scalars
  663.  
  664. ../astropy-healpix/astropy_healpix/core.py:287: TypeError
  665. _______________________________________________ test_hpxgeom_contains[8-False-GAL-None-axes3] _______________________________________________
  666.  
  667. nside = 8, nested = False, coordsys = 'GAL', region = None
  668. axes = [<gammapy.maps.geom.MapAxis object at 0x11808cbe0>, <gammapy.maps.geom.MapAxis object at 0x11808cc18>]
  669.  
  670. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  671. hpx_test_geoms)
  672. def test_hpxgeom_contains(nside, nested, coordsys, region, axes):
  673. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  674. coords = geom.get_coords()
  675. assert_allclose(geom.contains(coords), np.ones(
  676. coords[0].shape, dtype=bool))
  677.  
  678. if axes is not None:
  679.  
  680. coords = [c[0] for c in coords[:2]] + \
  681. [ax.edges[-1] + 1.0 for ax in axes]
  682. > assert_allclose(geom.contains(coords), np.zeros((1,), dtype=bool))
  683.  
  684. gammapy/maps/tests/test_hpx.py:353:
  685. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  686. gammapy/maps/hpx.py:1374: in contains
  687. idx = self.coord_to_idx(coords)
  688. gammapy/maps/geom.py:809: in coord_to_idx
  689. return self.pix_to_idx(pix)
  690. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  691.  
  692. self = <gammapy.maps.hpx.HpxGeom object at 0x118407ac8>, pix = (0, array([ 1.50103266]), array([ 2.51274605]))
  693.  
  694. def pix_to_idx(self, pix):
  695.  
  696. # FIXME: Correctly apply bounds on non-spatial pixel
  697. # coordinates
  698. idx = list(pix_tuple_to_idx(pix))
  699. idx_local = self.global_to_local(idx)
  700. for i, _ in enumerate(idx):
  701. > idx[i][(idx_local[i] < 0) | (idx[i] < 0)] = -1
  702. E IndexError: too many indices for array
  703.  
  704. gammapy/maps/hpx.py:654: IndexError
  705. ________________________________________ test_hpxgeom_contains[8-False-GAL-DISK(110.,75.,10.)-None] _________________________________________
  706.  
  707. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = None
  708.  
  709. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  710. hpx_test_geoms)
  711. def test_hpxgeom_contains(nside, nested, coordsys, region, axes):
  712. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  713. coords = geom.get_coords()
  714. assert_allclose(geom.contains(coords), np.ones(
  715. coords[0].shape, dtype=bool))
  716.  
  717. if axes is not None:
  718.  
  719. coords = [c[0] for c in coords[:2]] + \
  720. [ax.edges[-1] + 1.0 for ax in axes]
  721. assert_allclose(geom.contains(coords), np.zeros((1,), dtype=bool))
  722.  
  723. if geom.region is not None:
  724.  
  725. coords = [0.0, 0.0] + [ax.center[0] for ax in geom.axes]
  726. > assert_allclose(geom.contains(coords), np.zeros((1,), dtype=bool))
  727.  
  728. gammapy/maps/tests/test_hpx.py:358:
  729. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  730. gammapy/maps/hpx.py:1374: in contains
  731. idx = self.coord_to_idx(coords)
  732. gammapy/maps/geom.py:809: in coord_to_idx
  733. return self.pix_to_idx(pix)
  734. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  735.  
  736. self = <gammapy.maps.hpx.HpxGeom object at 0x1189f4a20>, pix = (336,)
  737.  
  738. def pix_to_idx(self, pix):
  739.  
  740. # FIXME: Correctly apply bounds on non-spatial pixel
  741. # coordinates
  742. idx = list(pix_tuple_to_idx(pix))
  743. idx_local = self.global_to_local(idx)
  744. for i, _ in enumerate(idx):
  745. > idx[i][(idx_local[i] < 0) | (idx[i] < 0)] = -1
  746. E IndexError: too many indices for array
  747.  
  748. gammapy/maps/hpx.py:654: IndexError
  749. ________________________________________ test_hpxgeom_contains[8-False-GAL-DISK(110.,75.,10.)-axes5] ________________________________________
  750.  
  751. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = [<gammapy.maps.geom.MapAxis object at 0x11808cc50>]
  752.  
  753. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  754. hpx_test_geoms)
  755. def test_hpxgeom_contains(nside, nested, coordsys, region, axes):
  756. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  757. coords = geom.get_coords()
  758. assert_allclose(geom.contains(coords), np.ones(
  759. coords[0].shape, dtype=bool))
  760.  
  761. if axes is not None:
  762.  
  763. coords = [c[0] for c in coords[:2]] + \
  764. [ax.edges[-1] + 1.0 for ax in axes]
  765. > assert_allclose(geom.contains(coords), np.zeros((1,), dtype=bool))
  766.  
  767. gammapy/maps/tests/test_hpx.py:353:
  768. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  769. gammapy/maps/hpx.py:1374: in contains
  770. idx = self.coord_to_idx(coords)
  771. gammapy/maps/geom.py:809: in coord_to_idx
  772. return self.pix_to_idx(pix)
  773. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  774.  
  775. self = <gammapy.maps.hpx.HpxGeom object at 0x118a0c518>, pix = (6, array([ 2.50111111]))
  776.  
  777. def pix_to_idx(self, pix):
  778.  
  779. # FIXME: Correctly apply bounds on non-spatial pixel
  780. # coordinates
  781. idx = list(pix_tuple_to_idx(pix))
  782. idx_local = self.global_to_local(idx)
  783. for i, _ in enumerate(idx):
  784. > idx[i][(idx_local[i] < 0) | (idx[i] < 0)] = -1
  785. E IndexError: too many indices for array
  786.  
  787. gammapy/maps/hpx.py:654: IndexError
  788. _____________________________________ test_hpxgeom_contains[nside6-False-GAL-DISK(110.,75.,10.)-axes6] ______________________________________
  789.  
  790. nside = [8, 16, 32], nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  791. axes = [<gammapy.maps.geom.MapAxis object at 0x11808cc88>]
  792.  
  793. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  794. hpx_test_geoms)
  795. def test_hpxgeom_contains(nside, nested, coordsys, region, axes):
  796. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  797. > coords = geom.get_coords()
  798.  
  799. gammapy/maps/tests/test_hpx.py:345:
  800. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  801. gammapy/maps/hpx.py:1370: in get_coords
  802. return self.pix_to_coord(pix)
  803. gammapy/maps/hpx.py:637: in pix_to_coord
  804. theta, phi = hp.pix2ang(nside, ipix, nest=self.nest)
  805. ../astropy-healpix/astropy_healpix/healpy.py:98: in pix2ang
  806. lon, lat = healpix_to_lonlat(ipix, nside, order='nested' if nest else 'ring')
  807. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  808.  
  809. healpix_index = array([ 6, 1, 0, 5, 14, 15, 29, 16, 7, 28, 46, 27, 46,
  810. 29, 15, 28, 45, 67, 93, 68, 47,..., 380, 326, 379, 276, 325, 45, 92, 67, 46, 28, 93,
  811. 68, 47, 29, 94, 69, 48, 30, 95, 70, 15, 27])
  812. nside = array([ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16,
  813. 16, 16, 16, 16, 16, 16, 16, 16, 16, ...32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
  814. 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32])
  815. dx = None, dy = None, order = 'ring'
  816.  
  817. def healpix_to_lonlat(healpix_index, nside, dx=None, dy=None, order='ring'):
  818. """
  819. Convert HEALPix indices (optionally with offsets) to longitudes/latitudes.
  820.  
  821. If no offsets (``dx`` and ``dy``) are provided, the coordinates will default
  822. to those at the center of the HEALPix pixels.
  823.  
  824. Parameters
  825. ----------
  826. healpix_index : int or `~numpy.ndarray`
  827. HEALPix indices (as a scalar or array)
  828. nside : int
  829. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  830. dx, dy : float or `~numpy.ndarray`, optional
  831. Offsets inside the HEALPix pixel, which must be in the range [0:1],
  832. where 0.5 is the center of the HEALPix pixels (as scalars or arrays)
  833. order : { 'nested' | 'ring' }, optional
  834. Order of HEALPix pixels
  835.  
  836. Returns
  837. -------
  838. lon : :class:`~astropy.coordinates.Longitude`
  839. The longitude values
  840. lat : :class:`~astropy.coordinates.Latitude`
  841. The latitude values
  842. """
  843.  
  844. if (dx is None and dy is not None) or (dx is not None and dy is None):
  845. raise ValueError('Either both or neither dx and dy must be specified')
  846.  
  847. healpix_index = np.asarray(healpix_index, dtype=np.int64)
  848.  
  849. if dx is None and dy is not None:
  850. dx = 0.5
  851. elif dx is not None and dy is None:
  852. dy = 0.5
  853.  
  854. if dx is not None:
  855. dx = np.asarray(dx, dtype=np.float)
  856. dy = np.asarray(dy, dtype=np.float)
  857. _validate_offset('x', dx)
  858. _validate_offset('y', dy)
  859. healpix_index, dx, dy = np.broadcast_arrays(healpix_index, dx, dy)
  860. dx = dx.ravel()
  861. dy = dy.ravel()
  862.  
  863. shape = healpix_index.shape
  864. healpix_index = healpix_index.ravel()
  865. > nside = int(nside)
  866. E TypeError: only length-1 arrays can be converted to Python scalars
  867.  
  868. ../astropy-healpix/astropy_healpix/core.py:287: TypeError
  869. _____________________________________ test_hpxgeom_contains[nside7-False-GAL-DISK(110.,75.,10.)-axes7] ______________________________________
  870.  
  871. nside = [[8, 16, 32], [8, 8, 16]], nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  872. axes = [<gammapy.maps.geom.MapAxis object at 0x11808ccc0>, <gammapy.maps.geom.MapAxis object at 0x11808ccf8>]
  873.  
  874. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  875. hpx_test_geoms)
  876. def test_hpxgeom_contains(nside, nested, coordsys, region, axes):
  877. geom = HpxGeom(nside, nested, coordsys, region=region, axes=axes)
  878. > coords = geom.get_coords()
  879.  
  880. gammapy/maps/tests/test_hpx.py:345:
  881. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  882. gammapy/maps/hpx.py:1370: in get_coords
  883. return self.pix_to_coord(pix)
  884. gammapy/maps/hpx.py:637: in pix_to_coord
  885. theta, phi = hp.pix2ang(nside, ipix, nest=self.nest)
  886. ../astropy-healpix/astropy_healpix/healpy.py:98: in pix2ang
  887. lon, lat = healpix_to_lonlat(ipix, nside, order='nested' if nest else 'ring')
  888. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  889.  
  890. healpix_index = array([ 6, 1, 0, 5, 14, 15, 29, 16, 7, 28, 46, 27, 46,
  891. 29, 15, 28, 45, 67, 93, 68, 47,... 7, 6,
  892. 5, 14, 43, 27, 64, 44, 65, 66, 90, 91, 121, 92, 155,
  893. 122, 156, 123, 154, 120, 119])
  894. nside = array([ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16,
  895. 16, 16, 16, 16, 16, 16, 16, 16, 16, ... 16, 16, 16,
  896. 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
  897. 16, 16, 16, 16, 16, 16])
  898. dx = None, dy = None, order = 'ring'
  899.  
  900. def healpix_to_lonlat(healpix_index, nside, dx=None, dy=None, order='ring'):
  901. """
  902. Convert HEALPix indices (optionally with offsets) to longitudes/latitudes.
  903.  
  904. If no offsets (``dx`` and ``dy``) are provided, the coordinates will default
  905. to those at the center of the HEALPix pixels.
  906.  
  907. Parameters
  908. ----------
  909. healpix_index : int or `~numpy.ndarray`
  910. HEALPix indices (as a scalar or array)
  911. nside : int
  912. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  913. dx, dy : float or `~numpy.ndarray`, optional
  914. Offsets inside the HEALPix pixel, which must be in the range [0:1],
  915. where 0.5 is the center of the HEALPix pixels (as scalars or arrays)
  916. order : { 'nested' | 'ring' }, optional
  917. Order of HEALPix pixels
  918.  
  919. Returns
  920. -------
  921. lon : :class:`~astropy.coordinates.Longitude`
  922. The longitude values
  923. lat : :class:`~astropy.coordinates.Latitude`
  924. The latitude values
  925. """
  926.  
  927. if (dx is None and dy is not None) or (dx is not None and dy is None):
  928. raise ValueError('Either both or neither dx and dy must be specified')
  929.  
  930. healpix_index = np.asarray(healpix_index, dtype=np.int64)
  931.  
  932. if dx is None and dy is not None:
  933. dx = 0.5
  934. elif dx is not None and dy is None:
  935. dy = 0.5
  936.  
  937. if dx is not None:
  938. dx = np.asarray(dx, dtype=np.float)
  939. dy = np.asarray(dy, dtype=np.float)
  940. _validate_offset('x', dx)
  941. _validate_offset('y', dy)
  942. healpix_index, dx, dy = np.broadcast_arrays(healpix_index, dx, dy)
  943. dx = dx.ravel()
  944. dy = dy.ravel()
  945.  
  946. shape = healpix_index.shape
  947. healpix_index = healpix_index.ravel()
  948. > nside = int(nside)
  949. E TypeError: only length-1 arrays can be converted to Python scalars
  950.  
  951. ../astropy-healpix/astropy_healpix/core.py:287: TypeError
  952. _______________________________________________________ test_make_hpx_to_wcs_mapping ________________________________________________________
  953.  
  954. def test_make_hpx_to_wcs_mapping():
  955. ax0 = np.linspace(0., 1., 3)
  956. hpx = HpxGeom(16, False, 'GAL', region='DISK(110.,75.,2.)')
  957. # FIXME construct explicit WCS projection here
  958. wcs = hpx.make_wcs()
  959. hpx2wcs = make_hpx_to_wcs_mapping(hpx, wcs)
  960. assert_allclose(hpx2wcs[0],
  961. np.array([67, 46, 46, 46, 46, 29, 67, 67, 46, 46,
  962. 46, 46, 67, 67, 67, 46, 46, 46, 67, 67,
  963. 67, 28, 28, 28, 45, 45, 45, 45, 28, 28,
  964. 66, 45, 45, 45, 45, 28]))
  965. assert_allclose(hpx2wcs[1],
  966. np.array([0.11111111, 0.09090909, 0.09090909, 0.09090909,
  967. 0.09090909, 1., 0.11111111, 0.11111111, 0.09090909,
  968. 0.09090909, 0.09090909, 0.09090909, 0.11111111,
  969. 0.11111111, 0.11111111, 0.09090909, 0.09090909,
  970. 0.09090909, 0.11111111, 0.11111111, 0.11111111,
  971. 0.16666667, 0.16666667, 0.16666667, 0.125,
  972. 0.125, 0.125, 0.125, 0.16666667, 0.16666667,
  973. 1., 0.125, 0.125, 0.125, 0.125, 0.16666667]))
  974.  
  975. hpx = HpxGeom([8, 16], False, 'GAL',
  976. region='DISK(110.,75.,2.)', axes=[ax0])
  977. > hpx2wcs = make_hpx_to_wcs_mapping(hpx, wcs)
  978.  
  979. gammapy/maps/tests/test_hpx.py:384:
  980. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  981. gammapy/maps/hpx.py:289: in make_hpx_to_wcs_mapping
  982. hpx.nest).flatten()
  983. ../astropy-healpix/astropy_healpix/healpy.py:105: in ang2pix
  984. return lonlat_to_healpix(lon, lat, nside, order='nested' if nest else 'ring')
  985. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  986.  
  987. lon = array([ 2.06399919, 2.07237334, 2.08180679, 2.09251182, 2.10476085,
  988. 2.118909 , 2.00669982, 2.0117912 , ... 1.80816208, 1.79948062,
  989. 1.77572516, 1.76735101, 1.75791757, 1.74721254, 1.73496351,
  990. 1.72081536])
  991. lat = array([ 1.26231867, 1.27959765, 1.29685147, 1.31407677, 1.33126886,
  992. 1.34842119, 1.26426183, 1.28165346, ... 1.33376308, 1.35110788,
  993. 1.26231867, 1.27959765, 1.29685147, 1.31407677, 1.33126886,
  994. 1.34842119])
  995. nside = array([[ 8],
  996. [16]]), return_offsets = False, order = 'ring'
  997.  
  998. def lonlat_to_healpix(lon, lat, nside, return_offsets=False, order='ring'):
  999. """
  1000. Convert longitudes/latitudes to HEALPix indices
  1001.  
  1002. Parameters
  1003. ----------
  1004. lon, lat : :class:`~astropy.units.Quantity`
  1005. The longitude and latitude values as :class:`~astropy.units.Quantity`
  1006. instances with angle units.
  1007. nside : int
  1008. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  1009. order : { 'nested' | 'ring' }
  1010. Order of HEALPix pixels
  1011. return_offsets : bool, optional
  1012. If `True`, the returned values are the HEALPix pixel indices as well as
  1013. ``dx`` and ``dy``, the fractional positions inside the pixels. If
  1014. `False` (the default), only the HEALPix pixel indices is returned.
  1015.  
  1016. Returns
  1017. -------
  1018. healpix_index : int or `~numpy.ndarray`
  1019. The HEALPix indices
  1020. dx, dy : `~numpy.ndarray`
  1021. Offsets inside the HEALPix pixel in the range [0:1], where 0.5 is the
  1022. center of the HEALPix pixels
  1023. """
  1024.  
  1025. lon = lon.to(u.rad).value
  1026. lat = lat.to(u.rad).value
  1027.  
  1028. lon, lat = np.broadcast_arrays(lon, lat)
  1029.  
  1030. shape = np.shape(lon)
  1031.  
  1032. lon = lon.astype(float).ravel()
  1033. lat = lat.astype(float).ravel()
  1034.  
  1035. > nside = int(nside)
  1036. E TypeError: only length-1 arrays can be converted to Python scalars
  1037.  
  1038. ../astropy-healpix/astropy_healpix/core.py:341: TypeError
  1039. _______________________________________ test_hpxcube_read_write[8-False-GAL-DISK(110.,75.,10.)-axes3] _______________________________________
  1040.  
  1041. tmpdir = local('/private/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/pytest-of-deil/pytest-27/test_hpxcube_read_write_8_Fals2')
  1042. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = [<gammapy.maps.geom.MapAxis object at 0x1180da7f0>]
  1043.  
  1044. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1045. hpx_test_geoms)
  1046. def test_hpxcube_read_write(tmpdir, nside, nested, coordsys, region, axes):
  1047. filename = str(tmpdir / 'skycube.fits')
  1048. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1049. coordsys=coordsys, region=region, axes=axes))
  1050. m.fill_poisson(0.5)
  1051. m.write(filename)
  1052. m2 = HpxMapND.read(filename)
  1053. assert_allclose(m.data, m2.data)
  1054. m.write(filename, sparse=True)
  1055. m2 = HpxMapND.read(filename)
  1056. > assert_allclose(m.data, m2.data)
  1057. E AssertionError:
  1058. E Not equal to tolerance rtol=1e-07, atol=0
  1059. E
  1060. E (mismatch 13.333333333333329%)
  1061. E x: array([ 0., 1., 3., 1., 2., 0., 0., 2., 1., 1., 1., 0., 0.,
  1062. E 0., 1.], dtype=float32)
  1063. E y: array([ 0., 1., 3., 1., 2., 0., 0., 2., 1., 1., 0., 0., 1.,
  1064. E 0., 1.], dtype=float32)
  1065.  
  1066. gammapy/maps/tests/test_hpxcube.py:62: AssertionError
  1067. _______________________________________ test_hpxcube_read_write[8-False-GAL-DISK(110.,75.,10.)-axes4] _______________________________________
  1068.  
  1069. tmpdir = local('/private/var/folders/sb/4qv5j4m90pz1rw7m70rj1b1r0000gn/T/pytest-of-deil/pytest-27/test_hpxcube_read_write_8_Fals3')
  1070. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  1071. axes = [<gammapy.maps.geom.MapAxis object at 0x1180da828>, <gammapy.maps.geom.MapAxis object at 0x1180da860>]
  1072.  
  1073. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1074. hpx_test_geoms)
  1075. def test_hpxcube_read_write(tmpdir, nside, nested, coordsys, region, axes):
  1076. filename = str(tmpdir / 'skycube.fits')
  1077. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1078. coordsys=coordsys, region=region, axes=axes))
  1079. m.fill_poisson(0.5)
  1080. m.write(filename)
  1081. m2 = HpxMapND.read(filename)
  1082. assert_allclose(m.data, m2.data)
  1083. m.write(filename, sparse=True)
  1084. m2 = HpxMapND.read(filename)
  1085. > assert_allclose(m.data, m2.data)
  1086. E AssertionError:
  1087. E Not equal to tolerance rtol=1e-07, atol=0
  1088. E
  1089. E (mismatch 6.666666666666671%)
  1090. E x: array([ 0., 0., 3., 1., 1., 1., 0., 1., 1., 0., 1., 1., 1.,
  1091. E 6., 3., 0., 1., 1., 4., 1., 0., 0., 3., 3., 0., 0.,
  1092. E 1., 2., 3., 0.], dtype=float32)
  1093. E y: array([ 0., 0., 3., 1., 1., 0., 0., 1., 1., 0., 0., 1., 1.,
  1094. E 6., 3., 0., 1., 1., 4., 1., 0., 0., 3., 3., 0., 0.,
  1095. E 1., 2., 3., 0.], dtype=float32)
  1096.  
  1097. gammapy/maps/tests/test_hpxcube.py:62: AssertionError
  1098. _________________________________________ test_hpxcube_set_get_by_pix[nside2-False-GAL-None-axes2] __________________________________________
  1099.  
  1100. nside = [4, 8], nested = False, coordsys = 'GAL', region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x1180da6d8>]
  1101.  
  1102. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1103. hpx_test_geoms)
  1104. def test_hpxcube_set_get_by_pix(nside, nested, coordsys, region, axes):
  1105. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1106. coordsys=coordsys, region=region, axes=axes))
  1107. > coords = m.hpx.get_coords()
  1108.  
  1109. gammapy/maps/tests/test_hpxcube.py:70:
  1110. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1111. gammapy/maps/hpx.py:1370: in get_coords
  1112. return self.pix_to_coord(pix)
  1113. gammapy/maps/hpx.py:637: in pix_to_coord
  1114. theta, phi = hp.pix2ang(nside, ipix, nest=self.nest)
  1115. ../astropy-healpix/astropy_healpix/healpy.py:98: in pix2ang
  1116. lon, lat = healpix_to_lonlat(ipix, nside, order='nested' if nest else 'ring')
  1117. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1118.  
  1119. healpix_index = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  1120. 13, 14, 15, 16, 17, 18, 19, 20,..., 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756,
  1121. 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767])
  1122. nside = array([4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  1123. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,... 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  1124. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8])
  1125. dx = None, dy = None, order = 'ring'
  1126.  
  1127. def healpix_to_lonlat(healpix_index, nside, dx=None, dy=None, order='ring'):
  1128. """
  1129. Convert HEALPix indices (optionally with offsets) to longitudes/latitudes.
  1130.  
  1131. If no offsets (``dx`` and ``dy``) are provided, the coordinates will default
  1132. to those at the center of the HEALPix pixels.
  1133.  
  1134. Parameters
  1135. ----------
  1136. healpix_index : int or `~numpy.ndarray`
  1137. HEALPix indices (as a scalar or array)
  1138. nside : int
  1139. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  1140. dx, dy : float or `~numpy.ndarray`, optional
  1141. Offsets inside the HEALPix pixel, which must be in the range [0:1],
  1142. where 0.5 is the center of the HEALPix pixels (as scalars or arrays)
  1143. order : { 'nested' | 'ring' }, optional
  1144. Order of HEALPix pixels
  1145.  
  1146. Returns
  1147. -------
  1148. lon : :class:`~astropy.coordinates.Longitude`
  1149. The longitude values
  1150. lat : :class:`~astropy.coordinates.Latitude`
  1151. The latitude values
  1152. """
  1153.  
  1154. if (dx is None and dy is not None) or (dx is not None and dy is None):
  1155. raise ValueError('Either both or neither dx and dy must be specified')
  1156.  
  1157. healpix_index = np.asarray(healpix_index, dtype=np.int64)
  1158.  
  1159. if dx is None and dy is not None:
  1160. dx = 0.5
  1161. elif dx is not None and dy is None:
  1162. dy = 0.5
  1163.  
  1164. if dx is not None:
  1165. dx = np.asarray(dx, dtype=np.float)
  1166. dy = np.asarray(dy, dtype=np.float)
  1167. _validate_offset('x', dx)
  1168. _validate_offset('y', dy)
  1169. healpix_index, dx, dy = np.broadcast_arrays(healpix_index, dx, dy)
  1170. dx = dx.ravel()
  1171. dy = dy.ravel()
  1172.  
  1173. shape = healpix_index.shape
  1174. healpix_index = healpix_index.ravel()
  1175. > nside = int(nside)
  1176. E TypeError: only length-1 arrays can be converted to Python scalars
  1177.  
  1178. ../astropy-healpix/astropy_healpix/core.py:287: TypeError
  1179. _____________________________________ test_hpxcube_set_get_by_pix[8-False-GAL-DISK(110.,75.,10.)-axes3] _____________________________________
  1180.  
  1181. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = [<gammapy.maps.geom.MapAxis object at 0x1180da7f0>]
  1182.  
  1183. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1184. hpx_test_geoms)
  1185. def test_hpxcube_set_get_by_pix(nside, nested, coordsys, region, axes):
  1186. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1187. coordsys=coordsys, region=region, axes=axes))
  1188. coords = m.hpx.get_coords()
  1189. pix = m.hpx.get_pixels()
  1190. m.set_by_pix(pix, coords[0])
  1191. > assert_allclose(coords[0], m.get_by_pix(pix))
  1192. E AssertionError:
  1193. E Not equal to tolerance rtol=1e-07, atol=0
  1194. E
  1195. E (mismatch 58.333333333333336%)
  1196. E x: array([ 112.5 , 135. , 45. , 67.5 , 75. , 105. , 123.75,
  1197. E 135. , 157.5 , 101.25, 117. , 78.75, 112.5 , 135. ,
  1198. E 45. , 67.5 , 75. , 105. , 123.75, 135. , 157.5 ,...
  1199. E y: array([ 157.5 , 67.5 , 45. , 67.5 , 157.5 , 78.75, 117. ,
  1200. E 78.75, 157.5 , 78.75, 117. , 78.75, 157.5 , 67.5 ,
  1201. E 45. , 67.5 , 157.5 , 78.75, 117. , 78.75, 157.5 ,...
  1202.  
  1203. gammapy/maps/tests/test_hpxcube.py:73: AssertionError
  1204. _____________________________________ test_hpxcube_set_get_by_pix[8-False-GAL-DISK(110.,75.,10.)-axes4] _____________________________________
  1205.  
  1206. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  1207. axes = [<gammapy.maps.geom.MapAxis object at 0x1180da828>, <gammapy.maps.geom.MapAxis object at 0x1180da860>]
  1208.  
  1209. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1210. hpx_test_geoms)
  1211. def test_hpxcube_set_get_by_pix(nside, nested, coordsys, region, axes):
  1212. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1213. coordsys=coordsys, region=region, axes=axes))
  1214. coords = m.hpx.get_coords()
  1215. pix = m.hpx.get_pixels()
  1216. m.set_by_pix(pix, coords[0])
  1217. > assert_allclose(coords[0], m.get_by_pix(pix))
  1218. E AssertionError:
  1219. E Not equal to tolerance rtol=1e-07, atol=0
  1220. E
  1221. E (mismatch 58.333333333333336%)
  1222. E x: array([ 112.5 , 135. , 45. , 67.5 , 75. , 105. , 123.75,
  1223. E 135. , 157.5 , 101.25, 117. , 78.75, 112.5 , 135. ,
  1224. E 45. , 67.5 , 75. , 105. , 123.75, 135. , 157.5 ,...
  1225. E y: array([ 157.5 , 67.5 , 45. , 67.5 , 157.5 , 78.75, 117. ,
  1226. E 78.75, 157.5 , 78.75, 117. , 78.75, 157.5 , 67.5 ,
  1227. E 45. , 67.5 , 157.5 , 78.75, 117. , 78.75, 157.5 ,...
  1228.  
  1229. gammapy/maps/tests/test_hpxcube.py:73: AssertionError
  1230. ________________________________________ test_hpxcube_set_get_by_coords[nside2-False-GAL-None-axes2] ________________________________________
  1231.  
  1232. nside = [4, 8], nested = False, coordsys = 'GAL', region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x1180da6d8>]
  1233.  
  1234. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1235. hpx_test_geoms)
  1236. def test_hpxcube_set_get_by_coords(nside, nested, coordsys, region, axes):
  1237. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1238. coordsys=coordsys, region=region, axes=axes))
  1239. > coords = m.hpx.get_coords()
  1240.  
  1241. gammapy/maps/tests/test_hpxcube.py:81:
  1242. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1243. gammapy/maps/hpx.py:1370: in get_coords
  1244. return self.pix_to_coord(pix)
  1245. gammapy/maps/hpx.py:637: in pix_to_coord
  1246. theta, phi = hp.pix2ang(nside, ipix, nest=self.nest)
  1247. ../astropy-healpix/astropy_healpix/healpy.py:98: in pix2ang
  1248. lon, lat = healpix_to_lonlat(ipix, nside, order='nested' if nest else 'ring')
  1249. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1250.  
  1251. healpix_index = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  1252. 13, 14, 15, 16, 17, 18, 19, 20,..., 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756,
  1253. 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767])
  1254. nside = array([4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  1255. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,... 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  1256. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8])
  1257. dx = None, dy = None, order = 'ring'
  1258.  
  1259. def healpix_to_lonlat(healpix_index, nside, dx=None, dy=None, order='ring'):
  1260. """
  1261. Convert HEALPix indices (optionally with offsets) to longitudes/latitudes.
  1262.  
  1263. If no offsets (``dx`` and ``dy``) are provided, the coordinates will default
  1264. to those at the center of the HEALPix pixels.
  1265.  
  1266. Parameters
  1267. ----------
  1268. healpix_index : int or `~numpy.ndarray`
  1269. HEALPix indices (as a scalar or array)
  1270. nside : int
  1271. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  1272. dx, dy : float or `~numpy.ndarray`, optional
  1273. Offsets inside the HEALPix pixel, which must be in the range [0:1],
  1274. where 0.5 is the center of the HEALPix pixels (as scalars or arrays)
  1275. order : { 'nested' | 'ring' }, optional
  1276. Order of HEALPix pixels
  1277.  
  1278. Returns
  1279. -------
  1280. lon : :class:`~astropy.coordinates.Longitude`
  1281. The longitude values
  1282. lat : :class:`~astropy.coordinates.Latitude`
  1283. The latitude values
  1284. """
  1285.  
  1286. if (dx is None and dy is not None) or (dx is not None and dy is None):
  1287. raise ValueError('Either both or neither dx and dy must be specified')
  1288.  
  1289. healpix_index = np.asarray(healpix_index, dtype=np.int64)
  1290.  
  1291. if dx is None and dy is not None:
  1292. dx = 0.5
  1293. elif dx is not None and dy is None:
  1294. dy = 0.5
  1295.  
  1296. if dx is not None:
  1297. dx = np.asarray(dx, dtype=np.float)
  1298. dy = np.asarray(dy, dtype=np.float)
  1299. _validate_offset('x', dx)
  1300. _validate_offset('y', dy)
  1301. healpix_index, dx, dy = np.broadcast_arrays(healpix_index, dx, dy)
  1302. dx = dx.ravel()
  1303. dy = dy.ravel()
  1304.  
  1305. shape = healpix_index.shape
  1306. healpix_index = healpix_index.ravel()
  1307. > nside = int(nside)
  1308. E TypeError: only length-1 arrays can be converted to Python scalars
  1309.  
  1310. ../astropy-healpix/astropy_healpix/core.py:287: TypeError
  1311. ___________________________________ test_hpxcube_set_get_by_coords[8-False-GAL-DISK(110.,75.,10.)-axes3] ____________________________________
  1312.  
  1313. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = [<gammapy.maps.geom.MapAxis object at 0x1180da7f0>]
  1314.  
  1315. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1316. hpx_test_geoms)
  1317. def test_hpxcube_set_get_by_coords(nside, nested, coordsys, region, axes):
  1318. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1319. coordsys=coordsys, region=region, axes=axes))
  1320. coords = m.hpx.get_coords()
  1321. m.set_by_coords(coords, coords[0])
  1322. > assert_allclose(coords[0], m.get_by_coords(coords))
  1323. E AssertionError:
  1324. E Not equal to tolerance rtol=1e-07, atol=0
  1325. E
  1326. E (mismatch 58.333333333333336%)
  1327. E x: array([ 112.5 , 135. , 45. , 67.5 , 75. , 105. , 123.75,
  1328. E 135. , 157.5 , 101.25, 117. , 78.75, 112.5 , 135. ,
  1329. E 45. , 67.5 , 75. , 105. , 123.75, 135. , 157.5 ,...
  1330. E y: array([ 157.5 , 67.5 , 45. , 67.5 , 157.5 , 78.75, 117. ,
  1331. E 78.75, 157.5 , 78.75, 117. , 78.75, 157.5 , 67.5 ,
  1332. E 45. , 67.5 , 157.5 , 78.75, 117. , 78.75, 157.5 ,...
  1333.  
  1334. gammapy/maps/tests/test_hpxcube.py:83: AssertionError
  1335. ___________________________________ test_hpxcube_set_get_by_coords[8-False-GAL-DISK(110.,75.,10.)-axes4] ____________________________________
  1336.  
  1337. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  1338. axes = [<gammapy.maps.geom.MapAxis object at 0x1180da828>, <gammapy.maps.geom.MapAxis object at 0x1180da860>]
  1339.  
  1340. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1341. hpx_test_geoms)
  1342. def test_hpxcube_set_get_by_coords(nside, nested, coordsys, region, axes):
  1343. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1344. coordsys=coordsys, region=region, axes=axes))
  1345. coords = m.hpx.get_coords()
  1346. m.set_by_coords(coords, coords[0])
  1347. > assert_allclose(coords[0], m.get_by_coords(coords))
  1348. E AssertionError:
  1349. E Not equal to tolerance rtol=1e-07, atol=0
  1350. E
  1351. E (mismatch 58.333333333333336%)
  1352. E x: array([ 112.5 , 135. , 45. , 67.5 , 75. , 105. , 123.75,
  1353. E 135. , 157.5 , 101.25, 117. , 78.75, 112.5 , 135. ,
  1354. E 45. , 67.5 , 75. , 105. , 123.75, 135. , 157.5 ,...
  1355. E y: array([ 157.5 , 67.5 , 45. , 67.5 , 157.5 , 78.75, 117. ,
  1356. E 78.75, 157.5 , 78.75, 117. , 78.75, 157.5 , 67.5 ,
  1357. E 45. , 67.5 , 157.5 , 78.75, 117. , 78.75, 157.5 ,...
  1358.  
  1359. gammapy/maps/tests/test_hpxcube.py:83: AssertionError
  1360. _________________________________________ test_hpxcube_fill_by_coords[nside2-False-GAL-None-axes2] __________________________________________
  1361.  
  1362. nside = [4, 8], nested = False, coordsys = 'GAL', region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x1180da6d8>]
  1363.  
  1364. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1365. hpx_test_geoms)
  1366. def test_hpxcube_fill_by_coords(nside, nested, coordsys, region, axes):
  1367. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1368. coordsys=coordsys, region=region, axes=axes))
  1369. > coords = m.hpx.get_coords()
  1370.  
  1371. gammapy/maps/tests/test_hpxcube.py:103:
  1372. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1373. gammapy/maps/hpx.py:1370: in get_coords
  1374. return self.pix_to_coord(pix)
  1375. gammapy/maps/hpx.py:637: in pix_to_coord
  1376. theta, phi = hp.pix2ang(nside, ipix, nest=self.nest)
  1377. ../astropy-healpix/astropy_healpix/healpy.py:98: in pix2ang
  1378. lon, lat = healpix_to_lonlat(ipix, nside, order='nested' if nest else 'ring')
  1379. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1380.  
  1381. healpix_index = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  1382. 13, 14, 15, 16, 17, 18, 19, 20,..., 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756,
  1383. 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767])
  1384. nside = array([4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  1385. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,... 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  1386. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8])
  1387. dx = None, dy = None, order = 'ring'
  1388.  
  1389. def healpix_to_lonlat(healpix_index, nside, dx=None, dy=None, order='ring'):
  1390. """
  1391. Convert HEALPix indices (optionally with offsets) to longitudes/latitudes.
  1392.  
  1393. If no offsets (``dx`` and ``dy``) are provided, the coordinates will default
  1394. to those at the center of the HEALPix pixels.
  1395.  
  1396. Parameters
  1397. ----------
  1398. healpix_index : int or `~numpy.ndarray`
  1399. HEALPix indices (as a scalar or array)
  1400. nside : int
  1401. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  1402. dx, dy : float or `~numpy.ndarray`, optional
  1403. Offsets inside the HEALPix pixel, which must be in the range [0:1],
  1404. where 0.5 is the center of the HEALPix pixels (as scalars or arrays)
  1405. order : { 'nested' | 'ring' }, optional
  1406. Order of HEALPix pixels
  1407.  
  1408. Returns
  1409. -------
  1410. lon : :class:`~astropy.coordinates.Longitude`
  1411. The longitude values
  1412. lat : :class:`~astropy.coordinates.Latitude`
  1413. The latitude values
  1414. """
  1415.  
  1416. if (dx is None and dy is not None) or (dx is not None and dy is None):
  1417. raise ValueError('Either both or neither dx and dy must be specified')
  1418.  
  1419. healpix_index = np.asarray(healpix_index, dtype=np.int64)
  1420.  
  1421. if dx is None and dy is not None:
  1422. dx = 0.5
  1423. elif dx is not None and dy is None:
  1424. dy = 0.5
  1425.  
  1426. if dx is not None:
  1427. dx = np.asarray(dx, dtype=np.float)
  1428. dy = np.asarray(dy, dtype=np.float)
  1429. _validate_offset('x', dx)
  1430. _validate_offset('y', dy)
  1431. healpix_index, dx, dy = np.broadcast_arrays(healpix_index, dx, dy)
  1432. dx = dx.ravel()
  1433. dy = dy.ravel()
  1434.  
  1435. shape = healpix_index.shape
  1436. healpix_index = healpix_index.ravel()
  1437. > nside = int(nside)
  1438. E TypeError: only length-1 arrays can be converted to Python scalars
  1439.  
  1440. ../astropy-healpix/astropy_healpix/core.py:287: TypeError
  1441. _____________________________________ test_hpxcube_fill_by_coords[8-False-GAL-DISK(110.,75.,10.)-axes3] _____________________________________
  1442.  
  1443. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = [<gammapy.maps.geom.MapAxis object at 0x1180da7f0>]
  1444.  
  1445. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1446. hpx_test_geoms)
  1447. def test_hpxcube_fill_by_coords(nside, nested, coordsys, region, axes):
  1448. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1449. coordsys=coordsys, region=region, axes=axes))
  1450. coords = m.hpx.get_coords()
  1451. m.fill_by_coords(coords, coords[1])
  1452. m.fill_by_coords(coords, coords[1])
  1453. > assert_allclose(m.get_by_coords(coords), 2.0 * coords[1])
  1454. E AssertionError:
  1455. E Not equal to tolerance rtol=1e-07, atol=0
  1456. E
  1457. E (mismatch 91.66666666666667%)
  1458. E x: array([ 457.911713, 324.867767, 168.299469, 324.867767, 457.911713,
  1459. E 555.324402, 253.755951, 555.324402, 457.911713, 555.324402,
  1460. E 253.755951, 555.324402, 457.911713, 324.867767, 168.299469,...
  1461. E y: array([ 156.568295, 168.299466, 168.299466, 156.568295, 144.775122,
  1462. E 144.775122, 132.887071, 144.775122, 156.568295, 132.887071,
  1463. E 120.868878, 132.887071, 156.568295, 168.299466, 168.299466,...
  1464.  
  1465. gammapy/maps/tests/test_hpxcube.py:106: AssertionError
  1466. _____________________________________ test_hpxcube_fill_by_coords[8-False-GAL-DISK(110.,75.,10.)-axes4] _____________________________________
  1467.  
  1468. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  1469. axes = [<gammapy.maps.geom.MapAxis object at 0x1180da828>, <gammapy.maps.geom.MapAxis object at 0x1180da860>]
  1470.  
  1471. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1472. hpx_test_geoms)
  1473. def test_hpxcube_fill_by_coords(nside, nested, coordsys, region, axes):
  1474. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1475. coordsys=coordsys, region=region, axes=axes))
  1476. coords = m.hpx.get_coords()
  1477. m.fill_by_coords(coords, coords[1])
  1478. m.fill_by_coords(coords, coords[1])
  1479. > assert_allclose(m.get_by_coords(coords), 2.0 * coords[1])
  1480. E AssertionError:
  1481. E Not equal to tolerance rtol=1e-07, atol=0
  1482. E
  1483. E (mismatch 91.66666666666667%)
  1484. E x: array([ 457.911713, 324.867767, 168.299469, 324.867767, 457.911713,
  1485. E 555.324402, 253.755951, 555.324402, 457.911713, 555.324402,
  1486. E 253.755951, 555.324402, 457.911713, 324.867767, 168.299469,...
  1487. E y: array([ 156.568295, 168.299466, 168.299466, 156.568295, 144.775122,
  1488. E 144.775122, 132.887071, 144.775122, 156.568295, 132.887071,
  1489. E 120.868878, 132.887071, 156.568295, 168.299466, 168.299466,...
  1490.  
  1491. gammapy/maps/tests/test_hpxcube.py:106: AssertionError
  1492. ______________________________________________ test_hpxcube_iter[nside2-False-GAL-None-axes2] _______________________________________________
  1493.  
  1494. nside = [4, 8], nested = False, coordsys = 'GAL', region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x1180da6d8>]
  1495.  
  1496. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1497. hpx_test_geoms)
  1498. def test_hpxcube_iter(nside, nested, coordsys, region, axes):
  1499. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1500. coordsys=coordsys, region=region, axes=axes))
  1501. > coords = m.geom.get_coords()
  1502.  
  1503. gammapy/maps/tests/test_hpxcube.py:114:
  1504. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1505. gammapy/maps/hpx.py:1370: in get_coords
  1506. return self.pix_to_coord(pix)
  1507. gammapy/maps/hpx.py:637: in pix_to_coord
  1508. theta, phi = hp.pix2ang(nside, ipix, nest=self.nest)
  1509. ../astropy-healpix/astropy_healpix/healpy.py:98: in pix2ang
  1510. lon, lat = healpix_to_lonlat(ipix, nside, order='nested' if nest else 'ring')
  1511. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1512.  
  1513. healpix_index = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  1514. 13, 14, 15, 16, 17, 18, 19, 20,..., 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756,
  1515. 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767])
  1516. nside = array([4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  1517. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,... 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  1518. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8])
  1519. dx = None, dy = None, order = 'ring'
  1520.  
  1521. def healpix_to_lonlat(healpix_index, nside, dx=None, dy=None, order='ring'):
  1522. """
  1523. Convert HEALPix indices (optionally with offsets) to longitudes/latitudes.
  1524.  
  1525. If no offsets (``dx`` and ``dy``) are provided, the coordinates will default
  1526. to those at the center of the HEALPix pixels.
  1527.  
  1528. Parameters
  1529. ----------
  1530. healpix_index : int or `~numpy.ndarray`
  1531. HEALPix indices (as a scalar or array)
  1532. nside : int
  1533. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  1534. dx, dy : float or `~numpy.ndarray`, optional
  1535. Offsets inside the HEALPix pixel, which must be in the range [0:1],
  1536. where 0.5 is the center of the HEALPix pixels (as scalars or arrays)
  1537. order : { 'nested' | 'ring' }, optional
  1538. Order of HEALPix pixels
  1539.  
  1540. Returns
  1541. -------
  1542. lon : :class:`~astropy.coordinates.Longitude`
  1543. The longitude values
  1544. lat : :class:`~astropy.coordinates.Latitude`
  1545. The latitude values
  1546. """
  1547.  
  1548. if (dx is None and dy is not None) or (dx is not None and dy is None):
  1549. raise ValueError('Either both or neither dx and dy must be specified')
  1550.  
  1551. healpix_index = np.asarray(healpix_index, dtype=np.int64)
  1552.  
  1553. if dx is None and dy is not None:
  1554. dx = 0.5
  1555. elif dx is not None and dy is None:
  1556. dy = 0.5
  1557.  
  1558. if dx is not None:
  1559. dx = np.asarray(dx, dtype=np.float)
  1560. dy = np.asarray(dy, dtype=np.float)
  1561. _validate_offset('x', dx)
  1562. _validate_offset('y', dy)
  1563. healpix_index, dx, dy = np.broadcast_arrays(healpix_index, dx, dy)
  1564. dx = dx.ravel()
  1565. dy = dy.ravel()
  1566.  
  1567. shape = healpix_index.shape
  1568. healpix_index = healpix_index.ravel()
  1569. > nside = int(nside)
  1570. E TypeError: only length-1 arrays can be converted to Python scalars
  1571.  
  1572. ../astropy-healpix/astropy_healpix/core.py:287: TypeError
  1573. __________________________________________ test_hpxcube_iter[8-False-GAL-DISK(110.,75.,10.)-axes3] __________________________________________
  1574.  
  1575. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = [<gammapy.maps.geom.MapAxis object at 0x1180da7f0>]
  1576.  
  1577. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1578. hpx_test_geoms)
  1579. def test_hpxcube_iter(nside, nested, coordsys, region, axes):
  1580. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1581. coordsys=coordsys, region=region, axes=axes))
  1582. coords = m.geom.get_coords()
  1583. m.fill_by_coords(coords, coords[0])
  1584. > for vals, pix in m.iter_by_pix(buffersize=100):
  1585.  
  1586. gammapy/maps/tests/test_hpxcube.py:116:
  1587. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1588.  
  1589. self = <gammapy.maps.hpxcube.HpxMapND object at 0x1185381d0>, buffersize = 100
  1590.  
  1591. def iter_by_pix(self, buffersize=1):
  1592. pix = list(self.geom.get_pixels())
  1593. vals = self.data[np.isfinite(self.data)]
  1594. return unpack_seq(np.nditer([vals] + pix,
  1595. flags=['external_loop', 'buffered'],
  1596. > buffersize=buffersize))
  1597. E ValueError: operands could not be broadcast together with shapes (15,) (36,) (36,)
  1598.  
  1599. gammapy/maps/hpxcube.py:175: ValueError
  1600. __________________________________________ test_hpxcube_iter[8-False-GAL-DISK(110.,75.,10.)-axes4] __________________________________________
  1601.  
  1602. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  1603. axes = [<gammapy.maps.geom.MapAxis object at 0x1180da828>, <gammapy.maps.geom.MapAxis object at 0x1180da860>]
  1604.  
  1605. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1606. hpx_test_geoms)
  1607. def test_hpxcube_iter(nside, nested, coordsys, region, axes):
  1608. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1609. coordsys=coordsys, region=region, axes=axes))
  1610. coords = m.geom.get_coords()
  1611. m.fill_by_coords(coords, coords[0])
  1612. > for vals, pix in m.iter_by_pix(buffersize=100):
  1613.  
  1614. gammapy/maps/tests/test_hpxcube.py:116:
  1615. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1616.  
  1617. self = <gammapy.maps.hpxcube.HpxMapND object at 0x118301470>, buffersize = 100
  1618.  
  1619. def iter_by_pix(self, buffersize=1):
  1620. pix = list(self.geom.get_pixels())
  1621. vals = self.data[np.isfinite(self.data)]
  1622. return unpack_seq(np.nditer([vals] + pix,
  1623. flags=['external_loop', 'buffered'],
  1624. > buffersize=buffersize))
  1625. E ValueError: operands could not be broadcast together with shapes (30,) (72,) (72,) (72,)
  1626.  
  1627. gammapy/maps/hpxcube.py:175: ValueError
  1628. _____________________________________________ test_hpxcube_to_wcs[nside2-False-GAL-None-axes2] ______________________________________________
  1629.  
  1630. nside = [4, 8], nested = False, coordsys = 'GAL', region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x1180da6d8>]
  1631.  
  1632. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1633. hpx_test_geoms)
  1634. def test_hpxcube_to_wcs(nside, nested, coordsys, region, axes):
  1635. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1636. coordsys=coordsys, region=region, axes=axes))
  1637. > m_wcs = m.to_wcs(sum_bands=False, oversample=2, normalize=False)
  1638.  
  1639. gammapy/maps/tests/test_hpxcube.py:127:
  1640. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1641. gammapy/maps/hpxcube.py:135: in to_wcs
  1642. self.make_wcs_mapping(oversample=oversample, proj=proj)
  1643. gammapy/maps/hpxcube.py:123: in make_wcs_mapping
  1644. self._hpx2wcs = HpxToWcsMapping.create(self.hpx, self._wcs2d)
  1645. gammapy/maps/hpx.py:1481: in create
  1646. ipix, mult_val, npix = make_hpx_to_wcs_mapping(hpx, wcs)
  1647. gammapy/maps/hpx.py:289: in make_hpx_to_wcs_mapping
  1648. hpx.nest).flatten()
  1649. ../astropy-healpix/astropy_healpix/healpy.py:105: in ang2pix
  1650. return lonlat_to_healpix(lon, lat, nside, order='nested' if nest else 'ring')
  1651. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1652.  
  1653. lon = array([ 3.14025542, 3.13047409, 3.12316943, ..., 3.16001588,
  1654. 3.15271122, 3.14292989])
  1655. lat = array([-0.11133886, -0.08673701, -0.06202949, ..., 0.06202949,
  1656. 0.08673701, 0.11133886]), nside = array([[4],
  1657. [8]])
  1658. return_offsets = False, order = 'ring'
  1659.  
  1660. def lonlat_to_healpix(lon, lat, nside, return_offsets=False, order='ring'):
  1661. """
  1662. Convert longitudes/latitudes to HEALPix indices
  1663.  
  1664. Parameters
  1665. ----------
  1666. lon, lat : :class:`~astropy.units.Quantity`
  1667. The longitude and latitude values as :class:`~astropy.units.Quantity`
  1668. instances with angle units.
  1669. nside : int
  1670. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  1671. order : { 'nested' | 'ring' }
  1672. Order of HEALPix pixels
  1673. return_offsets : bool, optional
  1674. If `True`, the returned values are the HEALPix pixel indices as well as
  1675. ``dx`` and ``dy``, the fractional positions inside the pixels. If
  1676. `False` (the default), only the HEALPix pixel indices is returned.
  1677.  
  1678. Returns
  1679. -------
  1680. healpix_index : int or `~numpy.ndarray`
  1681. The HEALPix indices
  1682. dx, dy : `~numpy.ndarray`
  1683. Offsets inside the HEALPix pixel in the range [0:1], where 0.5 is the
  1684. center of the HEALPix pixels
  1685. """
  1686.  
  1687. lon = lon.to(u.rad).value
  1688. lat = lat.to(u.rad).value
  1689.  
  1690. lon, lat = np.broadcast_arrays(lon, lat)
  1691.  
  1692. shape = np.shape(lon)
  1693.  
  1694. lon = lon.astype(float).ravel()
  1695. lat = lat.astype(float).ravel()
  1696.  
  1697. > nside = int(nside)
  1698. E TypeError: only length-1 arrays can be converted to Python scalars
  1699.  
  1700. ../astropy-healpix/astropy_healpix/core.py:341: TypeError
  1701. ___________________________________________ test_hpxcube_swap_scheme[nside2-False-GAL-None-axes2] ___________________________________________
  1702.  
  1703. nside = [4, 8], nested = False, coordsys = 'GAL', region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x1180da6d8>]
  1704.  
  1705. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1706. hpx_test_geoms)
  1707. def test_hpxcube_swap_scheme(nside, nested, coordsys, region, axes):
  1708. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1709. coordsys=coordsys, region=region, axes=axes))
  1710. m.fill_poisson(1.0)
  1711. > m2 = m.to_swapped_scheme()
  1712.  
  1713. gammapy/maps/tests/test_hpxcube.py:137:
  1714. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1715. gammapy/maps/hpxcube.py:391: in to_swapped_scheme
  1716. idx_new = tuple([hp.ring2nest(nside, idx[0])] + idx[1:])
  1717. ../astropy-healpix/astropy_healpix/healpy.py:117: in ring2nest
  1718. return ring_to_nested(ipix, nside)
  1719. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1720.  
  1721. ring_index = array([ 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  1722. 14, 15, 17, 18, 20, 21, 22, 23,...740, 741, 742, 743,
  1723. 744, 746, 747, 749, 750, 751, 752, 753, 755, 756, 757, 759, 761,
  1724. 762, 764, 765, 766])
  1725. nside = array([4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  1726. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,...8, 8, 8, 8, 8,
  1727. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  1728. 8, 8, 8, 8, 8, 8, 8])
  1729.  
  1730. def ring_to_nested(ring_index, nside):
  1731. """
  1732. Convert a HEALPix 'ring' index to a HEALPix 'nested' index
  1733.  
  1734. Parameters
  1735. ----------
  1736. ring_index : int or `~numpy.ndarray`
  1737. Healpix index using the 'ring' ordering
  1738. nside : int
  1739. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  1740.  
  1741. Returns
  1742. -------
  1743. nested_index : int or `~numpy.ndarray`
  1744. Healpix index using the 'nested' ordering
  1745. """
  1746.  
  1747. ring_index = np.asarray(ring_index, dtype=np.int64)
  1748. shape = ring_index.shape
  1749. ring_index = ring_index.ravel()
  1750. > nside = int(nside)
  1751. E TypeError: only length-1 arrays can be converted to Python scalars
  1752.  
  1753. ../astropy-healpix/astropy_healpix/core.py:402: TypeError
  1754. ______________________________________ test_hpxcube_swap_scheme[8-False-GAL-DISK(110.,75.,10.)-axes3] _______________________________________
  1755.  
  1756. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)', axes = [<gammapy.maps.geom.MapAxis object at 0x1180da7f0>]
  1757.  
  1758. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1759. hpx_test_geoms)
  1760. def test_hpxcube_swap_scheme(nside, nested, coordsys, region, axes):
  1761. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1762. coordsys=coordsys, region=region, axes=axes))
  1763. m.fill_poisson(1.0)
  1764. > m2 = m.to_swapped_scheme()
  1765.  
  1766. gammapy/maps/tests/test_hpxcube.py:137:
  1767. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1768. gammapy/maps/hpxcube.py:376: in to_swapped_scheme
  1769. map_out = self.__class__(hpx_out)
  1770. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1771.  
  1772. self = <gammapy.maps.hpxcube.HpxMapND object at 0x118b6af60>, hpx = <gammapy.maps.hpx.HpxGeom object at 0x118b6ad68>
  1773. data = array([[ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
  1774. nan],
  1775. [ nan, nan, nan, na... nan],
  1776. [ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
  1777. nan]], dtype=float32)
  1778. dtype = 'float32'
  1779.  
  1780. def __init__(self, hpx, data=None, dtype='float32'):
  1781.  
  1782. shape = tuple([np.max(hpx.npix)] + [ax.nbin for ax in hpx.axes])
  1783. if data is None:
  1784.  
  1785. if hpx.npix.size > 1:
  1786. data = np.nan * np.ones(shape, dtype=dtype).T
  1787. pix = hpx.get_pixels(local=True)
  1788. > data[pix[::-1]] = 0.0
  1789. E IndexError: index 12 is out of bounds for axis 1 with size 12
  1790.  
  1791. gammapy/maps/hpxcube.py:41: IndexError
  1792. ______________________________________ test_hpxcube_swap_scheme[8-False-GAL-DISK(110.,75.,10.)-axes4] _______________________________________
  1793.  
  1794. nside = 8, nested = False, coordsys = 'GAL', region = 'DISK(110.,75.,10.)'
  1795. axes = [<gammapy.maps.geom.MapAxis object at 0x1180da828>, <gammapy.maps.geom.MapAxis object at 0x1180da860>]
  1796.  
  1797. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1798. hpx_test_geoms)
  1799. def test_hpxcube_swap_scheme(nside, nested, coordsys, region, axes):
  1800. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1801. coordsys=coordsys, region=region, axes=axes))
  1802. m.fill_poisson(1.0)
  1803. > m2 = m.to_swapped_scheme()
  1804.  
  1805. gammapy/maps/tests/test_hpxcube.py:137:
  1806. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1807. gammapy/maps/hpxcube.py:376: in to_swapped_scheme
  1808. map_out = self.__class__(hpx_out)
  1809. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1810.  
  1811. self = <gammapy.maps.hpxcube.HpxMapND object at 0x1189aa0b8>, hpx = <gammapy.maps.hpx.HpxGeom object at 0x1189aa860>
  1812. data = array([[[ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
  1813. nan],
  1814. [ nan, nan, nan, ... nan],
  1815. [ nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
  1816. nan]]], dtype=float32)
  1817. dtype = 'float32'
  1818.  
  1819. def __init__(self, hpx, data=None, dtype='float32'):
  1820.  
  1821. shape = tuple([np.max(hpx.npix)] + [ax.nbin for ax in hpx.axes])
  1822. if data is None:
  1823.  
  1824. if hpx.npix.size > 1:
  1825. data = np.nan * np.ones(shape, dtype=dtype).T
  1826. pix = hpx.get_pixels(local=True)
  1827. > data[pix[::-1]] = 0.0
  1828. E IndexError: index 12 is out of bounds for axis 2 with size 12
  1829.  
  1830. gammapy/maps/hpxcube.py:41: IndexError
  1831. ____________________________________________ test_hpxcube_ud_grade[nside2-False-GAL-None-axes2] _____________________________________________
  1832.  
  1833. nside = [4, 8], nested = False, coordsys = 'GAL', region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x1180da6d8>]
  1834.  
  1835. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1836. hpx_test_geoms)
  1837. def test_hpxcube_ud_grade(nside, nested, coordsys, region, axes):
  1838. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1839. coordsys=coordsys, region=region, axes=axes))
  1840. > m.to_ud_graded(4)
  1841.  
  1842. gammapy/maps/tests/test_hpxcube.py:147:
  1843. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1844. gammapy/maps/hpxcube.py:410: in to_ud_graded
  1845. coords = self.hpx.get_coords()
  1846. gammapy/maps/hpx.py:1370: in get_coords
  1847. return self.pix_to_coord(pix)
  1848. gammapy/maps/hpx.py:637: in pix_to_coord
  1849. theta, phi = hp.pix2ang(nside, ipix, nest=self.nest)
  1850. ../astropy-healpix/astropy_healpix/healpy.py:98: in pix2ang
  1851. lon, lat = healpix_to_lonlat(ipix, nside, order='nested' if nest else 'ring')
  1852. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1853.  
  1854. healpix_index = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  1855. 13, 14, 15, 16, 17, 18, 19, 20,..., 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756,
  1856. 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767])
  1857. nside = array([4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  1858. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,... 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  1859. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8])
  1860. dx = None, dy = None, order = 'ring'
  1861.  
  1862. def healpix_to_lonlat(healpix_index, nside, dx=None, dy=None, order='ring'):
  1863. """
  1864. Convert HEALPix indices (optionally with offsets) to longitudes/latitudes.
  1865.  
  1866. If no offsets (``dx`` and ``dy``) are provided, the coordinates will default
  1867. to those at the center of the HEALPix pixels.
  1868.  
  1869. Parameters
  1870. ----------
  1871. healpix_index : int or `~numpy.ndarray`
  1872. HEALPix indices (as a scalar or array)
  1873. nside : int
  1874. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  1875. dx, dy : float or `~numpy.ndarray`, optional
  1876. Offsets inside the HEALPix pixel, which must be in the range [0:1],
  1877. where 0.5 is the center of the HEALPix pixels (as scalars or arrays)
  1878. order : { 'nested' | 'ring' }, optional
  1879. Order of HEALPix pixels
  1880.  
  1881. Returns
  1882. -------
  1883. lon : :class:`~astropy.coordinates.Longitude`
  1884. The longitude values
  1885. lat : :class:`~astropy.coordinates.Latitude`
  1886. The latitude values
  1887. """
  1888.  
  1889. if (dx is None and dy is not None) or (dx is not None and dy is None):
  1890. raise ValueError('Either both or neither dx and dy must be specified')
  1891.  
  1892. healpix_index = np.asarray(healpix_index, dtype=np.int64)
  1893.  
  1894. if dx is None and dy is not None:
  1895. dx = 0.5
  1896. elif dx is not None and dy is None:
  1897. dy = 0.5
  1898.  
  1899. if dx is not None:
  1900. dx = np.asarray(dx, dtype=np.float)
  1901. dy = np.asarray(dy, dtype=np.float)
  1902. _validate_offset('x', dx)
  1903. _validate_offset('y', dy)
  1904. healpix_index, dx, dy = np.broadcast_arrays(healpix_index, dx, dy)
  1905. dx = dx.ravel()
  1906. dy = dy.ravel()
  1907.  
  1908. shape = healpix_index.shape
  1909. healpix_index = healpix_index.ravel()
  1910. > nside = int(nside)
  1911. E TypeError: only length-1 arrays can be converted to Python scalars
  1912.  
  1913. ../astropy-healpix/astropy_healpix/core.py:287: TypeError
  1914. __________________________________________ test_hpxcube_sum_over_axes[nside2-False-GAL-None-axes2] __________________________________________
  1915.  
  1916. nside = [4, 8], nested = False, coordsys = 'GAL', region = None, axes = [<gammapy.maps.geom.MapAxis object at 0x1180da6d8>]
  1917.  
  1918. @pytest.mark.parametrize(('nside', 'nested', 'coordsys', 'region', 'axes'),
  1919. hpx_test_geoms)
  1920. def test_hpxcube_sum_over_axes(nside, nested, coordsys, region, axes):
  1921. m = HpxMapND(HpxGeom(nside=nside, nest=nested,
  1922. coordsys=coordsys, region=region, axes=axes))
  1923. > coords = m.geom.get_coords()
  1924.  
  1925. gammapy/maps/tests/test_hpxcube.py:155:
  1926. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1927. gammapy/maps/hpx.py:1370: in get_coords
  1928. return self.pix_to_coord(pix)
  1929. gammapy/maps/hpx.py:637: in pix_to_coord
  1930. theta, phi = hp.pix2ang(nside, ipix, nest=self.nest)
  1931. ../astropy-healpix/astropy_healpix/healpy.py:98: in pix2ang
  1932. lon, lat = healpix_to_lonlat(ipix, nside, order='nested' if nest else 'ring')
  1933. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  1934.  
  1935. healpix_index = array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  1936. 13, 14, 15, 16, 17, 18, 19, 20,..., 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756,
  1937. 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767])
  1938. nside = array([4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  1939. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,... 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  1940. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8])
  1941. dx = None, dy = None, order = 'ring'
  1942.  
  1943. def healpix_to_lonlat(healpix_index, nside, dx=None, dy=None, order='ring'):
  1944. """
  1945. Convert HEALPix indices (optionally with offsets) to longitudes/latitudes.
  1946.  
  1947. If no offsets (``dx`` and ``dy``) are provided, the coordinates will default
  1948. to those at the center of the HEALPix pixels.
  1949.  
  1950. Parameters
  1951. ----------
  1952. healpix_index : int or `~numpy.ndarray`
  1953. HEALPix indices (as a scalar or array)
  1954. nside : int
  1955. Number of pixels along the side of each of the 12 top-level HEALPix tiles
  1956. dx, dy : float or `~numpy.ndarray`, optional
  1957. Offsets inside the HEALPix pixel, which must be in the range [0:1],
  1958. where 0.5 is the center of the HEALPix pixels (as scalars or arrays)
  1959. order : { 'nested' | 'ring' }, optional
  1960. Order of HEALPix pixels
  1961.  
  1962. Returns
  1963. -------
  1964. lon : :class:`~astropy.coordinates.Longitude`
  1965. The longitude values
  1966. lat : :class:`~astropy.coordinates.Latitude`
  1967. The latitude values
  1968. """
  1969.  
  1970. if (dx is None and dy is not None) or (dx is not None and dy is None):
  1971. raise ValueError('Either both or neither dx and dy must be specified')
  1972.  
  1973. healpix_index = np.asarray(healpix_index, dtype=np.int64)
  1974.  
  1975. if dx is None and dy is not None:
  1976. dx = 0.5
  1977. elif dx is not None and dy is None:
  1978. dy = 0.5
  1979.  
  1980. if dx is not None:
  1981. dx = np.asarray(dx, dtype=np.float)
  1982. dy = np.asarray(dy, dtype=np.float)
  1983. _validate_offset('x', dx)
  1984. _validate_offset('y', dy)
  1985. healpix_index, dx, dy = np.broadcast_arrays(healpix_index, dx, dy)
  1986. dx = dx.ravel()
  1987. dy = dy.ravel()
  1988.  
  1989. shape = healpix_index.shape
  1990. healpix_index = healpix_index.ravel()
  1991. > nside = int(nside)
  1992. E TypeError: only length-1 arrays can be converted to Python scalars
  1993.  
  1994. ../astropy-healpix/astropy_healpix/core.py:287: TypeError
  1995. ======================================= 39 failed, 200 passed, 11 xfailed, 2 xpassed in 14.61 seconds =======================================
Add Comment
Please, Sign In to add comment