Skip to content

Commit b62d29c

Browse files
authored
Support other list-like inputs for plot_healpix_map (#606)
1 parent 83b2c34 commit b62d29c

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/hats/inspection/_plotting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def _initialize_wcs_axes(
397397
return fig, ax, wcs
398398

399399

400-
# pylint: disable=import-outside-toplevel,import-error,disable=too-many-locals
400+
# pylint: disable=import-outside-toplevel,import-error,too-many-locals
401401
def _plot_healpix_value_map(ipix, depth, values, ax, wcs, cmap="viridis", norm=None, cbar=True, **kwargs):
402402
"""Perform the plotting of a healpix pixel map."""
403403
import matplotlib.pyplot as plt
@@ -406,6 +406,8 @@ def _plot_healpix_value_map(ipix, depth, values, ax, wcs, cmap="viridis", norm=N
406406

407407
# create dict mapping depth to ipix and values
408408
depth_ipix_d = {}
409+
values = np.array(values)
410+
ipix = np.array(ipix)
409411

410412
for d in np.unique(depth):
411413
mask = depth == d

tests/hats/inspection/test_visualize_catalog.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import astropy.units as u
44
import numpy as np
5+
import pandas as pd
56
import pytest
67
from astropy.coordinates import Angle, SkyCoord
78
from mocpy import MOC, WCS
@@ -843,6 +844,37 @@ def test_plot_kwargs():
843844
np.testing.assert_array_equal(col.get_array(), pix_map)
844845

845846

847+
def test_plot_healpix_map_types():
848+
"""Pass healpix map, using various list-like types."""
849+
pytest.importorskip("matplotlib.pyplot")
850+
851+
# First, use all numpy arrays to get the golden value.
852+
length = 192
853+
pix_map_np = np.arange(length)
854+
_, ax = plot_healpix_map(pix_map_np)
855+
num_np_paths = len(ax.collections[0].get_paths())
856+
857+
pix_map = list(np.arange(length))
858+
_, ax = plot_healpix_map(pix_map)
859+
assert len(ax.collections) > 0
860+
assert len(ax.collections[0].get_paths()) == num_np_paths
861+
862+
order = 2
863+
ipix = list(np.arange(length))
864+
pix_map = list(range(0, length))
865+
depth = list(np.full(length, fill_value=order))
866+
_, ax = plot_healpix_map(pix_map, ipix=ipix, depth=depth)
867+
assert len(ax.collections) > 0
868+
assert len(ax.collections[0].get_paths()) == num_np_paths
869+
870+
ipix = pd.Series(range(0, length))
871+
pix_map = range(0, length)
872+
depth = pd.Series(np.full(length, fill_value=order))
873+
_, ax = plot_healpix_map(pix_map, ipix=ipix, depth=depth)
874+
assert len(ax.collections) > 0
875+
assert len(ax.collections[0].get_paths()) == num_np_paths
876+
877+
846878
def test_plot_existing_fig():
847879
plt = pytest.importorskip("matplotlib.pyplot")
848880

0 commit comments

Comments
 (0)