Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience method to estimate mindist for a given order. #392

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)