Skip to content

Commit

Permalink
Remove unused methods in pixel margin module (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
delucchi-cmu authored Sep 16, 2024
1 parent efb34b6 commit 4357f0c
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 66 deletions.
3 changes: 0 additions & 3 deletions docs/guide/pixel_math.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ faces).
#### Implementation
Pretty straightforward implementation of the algorithm above.

### pixel_is_polar
Because of the nature of spherical coordinate systems, hipscat runs into some tricky edge cases at the poles. To ensure we can appropriately handle those problems, we need to check if a pixel is one of the four 'polar pixels'.

#### Algorithm
In the ring id scheme for `healpix`, the first and last 4 pixels are the polar pixels. To determine whether a nest scheme pixel is at the poles, all we have to do is convert the pixel into the ring scheme and determine if it falls at the beginning or end of the range 0 -> npix. So, if in the ring scheme the pix is `<= 3`, or `>= npix - 4`, we can safely assume that it is a polar pixel.

Expand Down
2 changes: 1 addition & 1 deletion src/hipscat/pixel_math/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .hipscat_id import compute_hipscat_id, hipscat_id_to_healpix
from .margin_bounding import check_margin_bounds
from .partition_stats import empty_histogram, generate_alignment, generate_histogram
from .pixel_margins import get_edge, get_margin, pixel_is_polar
from .pixel_margins import get_margin
4 changes: 0 additions & 4 deletions src/hipscat/pixel_math/healpix_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ def ring2nest(*args, **kwargs):
return hp.ring2nest(*args, **kwargs)


def nest2ring(*args, **kwargs):
return hp.nest2ring(*args, **kwargs)


def unseen_pixel():
return hp.pixelfunc.UNSEEN

Expand Down
25 changes: 1 addition & 24 deletions src/hipscat/pixel_math/pixel_margins.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_margin(order, pix, d_order):
_, _, pix_face = hp.pix2xyf(nside, pix, nest=True)
_, _, faces = hp.pix2xyf(nside, neighbors, nest=True)

# indices which tell get_edge() which edge/verted to return
# indices which tell get_edge() which edge/vertex to return
# for a given pixel. The default order is compatible with the
# order returned by hp.get_all_neighbours().
which = np.arange(8)
Expand All @@ -114,26 +114,3 @@ def get_margin(order, pix, d_order):
margins.append(get_edge(d_order, pixel, edge))
margins = np.concatenate(margins)
return margins


def pixel_is_polar(order, pix):
"""Checks if a healpixel is a polar pixel.
Args:
order (int): the healpix order of the pixel to be checked.
pix (int): the id of a healpixel to be checked. must be in the nested id scheme.
Returns:
tuple of a boolean and a string, the boolean indicating whether the pixel
polar and the string denoting which pole it is ('North' or 'South')).
string is empty in the case that the pixel isn't polar.
"""
nside = hp.order2nside(order)
npix = hp.nside2npix(nside)
ring_pix = hp.nest2ring(nside, pix)

# in the ring numbering scheme, the first and last 4 pixels are the poles.
if ring_pix <= 3:
return (True, "North")
if ring_pix >= npix - 4:
return (True, "South")
return (False, "")
35 changes: 1 addition & 34 deletions tests/hipscat/pixel_math/test_pixel_margins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy.testing as npt
import pytest

import hipscat.pixel_math as pm
import hipscat.pixel_math.pixel_margins as pm


def test_get_margin():
Expand Down Expand Up @@ -137,36 +137,3 @@ def test_edge_greater_than_7():
pm.get_edge(2, 5, 8)

assert str(value_error.value) == "edge can only be values between 0 and 7 (see docstring)"


def test_pixel_is_polar_north():
"""Check to make sure pixel_is_polar works for a pixel at the north pole."""
order = 2
pix = 31

polar, pole = pm.pixel_is_polar(order, pix)

assert polar
assert pole == "North"


def test_pixel_is_polar_south():
"""Check to make sure pixel_is_polar works for a pixel at the south pole."""
order = 2
pix = 160

polar, pole = pm.pixel_is_polar(order, pix)

assert polar
assert pole == "South"


def test_pixel_is_polar_non_pole():
"""Check to make sure pixel_is_polar works for non-polar pixels."""
order = 2
pix = 105

polar, pole = pm.pixel_is_polar(order, pix)

assert not polar
assert pole == ""

0 comments on commit 4357f0c

Please sign in to comment.