Skip to content

Commit 2ea3300

Browse files
authored
Merge pull request #159 from astronomy-commons/issue/157/viz
Don't require full catalog to plot pixel list
2 parents 8340e73 + 80ca21e commit 2ea3300

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

src/hipscat/inspection/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .visualize_catalog import plot_pixels, plot_points
1+
from .visualize_catalog import plot_pixel_list, plot_pixels, plot_points

src/hipscat/inspection/visualize_catalog.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
NB: Testing validity of generated plots is currently not tested in our unit test suite.
44
"""
55

6-
from typing import Any, Dict, Union
6+
from typing import Any, Dict, List, Union
77

88
import healpy as hp
99
import numpy as np
1010
from matplotlib import pyplot as plt
1111

1212
from hipscat.catalog import Catalog
1313
from hipscat.io import file_io, paths
14+
from hipscat.pixel_math import HealpixPixel
1415

1516

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

2829

2930
def plot_points(catalog: Catalog, projection="moll", draw_map=True):
30-
"""Create a visual map of the input points of the catalog.
31+
"""Create a visual map of the input points of an in-memory catalog.
3132
3233
Args:
3334
catalog (`hipscat.catalog.Catalog`) Catalog to display
@@ -37,6 +38,8 @@ def plot_points(catalog: Catalog, projection="moll", draw_map=True):
3738
- cart - Cartesian projection
3839
- orth - Orthographic projection
3940
"""
41+
if not catalog.on_disk:
42+
raise ValueError("on disk catalog required for point-wise visualization")
4043
point_map = _read_point_map(catalog.catalog_base_dir, storage_options=catalog.storage_options)
4144
_plot_healpix_map(
4245
point_map,
@@ -58,7 +61,27 @@ def plot_pixels(catalog: Catalog, projection="moll", draw_map=True):
5861
- orth - Orthographic projection
5962
"""
6063
pixels = catalog.get_healpix_pixels()
61-
max_order = catalog.partition_info.get_highest_order()
64+
plot_pixel_list(
65+
pixels=pixels,
66+
plot_title=f"Catalog pixel density map - {catalog.catalog_name}",
67+
projection=projection,
68+
draw_map=draw_map,
69+
)
70+
71+
72+
def plot_pixel_list(pixels: List[HealpixPixel], plot_title: str = "", projection="moll", draw_map=True):
73+
"""Create a visual map of the pixel density of a list of pixels.
74+
75+
Args:
76+
pixels: healpix pixels (order and pixel number) to visualize
77+
plot_title (str): heading for the plot
78+
projection (str) The map projection to use. Valid values include:
79+
- moll - Molleweide projection (default)
80+
- gnom - Gnomonic projection
81+
- cart - Cartesian projection
82+
- orth - Orthographic projection
83+
"""
84+
max_order = np.max(pixels).order
6285

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

@@ -74,7 +97,7 @@ def plot_pixels(catalog: Catalog, projection="moll", draw_map=True):
7497
_plot_healpix_map(
7598
order_map,
7699
projection,
77-
f"Catalog pixel density map - {catalog.catalog_name}",
100+
plot_title,
78101
draw_map=draw_map,
79102
)
80103

tests/hipscat/inspection/test_visualize_catalog.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from hipscat.catalog import Catalog
4-
from hipscat.inspection import plot_pixels, plot_points
4+
from hipscat.inspection import plot_pixel_list, plot_pixels, plot_points
55

66

77
@pytest.mark.parametrize("projection", ["moll", "gnom", "cart", "orth"])
@@ -33,3 +33,13 @@ def test_generate_map_order1(small_sky_order1_dir):
3333
cat = Catalog.read_from_hipscat(small_sky_order1_dir)
3434
plot_pixels(cat, draw_map=False)
3535
plot_points(cat, draw_map=False)
36+
37+
38+
def test_visualize_in_memory_catalogs(catalog_info, catalog_pixels):
39+
"""Test behavior of visualization methods for non-on-disk catalogs and pixel data."""
40+
catalog = Catalog(catalog_info, catalog_pixels)
41+
plot_pixels(catalog, draw_map=False)
42+
plot_pixel_list(catalog_pixels, plot_title="My special catalog", draw_map=False)
43+
44+
with pytest.raises(ValueError, match="on disk catalog required"):
45+
plot_points(catalog, draw_map=False)

0 commit comments

Comments
 (0)