Skip to content

Commit

Permalink
Convenience method to estimate mindist for a given order.
Browse files Browse the repository at this point in the history
  • Loading branch information
delucchi-cmu committed Oct 23, 2024
1 parent 499c66a commit fb7683a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/hats/pixel_math/healpix_shim.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import healpy as hp
import numpy as np

Expand Down Expand Up @@ -187,3 +189,25 @@ def margin2order(margin_thr_arcmin: np.ndarray) -> np.ndarray:
"""
avg_size_arcmin = mindist2avgsize(margin_thr_arcmin)
return avgsize2order(avg_size_arcmin)


def order2mindist(order: np.ndarray | int) -> np.ndarray | float:
"""Get the estimated minimum distance between pixels at a given order.
We don't have the precise geometry of the healpix grid yet,
we are using average_size / mininimum_distance = 1.6
as a rough estimate.
Parameters
----------
order : np.ndarray of int or a single scalar int
The healpix order
Returns
-------
np.ndarray of float or a single scalar float
The minimum distance between pixels in arcminutes
"""
pixel_nside = order2nside(order)
pixel_avgsize = nside2resol(pixel_nside, arcmin=True)
return avgsize2mindist(pixel_avgsize)
9 changes: 9 additions & 0 deletions tests/hats/pixel_math/test_healpix_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ def test_margin2order():
margin_thr_arcmin = np.array([1 / 60, 10 / 60, 1, 5, 60])
orders = np.array([17, 13, 11, 8, 5])
assert_array_equal(hps.margin2order(margin_thr_arcmin), orders)


def test_order2mindist():
"""Test order2mindist for some pre-computed values"""
orders = np.array([17, 13, 11, 8, 5])
min_distances = np.array([0.01677, 0.268, 1.07, 8.588, 68.7])
assert_allclose(hps.order2mindist(orders), min_distances, rtol=1e-2)

assert_allclose(hps.order2mindist(17), 0.01677, rtol=1e-2)

0 comments on commit fb7683a

Please sign in to comment.