Skip to content

Commit

Permalink
Add plot_pixels method to Catalog (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
delucchi-cmu authored Mar 12, 2024
1 parent efa6cfb commit 76f2265
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/lsdb/catalog/dataset/healpix_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pandas as pd
from dask.delayed import Delayed, delayed
from hipscat.catalog.healpix_dataset.healpix_dataset import HealpixDataset as HCHealpixDataset
from hipscat.inspection import plot_pixel_list
from hipscat.pixel_math import HealpixPixel
from hipscat.pixel_math.healpix_pixel_function import get_pixel_argsort
from typing_extensions import Self
Expand Down Expand Up @@ -232,6 +233,19 @@ def skymap(self, func: Callable[[pd.DataFrame, HealpixPixel], Any], **kwargs):
result_dict = {pixels[i]: results[i] for i in range(len(pixels))}
plot_skymap(result_dict)

def plot_pixels(self, projection: str = "moll", **kwargs):
"""Create a visual map of the pixel density of the catalog.
Args:
projection (str) The map projection to use. Valid values include:
- moll - Molleweide projection (default)
- gnom - Gnomonic projection
- cart - Cartesian projection
- orth - Orthographic projection
kwargs (dict): additional keyword arguments to pass to plotting call.
"""
plot_pixel_list(self.get_healpix_pixels(), projection, **kwargs)

def to_hipscat(
self,
base_catalog_path: str,
Expand Down
14 changes: 14 additions & 0 deletions tests/lsdb/catalog/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,17 @@ def func(df, healpix):
img[img_order_pixels] = value
hp.mollview.assert_called_once()
assert (hp.mollview.call_args[0][0] == img).all()


# pylint: disable=no-member
def test_plot_pixels(small_sky_order1_catalog, mocker):
mocker.patch("healpy.mollview")

small_sky_order1_catalog.plot_pixels()

# Everything will be empty, except the four pixels at order 1.
img = np.full(48, hp.pixelfunc.UNSEEN)
img[[44, 45, 46, 47]] = 1

hp.mollview.assert_called_once()
assert (hp.mollview.call_args[0][0] == img).all()

0 comments on commit 76f2265

Please sign in to comment.