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

plot_pixels with no pixels has confusing error #468

Open
2 of 3 tasks
delucchi-cmu opened this issue Mar 5, 2025 · 0 comments
Open
2 of 3 tasks

plot_pixels with no pixels has confusing error #468

delucchi-cmu opened this issue Mar 5, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@delucchi-cmu
Copy link
Contributor

Bug report

If you have a catalog with no remaining pixels (e.g. a cone search that lies outside the survey footprint), and you attempt to plot the pixels, you get an error way on down inside the libraries.

We could make a quick check that there are some pixels before attempting plotting and throw a friendlier error.

File ~/git/smoke/hats/src/hats/catalog/healpix_dataset/healpix_dataset.py:241, in HealpixDataset.plot_pixels(self, **kwargs)
    [235](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/catalog/healpix_dataset/healpix_dataset.py:235) def plot_pixels(self, **kwargs):
    [236](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/catalog/healpix_dataset/healpix_dataset.py:236)     """Create a visual map of the pixel density of the catalog.
    [237](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/catalog/healpix_dataset/healpix_dataset.py:237) 
    [238](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/catalog/healpix_dataset/healpix_dataset.py:238)     Args:
    [239](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/catalog/healpix_dataset/healpix_dataset.py:239)         kwargs: Additional args to pass to `hats.inspection.visualize_catalog.plot_healpix_map`
    [240](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/catalog/healpix_dataset/healpix_dataset.py:240)     """
--> [241](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/catalog/healpix_dataset/healpix_dataset.py:241)     return plot_pixels(self, **kwargs)

File ~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:101, in plot_pixels(catalog, plot_title, **kwargs)
     [99](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:99) pixels = catalog.get_healpix_pixels()
    [100](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:100) default_title = f"Catalog pixel density map - {catalog.catalog_name}"
--> [101](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:101) return plot_pixel_list(
    [102](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:102)     pixels=pixels,
    [103](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:103)     plot_title=default_title if plot_title is None else plot_title,
    [104](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:104)     **kwargs,
    [105](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:105) )

File ~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:124, in plot_pixel_list(pixels, plot_title, projection, color_by_order, **kwargs)
    [122](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:122) ipix = np.array([p.pixel for p in pixels])
    [123](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:123) order_map = orders.copy()
--> [124](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:124) fig, ax = plot_healpix_map(
    [125](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:125)     order_map, projection=projection, title=plot_title, ipix=ipix, depth=orders, cbar=False, **kwargs
    [126](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:126) )
    [127](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:127) col = ax.collections[0]
    [128](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:128) if color_by_order:

File ~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:529, in plot_healpix_map(healpix_map, projection, title, cmap, norm, ipix, depth, cbar, fov, center, wcs, frame_class, ax, fig, **kwargs)
    [516](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:516)     depth = np.full(len(healpix_map), fill_value=order)
    [518](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:518) fig, ax, wcs = initialize_wcs_axes(
    [519](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:519)     projection=projection,
    [520](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:520)     fov=fov,
   (...)
    [526](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:526)     figsize=(10, 5),
    [527](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:527) )
--> [529](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:529) _plot_healpix_value_map(ipix, depth, healpix_map, ax, wcs, cmap=cmap, norm=norm, cbar=cbar, **kwargs)
    [530](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:530) plt.grid()
    [531](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:531) plt.ylabel("Dec")

File ~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:629, in _plot_healpix_value_map(ipix, depth, values, ax, wcs, cmap, norm, cbar, **kwargs)
    [626](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:626)     depth_ipix_d[d] = (ipix[mask], values[mask])
    [628](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:628) # cull backfacing and out of fov cells
--> [629](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:629) fov_culled_d = cull_to_fov(depth_ipix_d, wcs)
    [630](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:630) culled_d = cull_from_pixel_map(fov_culled_d, wcs)
    [632](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:632) # Generate Paths for each pixel and add to ax

File ~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:272, in cull_to_fov(depth_ipix_d, wcs)
    [254](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:254) def cull_to_fov(depth_ipix_d: dict[int, tuple[np.ndarray, np.ndarray]], wcs):
    [255](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:255)     """Culls a mapping of ipix to values to pixels that are inside the plot window defined by a WCS
    [256](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:256) 
    [257](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:257)     Modified from mocpy.moc.plot.utils.build_plotting_moc
   (...)
    [269](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:269)         and any pixels too small merged with their map values subsampled.
    [270](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:270)     """
--> [272](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:272)     depth_ipix_d = _merge_too_small_pixels(depth_ipix_d, wcs)
    [274](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:274)     moc_viewport = get_fov_moc_from_wcs(wcs)
    [276](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:276)     if moc_viewport is None:

File ~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:305, in _merge_too_small_pixels(depth_ipix_d, wcs)
    [302](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:302) depth_res = int(np.floor(np.log2(np.sqrt(np.pi / 3) / cdelt)))
    [303](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:303) depth_res = max(depth_res, 0)
--> [305](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:305) max_depth = max(depth_ipix_d.keys())
    [307](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:307) # Combine healpix pixels smaller than 1px in the plot
    [308](https://file+.vscode-resource.vscode-cdn.net/home/delucchi/git/smoke/lsdb/~/git/smoke/hats/src/hats/inspection/visualize_catalog.py:308) if max_depth > depth_res:

Before submitting
Please check the following:

  • I have described the situation in which the bug arose, including what code was executed, information about my environment, and any applicable data others will need to reproduce the problem.
  • I have included available evidence of the unexpected behavior (including error messages, screenshots, and/or plots) as well as a description of what I expected instead.
  • If I have a solution in mind, I have provided an explanation and/or pseudocode and/or task list.
@delucchi-cmu delucchi-cmu added the bug Something isn't working label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

1 participant