Skip to content

Commit 1628457

Browse files
authored
Convenience method to estimate mindist for a given order. (#392)
1 parent 499c66a commit 1628457

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/hats/pixel_math/healpix_shim.py

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import healpy as hp
24
import numpy as np
35

@@ -187,3 +189,25 @@ def margin2order(margin_thr_arcmin: np.ndarray) -> np.ndarray:
187189
"""
188190
avg_size_arcmin = mindist2avgsize(margin_thr_arcmin)
189191
return avgsize2order(avg_size_arcmin)
192+
193+
194+
def order2mindist(order: np.ndarray | int) -> np.ndarray | float:
195+
"""Get the estimated minimum distance between pixels at a given order.
196+
197+
We don't have the precise geometry of the healpix grid yet,
198+
we are using average_size / mininimum_distance = 1.6
199+
as a rough estimate.
200+
201+
Parameters
202+
----------
203+
order : np.ndarray of int or a single scalar int
204+
The healpix order
205+
206+
Returns
207+
-------
208+
np.ndarray of float or a single scalar float
209+
The minimum distance between pixels in arcminutes
210+
"""
211+
pixel_nside = order2nside(order)
212+
pixel_avgsize = nside2resol(pixel_nside, arcmin=True)
213+
return avgsize2mindist(pixel_avgsize)

tests/hats/pixel_math/test_healpix_shim.py

+9
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ def test_margin2order():
2828
margin_thr_arcmin = np.array([1 / 60, 10 / 60, 1, 5, 60])
2929
orders = np.array([17, 13, 11, 8, 5])
3030
assert_array_equal(hps.margin2order(margin_thr_arcmin), orders)
31+
32+
33+
def test_order2mindist():
34+
"""Test order2mindist for some pre-computed values"""
35+
orders = np.array([17, 13, 11, 8, 5])
36+
min_distances = np.array([0.01677, 0.268, 1.07, 8.588, 68.7])
37+
assert_allclose(hps.order2mindist(orders), min_distances, rtol=1e-2)
38+
39+
assert_allclose(hps.order2mindist(17), 0.01677, rtol=1e-2)

0 commit comments

Comments
 (0)