Debian Codegraph @

astropy_healpix/tests/test_healpy.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 # Licensed under a 3-clause BSD style license - see LICENSE.rst
2 from itertoolsscip-python python python-stdlib 3.11 itertools/__init__: import productscip-python python python-stdlib 3.11 itertools/product#
3
4 from astropy.coordinatesscip-python python astropy 7.2.0 `astropy.coordinates`/__init__: import angular_separation
5 from astropyscip-python python astropy 7.2.0 astropy/__init__: import units as u
6 import pytestscip-python python pytest 9.0.3 pytest/__init__:
7 import numpyscip-python python numpy 2.4.6 numpy/__init__: as np
8
9 from numpy.testingscip-python python numpy 2.4.6 `numpy.testing`/__init__: import assert_equal, assert_allclose
10
11 from .. import healpy as hp_compat
12 from ..high_levelscip-python python astropy_healpix 1.1.2 high_level/__init__: import xyz_to_healpixscip-python python astropy_healpix 1.1.2 `astropy_healpix.core`/xyz_to_healpix().
13
14 from hypothesisscip-python python hypothesis 6.152.4 hypothesis/__init__: import given, settings, example
15 from hypothesis.strategiesscip-python python hypothesis 6.152.4 `hypothesis.strategies`/__init__: import integers, floats, booleans, tuples
16 from hypothesis.extra.numpyscip-python python hypothesis 6.152.4 `hypothesis.extra.numpy`/__init__: import arrays
17
18 # NOTE: If healpy is installed, we use it in these tests, but healpy is not a
19 # formal dependency of astropy-healpix.
20 hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp. = pytestscip-python python pytest 9.0.3 pytest/__init__:.importorskip('healpy')
21
22 NSIDE_VALUESscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/NSIDE_VALUES. = [2 ** n for n in rangescip-python python python-stdlib 3.11 builtins/range#(1, 6)]
23
24
25 @pytestscip-python python pytest 9.0.3 pytest/__init__:.mark.parametrize(('nside', 'degrees'), productscip-python python python-stdlib 3.11 itertools/product#(NSIDE_VALUESscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/NSIDE_VALUES., (False, True)))
26 def test_nside2pixareascip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2pixarea().(nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2pixarea().(nside), degreesscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2pixarea().(degrees)):
27 actual = hp_compat.nside2pixareascip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/nside2pixarea().(nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/nside2pixarea().(nside)=nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2pixarea().(nside), degreesscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/nside2pixarea().(degrees)=degreesscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2pixarea().(degrees))
28 expected = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..nside2pixarea(nside=nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2pixarea().(nside), degrees=degreesscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2pixarea().(degrees))
29 assert_allclose(actual, expected)
30
31
32 @pytestscip-python python pytest 9.0.3 pytest/__init__:.mark.parametrize(('nside', 'arcmin'), productscip-python python python-stdlib 3.11 itertools/product#(NSIDE_VALUESscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/NSIDE_VALUES., (False, True)))
33 def test_nside2resolscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2resol().(nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2resol().(nside), arcminscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2resol().(arcmin)):
34 actual = hp_compat.nside2resolscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/nside2resol().(nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/nside2resol().(nside)=nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2resol().(nside), arcminscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/nside2resol().(arcmin)=arcminscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2resol().(arcmin))
35 expected = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..nside2resol(nside=nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2resol().(nside), arcmin=arcminscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2resol().(arcmin))
36 assert_allclose(actual, expected)
37
38
39 @pytestscip-python python pytest 9.0.3 pytest/__init__:.mark.parametrize('nside', NSIDE_VALUESscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/NSIDE_VALUES.)
40 def test_nside2npixscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2npix().(nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2npix().(nside)):
41 actual = hp_compat.nside2npixscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/nside2npix().(nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2npix().(nside))
42 expected = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..nside2npix(nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nside2npix().(nside))
43 assert_equal(actual, expected)
44
45
46 @pytestscip-python python pytest 9.0.3 pytest/__init__:.mark.parametrize('level', [0, 3, 7])
47 def test_order2nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_order2nside().(levelscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_order2nside().(level)):
48 actual = hp_compat.order2nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/order2nside().(levelscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_order2nside().(level))
49 expected = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..order2nside(levelscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_order2nside().(level))
50 assert_equal(actual, expected)
51
52
53 @pytestscip-python python pytest 9.0.3 pytest/__init__:.mark.parametrize('npix', [12 * 2 ** (2 * n) for n in rangescip-python python python-stdlib 3.11 builtins/range#(1, 6)])
54 def test_npix2nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_npix2nside().(npixscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_npix2nside().(npix)):
55 actual = hp_compat.npix2nsidescip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/npix2nside().(npixscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_npix2nside().(npix))
56 expected = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..npix2nside(npixscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_npix2nside().(npix))
57 assert_equal(actual, expected)
58
59
60 # For the test below, we exclude latitudes that fall exactly on the pole or
61 # the equator since points that fall at exact boundaries are ambiguous.
62
63 @given(nside_pow=integers(0, 29), nest=booleans(), lonlat=booleans(),
64 lon=floats(0, 360, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(
65 lambda lon: abs(lon) > 1e-10),
66 lat=floats(-90, 90, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(
67 lambda lat: abs(lat) < 89.99 and abs(lat) > 1e-10))
68 @settings(max_examples=2000, derandomize=True, deadline=None)
69 def test_ang2pixscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(nside_pow), lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(lon), latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(lat), nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(nest), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(lonlat)):
70 nside = 2 ** nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(nside_pow)
71 if lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(lonlat):
72 theta, phi = lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(lon), latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(lat)
73 else:
74 theta, phi = np.pi / 2. - np.radians(latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(lat)), np.radians(lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(lon))
75 ipix1 = hp_compat.ang2pixscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/ang2pix().(nside, theta, phi, nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/ang2pix().(nest)=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(nest), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/ang2pix().(lonlat)=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(lonlat))
76 ipix2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..ang2pix(nside, theta, phi, nest=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(nest), lonlat=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix().(lonlat))
77 assert ipix1 == ipix2
78
79
80 def test_ang2pix_shapescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2pix_shape().():
81 ipix = hp_compat.ang2pixscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/ang2pix().(8, 1., 2.)
82 assert np.can_castscip-python python numpy 2.4.6 `numpy._core.multiarray`/can_cast().(ipix, np.int64)
83
84 ipix = hp_compat.ang2pixscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/ang2pix().(8, [[1., 2.], [3., 4.]], [[1., 2.], [3., 4.]])
85 assert ipix.shape == (2, 2)
86
87
88 def test_pix2ang_shapescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang_shape().():
89 lon, lat = hp_compat.pix2angscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/pix2ang().(8, 1)
90 assert isinstance(lon, floatscip-python python python-stdlib 3.11 builtins/float#)
91 assert isinstance(lat, floatscip-python python python-stdlib 3.11 builtins/float#)
92
93 lon, lat = hp_compat.pix2angscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/pix2ang().(8, [[1, 2, 3], [4, 5, 6]])
94 assert lon.shape == (2, 3)
95 assert lat.shape == (2, 3)
96
97
98 @given(nside_pow=integers(0, 29), nest=booleans(), lonlat=booleans(),
99 frac=floats(0, 1, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(lambda x: x < 1))
100 @settings(max_examples=2000, derandomize=True, deadline=None)
101 @example(nside_pow=29, frac=0.1666666694606345, nest=False, lonlat=False)
102 @example(nside_pow=27, frac=2./3., nest=True, lonlat=False)
103 def test_pix2angscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(nside_pow), fracscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(frac), nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(nest), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(lonlat)):
104 nside = 2 ** nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(nside_pow)
105 ipix = intscip-python python python-stdlib 3.11 builtins/int#(fracscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(frac) * 12 * nside ** 2)
106 theta1, phi1 = hp_compat.pix2angscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/pix2ang().(nside, ipix, nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/pix2ang().(nest)=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(nest), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/pix2ang().(lonlat)=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(lonlat))
107 theta2, phi2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..pix2ang(nside, ipix, nest=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(nest), lonlat=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(lonlat))
108 if lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2ang().(lonlat):
109 assert_allclose(phi1, phi2, atol=1e-8)
110 if abs(phi1) < 90:
111 assert_allclose(theta1, theta2, atol=1e-10)
112 else:
113 assert_allclose(theta1, theta2, atol=1e-8)
114 if theta1 > 0:
115 assert_allclose(phi1, phi2, atol=1e-10)
116
117
118 def not_on_boundariesscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/not_on_boundaries().(argsscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/not_on_boundaries().(args)):
119 """Skip vectors that are on the boundary of a pixel where ipix is ambiguous."""
120 nside_pow, nest, x, y, z = argsscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/not_on_boundaries().(args)
121 nside = 2 ** nside_pow
122 _, dx, dy = xyz_to_healpixscip-python python astropy_healpix 1.1.2 `astropy_healpix.core`/xyz_to_healpix().(
123 x, y, z, nside, return_offsetsscip-python python astropy_healpix 1.1.2 `astropy_healpix.core`/xyz_to_healpix().(return_offsets)=True, orderscip-python python astropy_healpix 1.1.2 `astropy_healpix.core`/xyz_to_healpix().(order)="nested" if nest else "ring"
124 )
125 return 0 < dx < 1 and 0 < dy < 1
126
127
128 @given(
129 args=tuples(
130 integers(0, 29), booleans(),
131 floats(-1, 1, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(lambda x: abs(x) > 1e-10),
132 floats(-1, 1, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(lambda y: abs(y) > 1e-10),
133 floats(-1, 1, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(lambda z: abs(z) > 1e-10)
134 ).filterscip-python python python-stdlib 3.11 builtins/filter#(not_on_boundariesscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/not_on_boundaries().)
135 )
136 @settings(max_examples=2000, derandomize=True, deadline=None)
137 def test_vec2pixscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2pix().(argsscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2pix().(args)):
138 nside_pow, nest, x, y, z = argsscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2pix().(args)
139 nside = 2 ** nside_pow
140 ipix1 = hp_compat.vec2pixscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/vec2pix().(nside, x, y, z, nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/vec2pix().(nest)=nest)
141 ipix2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..vec2pix(nside, x, y, z, nest=nest)
142 assert ipix1 == ipix2
143
144
145 @given(nside_pow=integers(0, 29), nest=booleans(),
146 frac=floats(0, 1, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(lambda x: x < 1))
147 @settings(max_examples=2000, derandomize=True, deadline=None)
148 @example(nside_pow=29, frac=0.1666666694606345, nest=False)
149 def test_pix2vecscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2vec().(nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2vec().(nside_pow), fracscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2vec().(frac), nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2vec().(nest)):
150 nside = 2 ** nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2vec().(nside_pow)
151 ipix = intscip-python python python-stdlib 3.11 builtins/int#(fracscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2vec().(frac) * 12 * nside ** 2)
152 xyz1 = hp_compat.pix2vecscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/pix2vec().(nside, ipix, nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/pix2vec().(nest)=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2vec().(nest))
153 xyz2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..pix2vec(nside, ipix, nest=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2vec().(nest))
154 assert_allclose(xyz1, xyz2, atol=1e-8)
155
156
157 def test_vec2pix_shapescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2pix_shape().():
158 ipix = hp_compat.vec2pixscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/vec2pix().(8, 1., 2., 3.)
159 assert np.can_castscip-python python numpy 2.4.6 `numpy._core.multiarray`/can_cast().(ipix, np.int64)
160
161 ipix = hp_compat.vec2pixscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/vec2pix().(8, [[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]], [[9., 10.], [11., 12.]])
162 assert ipix.shape == (2, 2)
163
164
165 def test_pix2vec_shapescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_pix2vec_shape().():
166 x, y, z = hp_compat.pix2vecscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/pix2vec().(8, 1)
167 assert isinstance(x, floatscip-python python python-stdlib 3.11 builtins/float#)
168 assert isinstance(y, floatscip-python python python-stdlib 3.11 builtins/float#)
169 assert isinstance(z, floatscip-python python python-stdlib 3.11 builtins/float#)
170
171 x, y, z = hp_compat.pix2vecscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/pix2vec().(8, [[1, 2, 3], [4, 5, 6]])
172 assert x.shape == (2, 3)
173 assert y.shape == (2, 3)
174 assert z.shape == (2, 3)
175
176
177 @given(nside_pow=integers(0, 29),
178 frac=floats(0, 1, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(lambda x: x < 1))
179 @settings(max_examples=2000, derandomize=True, deadline=None)
180 def test_nest2ringscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nest2ring().(nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nest2ring().(nside_pow), fracscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nest2ring().(frac)):
181 nside = 2 ** nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nest2ring().(nside_pow)
182 nest = intscip-python python python-stdlib 3.11 builtins/int#(fracscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_nest2ring().(frac) * 12 * nside ** 2)
183 ring1 = hp_compat.nest2ringscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/nest2ring().(nside, nest)
184 ring2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..nest2ring(nside, nest)
185 assert ring1 == ring2
186
187
188 @given(nside_pow=integers(0, 29),
189 frac=floats(0, 1, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(lambda x: x < 1))
190 @settings(max_examples=2000, derandomize=True, deadline=None)
191 @example(nside_pow=29, frac=0.16666666697710755)
192 def test_ring2nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ring2nest().(nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ring2nest().(nside_pow), fracscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ring2nest().(frac)):
193 nside = 2 ** nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ring2nest().(nside_pow)
194 ring = intscip-python python python-stdlib 3.11 builtins/int#(fracscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ring2nest().(frac) * 12 * nside ** 2)
195 nest1 = hp_compat.ring2nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/ring2nest().(nside, ring)
196 nest2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..ring2nest(nside, ring)
197 assert nest1 == nest2
198
199
200 @given(nside_pow=integers(0, 29), step=integers(1, 10), nest=booleans(),
201 frac=floats(0, 1, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(lambda x: x < 1))
202 @settings(max_examples=500, derandomize=True, deadline=None)
203 def test_boundariesscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(nside_pow), fracscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(frac), stepscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(step), nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(nest)):
204 nside = 2 ** nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(nside_pow)
205 pix = intscip-python python python-stdlib 3.11 builtins/int#(fracscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(frac) * 12 * nside ** 2)
206 b1 = hp_compat.boundariesscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/boundaries().(nside, pix, stepscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/boundaries().(step)=stepscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(step), nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/boundaries().(nest)=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(nest))
207 b2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..boundaries(nside, pix, step=stepscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(step), nest=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries().(nest))
208 assert_allclose(b1, b2, atol=1e-8)
209
210
211 def test_boundaries_shapescip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_boundaries_shape().():
212 pix = 1
213 b1 = hp_compat.boundariesscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/boundaries().(8, pix, stepscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/boundaries().(step)=4)
214 b2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..boundaries(8, pix, step=4)
215 assert b1.shape == b2.shape
216
217 pix = [1, 2, 3, 4, 5]
218 b1 = hp_compat.boundariesscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/boundaries().(8, pix, stepscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/boundaries().(step)=4)
219 b2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..boundaries(8, pix, step=4)
220 assert b1.shape == b2.shape
221
222
223 def not_at_originscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/not_at_origin().(vecscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/not_at_origin().(vec)):
224 return np.linalg.normscip-python python numpy 2.4.6 `numpy.linalg._linalg`/norm().(vecscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/not_at_origin().(vec)) > 0
225
226
227 @given(vectors=arrays(floatscip-python python python-stdlib 3.11 builtins/float#, (3,), elements=floats(-1, 1)).filterscip-python python python-stdlib 3.11 builtins/filter#(not_at_originscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/not_at_origin().),
228 lonlat=booleans(), ndim=integers(0, 4))
229 @settings(max_examples=500, derandomize=True, deadline=None)
230 def test_vec2angscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(vectorsscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(vectors), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(lonlat), ndimscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(ndim)):
231 vectorsscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(vectors) = np.broadcast_toscip-python python numpy 2.4.6 `numpy.lib._stride_tricks_impl`/broadcast_to().(vectorsscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(vectors), (2,) * ndimscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(ndim) + (3,))
232 lon1, lat1 = hp_compat.vec2angscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/vec2ang().(vectorsscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(vectors), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/vec2ang().(lonlat)=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(lonlat))
233 lon2, lat2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..vec2ang(vectorsscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(vectors), lonlat=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(lonlat))
234 if not lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_vec2ang().(lonlat):
235 lon1, lat1 = np.rad2deg(lat1), 90 - np.rad2deg(lon1)
236 lon2, lat2 = np.rad2deg(lat2), 90 - np.rad2deg(lon2)
237 sep = angular_separation(
238 lon1 * u.degscip-python python astropy_healpix 1.1.2 `astropy.units.core`/arcmin#, lat1 * u.degscip-python python astropy_healpix 1.1.2 `astropy.units.core`/arcmin#, lon2 * u.degscip-python python astropy_healpix 1.1.2 `astropy.units.core`/arcmin#, lat2 * u.degscip-python python astropy_healpix 1.1.2 `astropy.units.core`/arcmin#
239 ).to_value(u.radscip-python python astropy_healpix 1.1.2 `astropy.units.core`/sr#)
240 assert_allclose(sep, 0, atol=1e-8)
241
242
243 @given(lonlat=booleans(),
244 lon=floats(0, 360, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(
245 lambda lon: abs(lon) > 1e-10),
246 lat=floats(-90, 90, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(
247 lambda lat: abs(lat) < 89.99 and abs(lat) > 1e-10))
248 @settings(max_examples=2000, derandomize=True, deadline=None)
249 def test_ang2vecscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lon), latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lat), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lonlat)):
250 if lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lonlat):
251 theta, phi = lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lon), latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lat)
252 else:
253 theta, phi = np.pi / 2. - np.radians(latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lat)), np.radians(lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lon))
254 xyz1 = hp_compat.ang2vecscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/ang2vec().(theta, phi, lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/ang2vec().(lonlat)=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lonlat))
255 xyz2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..ang2vec(theta, phi, lonlat=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_ang2vec().(lonlat))
256 assert_allclose(xyz1, xyz2, atol=1e-10)
257
258
259 # The following fails, need to investigate:
260 # @example(nside_pow=29, lon=1.0000000028043134e-05, lat=1.000000000805912e-05,
261 # nest=False, lonlat=False)
262 #
263
264 @given(nside_pow=integers(0, 28), nest=booleans(), lonlat=booleans(),
265 lon=floats(0, 360, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(
266 lambda lon: abs(lon) > 1e-5),
267 lat=floats(-90, 90, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(
268 lambda lat: abs(lat) < 89.99 and abs(lat) > 1e-5))
269 @settings(max_examples=500, derandomize=True, deadline=None)
270 @example(nside_pow=27, lon=1.0000000028043134e-05, lat=-41.81031451395941, nest=False, lonlat=False)
271 @example(nside_pow=6, lon=1.6345238095238293, lat=69.42254649458224, nest=False, lonlat=False)
272 @example(nside_pow=15, lon=1.0000000028043134e-05, lat=1.000000000805912e-05,
273 nest=False, lonlat=False)
274 @example(nside_pow=0, lon=315.0000117809725, lat=1.000000000805912e-05, nest=False, lonlat=False)
275 @example(nside_pow=0, lon=1.0000000028043134e-05, lat=-41.81031489577861, nest=False, lonlat=False)
276 @example(nside_pow=0, lon=35.559942143736414, lat=-41.8103252622604, nest=False, lonlat=False)
277 @example(nside_pow=28, lon=359.9999922886491, lat=-41.81031470486902, nest=False, lonlat=False)
278 @example(nside_pow=0, lon=1.0000000028043134e-05, lat=-41.81031489577861, nest=False, lonlat=False)
279 @example(nside_pow=27, lon=1.0000000028043134e-05, lat=-41.81031451395941, nest=False, lonlat=False)
280 @example(nside_pow=26, lon=359.9999986588955, lat=41.81031489577861, nest=False, lonlat=False)
281 @example(nside_pow=27, lon=359.999997317791, lat=-41.81031451395943, nest=False, lonlat=False)
282 @example(nside_pow=27, lon=1.0000000028043134e-05, lat=89.80224636153702, nest=False, lonlat=False)
283 def test_interp_weightsscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(nside_pow), lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(lon), latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(lat), nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(nest), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(lonlat)):
284 nside = 2 ** nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(nside_pow)
285 if lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(lonlat):
286 theta, phi = lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(lon), latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(lat)
287 else:
288 theta, phi = np.pi / 2. - np.radians(latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(lat)), np.radians(lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(lon))
289 indices1, weights1 = hp_compat.get_interp_weightsscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/get_interp_weights().(nside, theta, phi, nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/get_interp_weights().(nest)=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(nest), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/get_interp_weights().(lonlat)=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(lonlat))
290 indices2, weights2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..get_interp_weights(nside, theta, phi, nest=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(nest), lonlat=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_weights().(lonlat))
291
292 # Ignore neighbours with weights < 1e-6 - we have to exclude these otherwise
293 # in some corner cases there will be different low-probability neighbours.
294
295 keep = weights1 > 1e-6
296 indices1, weights1 = indices1[keep], weights1[keep]
297
298 keep = weights2 > 1e-6
299 indices2, weights2 = indices2[keep], weights2[keep]
300
301 order1 = np.argsortscip-python python numpy 2.4.6 `numpy._core.fromnumeric`/argsort().(indices1)
302 order2 = np.argsortscip-python python numpy 2.4.6 `numpy._core.fromnumeric`/argsort().(indices2)
303
304 assert_equal(indices1[order1], indices2[order2])
•305 assert_allclose(weights1[order1], weights2[order2], atol=1e-4)
306
307
308 # Make an array that can be useful up to the highest nside tested below
309 NSIDE_POW_MAXscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/NSIDE_POW_MAX. = 8
310 VALUESscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/VALUES. = np.random.random(12 * NSIDE_POW_MAXscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/NSIDE_POW_MAX. ** 2)
311
312
313 @given(nside_pow=integers(0, NSIDE_POW_MAXscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/NSIDE_POW_MAX.), nest=booleans(), lonlat=booleans(),
314 lon=floats(0, 360, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(
315 lambda lon: abs(lon) > 1e-5),
316 lat=floats(-90, 90, allow_nan=False, allow_infinity=False).filterscip-python python python-stdlib 3.11 builtins/filter#(
317 lambda lat: abs(lat) < 89.99 and abs(lat) > 1e-5))
318 @settings(max_examples=500, derandomize=True, deadline=None)
319 def test_interp_valscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(nside_pow), lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(lon), latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(lat), nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(nest), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(lonlat)):
320 nside = 2 ** nside_powscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(nside_pow)
321 if lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(lonlat):
322 theta, phi = lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(lon), latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(lat)
323 else:
324 theta, phi = np.pi / 2. - np.radians(latscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(lat)), np.radians(lonscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(lon))
325 m = VALUESscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/VALUES.[:12 * nside ** 2]
326 value1 = hp_compat.get_interp_valscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/get_interp_val().(m, theta, phi, nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/get_interp_val().(nest)=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(nest), lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.healpy`/get_interp_val().(lonlat)=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(lonlat))
327 value2 = hpscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/hp..get_interp_val(m, theta, phi, nest=nestscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(nest), lonlat=lonlatscip-python python astropy_healpix 1.1.2 `astropy_healpix.tests.test_healpy`/test_interp_val().(lonlat))
328 assert_allclose(value1, value2, rtol=0.1, atol=1.e-10)