26
26
from mocpy .moc .plot .culling_backfacing_cells import backface_culling
27
27
from mocpy .moc .plot .utils import _set_wcs
28
28
29
+ import hats .pixel_math .healpix_shim as hp
29
30
from hats .io import file_io , paths
30
31
from hats .pixel_math import HealpixPixel
31
32
from hats .pixel_tree .moc_filter import perform_filter_by_moc
@@ -49,19 +50,42 @@ def _read_point_map(catalog_base_dir):
49
50
return file_io .read_fits_image (map_file_pointer )
50
51
51
52
52
- def plot_points (catalog : Catalog , plot_title : str | None = None , ** kwargs ):
53
- """Create a visual map of the input points of an in-memory catalog.
54
-
53
+ def plot_density (catalog : Catalog , * , plot_title : str | None = None , order = None , unit = None , ** kwargs ):
54
+ """Create a visual map of the density of input points of a catalog on-disk.
55
55
Args:
56
56
catalog (`hats.catalog.Catalog`) Catalog to display
57
57
plot_title (str): Optional title for the plot
58
+ order (int): Optionally reduce the display healpix order, and aggregate smaller tiles.
58
59
kwargs: Additional args to pass to `plot_healpix_map`
59
60
"""
60
61
if not catalog .on_disk :
61
62
raise ValueError ("on disk catalog required for point-wise visualization" )
62
63
point_map = _read_point_map (catalog .catalog_base_dir )
63
- default_title = f"Catalog point density map - { catalog .catalog_name } "
64
- return plot_healpix_map (point_map , title = default_title if plot_title is None else plot_title , ** kwargs )
64
+ map_order = hp .npix2order (len (point_map ))
65
+
66
+ if order is not None :
67
+ if order > map_order :
68
+ raise ValueError (f"plotting order should be less than stored density map order ({ map_order } )" )
69
+ ## Create larger pixel sums from the constituent pixels.
70
+ point_map = point_map .reshape ((hp .order2npix (order ), 2 ** (2 * (map_order - order )))).sum (axis = 1 )
71
+ else :
72
+ order = map_order
73
+ if unit is None :
74
+ unit = u .deg
75
+
76
+ pix_area = hp .order2pixarea (order , unit = unit )
77
+
78
+ point_map = point_map / pix_area
79
+ default_title = f"Angular density of catalog { catalog .catalog_name } "
80
+ fig , ax = plot_healpix_map (
81
+ point_map , title = default_title if plot_title is None else plot_title , cbar = False , ** kwargs
82
+ )
83
+ col = ax .collections [0 ]
84
+ plt .colorbar (
85
+ col ,
86
+ label = f"count / { unit } sq" ,
87
+ )
88
+ return fig , ax
65
89
66
90
67
91
def plot_pixels (catalog : HealpixDataset , plot_title : str | None = None , ** kwargs ):
0 commit comments