Skip to content

Commit

Permalink
Don't require full catalog to plot pixel list
Browse files Browse the repository at this point in the history
  • Loading branch information
delucchi-cmu committed Nov 2, 2023
1 parent 8340e73 commit c733f37
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/hipscat/inspection/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .visualize_catalog import plot_pixels, plot_points
from .visualize_catalog import plot_pixel_list, plot_pixels, plot_points
30 changes: 26 additions & 4 deletions src/hipscat/inspection/visualize_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
NB: Testing validity of generated plots is currently not tested in our unit test suite.
"""

from typing import Any, Dict, Union
from typing import Any, Dict, List, Union

import healpy as hp
import numpy as np
from matplotlib import pyplot as plt

from hipscat.catalog import Catalog
from hipscat.io import file_io, paths
from hipscat.pixel_math import HealpixPixel


def _read_point_map(catalog_base_dir, storage_options: Union[Dict[Any, Any], None] = None):
Expand All @@ -27,7 +28,7 @@ def _read_point_map(catalog_base_dir, storage_options: Union[Dict[Any, Any], Non


def plot_points(catalog: Catalog, projection="moll", draw_map=True):
"""Create a visual map of the input points of the catalog.
"""Create a visual map of the input points of an in-memory catalog.
Args:
catalog (`hipscat.catalog.Catalog`) Catalog to display
Expand All @@ -37,6 +38,8 @@ def plot_points(catalog: Catalog, projection="moll", draw_map=True):
- cart - Cartesian projection
- orth - Orthographic projection
"""
if not catalog.on_disk:
raise ValueError("on disk catalog required for point-wise visualization")
point_map = _read_point_map(catalog.catalog_base_dir, storage_options=catalog.storage_options)
_plot_healpix_map(
point_map,
Expand All @@ -58,7 +61,26 @@ def plot_pixels(catalog: Catalog, projection="moll", draw_map=True):
- orth - Orthographic projection
"""
pixels = catalog.get_healpix_pixels()
max_order = catalog.partition_info.get_highest_order()
plot_pixel_list(
pixels=pixels,
plot_title=f"Catalog pixel density map - {catalog.catalog_name}",
projection=projection,
draw_map=draw_map,
)


def plot_pixel_list(pixels: List[HealpixPixel], plot_title: str = "", projection="moll", draw_map=True):
"""Create a visual map of the pixel density of the catalog.
Args:
catalog (`hipscat.catalog.Catalog`) Catalog to display
projection (str) The map projection to use. Valid values include:
- moll - Molleweide projection (default)
- gnom - Gnomonic projection
- cart - Cartesian projection
- orth - Orthographic projection
"""
max_order = np.max(pixels).order

order_map = np.full(hp.order2npix(max_order), hp.pixelfunc.UNSEEN)

Expand All @@ -74,7 +96,7 @@ def plot_pixels(catalog: Catalog, projection="moll", draw_map=True):
_plot_healpix_map(
order_map,
projection,
f"Catalog pixel density map - {catalog.catalog_name}",
plot_title,
draw_map=draw_map,
)

Expand Down
11 changes: 10 additions & 1 deletion tests/hipscat/inspection/test_visualize_catalog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from hipscat.catalog import Catalog
from hipscat.inspection import plot_pixels, plot_points
from hipscat.inspection import plot_pixel_list, plot_pixels, plot_points


@pytest.mark.parametrize("projection", ["moll", "gnom", "cart", "orth"])
Expand Down Expand Up @@ -33,3 +33,12 @@ def test_generate_map_order1(small_sky_order1_dir):
cat = Catalog.read_from_hipscat(small_sky_order1_dir)
plot_pixels(cat, draw_map=False)
plot_points(cat, draw_map=False)


def test_visualize_in_memory_catalogs(catalog_info, catalog_pixels):
catalog = Catalog(catalog_info, catalog_pixels)
plot_pixels(catalog, draw_map=False)
plot_pixel_list(catalog_pixels, plot_title="My special catalog", draw_map=False)

with pytest.raises(ValueError, match="on disk catalog required"):
plot_points(catalog, draw_map=False)

0 comments on commit c733f37

Please sign in to comment.