Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't require full catalog to plot pixel list #159

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
31 changes: 27 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,27 @@ 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 a list of pixels.

Args:
pixels: healpix pixels (order and pixel number) to visualize
plot_title (str): heading for the plot
projection (str) The map projection to use. Valid values include:
delucchi-cmu marked this conversation as resolved.
Show resolved Hide resolved
- 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 +97,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
12 changes: 11 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,13 @@ 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):
"""Test behavior of visualization methods for non-on-disk catalogs and pixel data."""
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)