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

Allow for empty path_vertices #129

Merged
merged 2 commits into from
May 28, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

### Fixed

* `MOC.border` no does not attempt on plotting the border when the MOc is out of the
view anymore.

### Added

* `MOC.sum_in_multiordermap` takes an astropy table with a `UNIQ` column and
Expand Down
31 changes: 14 additions & 17 deletions python/mocpy/moc/plot/border.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import cdshealpix
import numpy as np

from astropy.coordinates import ICRS, SkyCoord

from astropy.wcs.utils import skycoord_to_pixel

from matplotlib.path import Path
from matplotlib.patches import PathPatch

import cdshealpix

from matplotlib.path import Path


def border(moc, ax, wcs, **kw_mpl_pathpatch):
"""Highlight the borders of a MOC in a plot."""
from .utils import build_plotting_moc, _set_wcs
from .utils import _set_wcs, build_plotting_moc

moc_to_plot = build_plotting_moc(moc, wcs)

Expand Down Expand Up @@ -55,7 +50,8 @@ def border(moc, ax, wcs, **kw_mpl_pathpatch):
ipixels_border = ipixels_open[ipixels_border_id]

ipix_lon_boundaries, ipix_lat_boundaries = cdshealpix.vertices(
ipixels_border, max_order,
ipixels_border,
max_order,
)
ipix_boundaries = SkyCoord(ipix_lon_boundaries, ipix_lat_boundaries, frame=ICRS())

Expand All @@ -75,22 +71,23 @@ def border(moc, ax, wcs, **kw_mpl_pathpatch):
vy = yp[i]
if not north_border[i]:
path_vertices_l += [(vx[0], vy[0]), (vx[1], vy[1]), (0, 0)]
codes += [Path.MOVETO] + [Path.LINETO] + [Path.CLOSEPOLY]
codes += [Path.MOVETO, Path.LINETO, Path.CLOSEPOLY]

if not east_border[i]:
path_vertices_l += [(vx[1], vy[1]), (vx[2], vy[2]), (0, 0)]
codes += [Path.MOVETO] + [Path.LINETO] + [Path.CLOSEPOLY]
codes += [Path.MOVETO, Path.LINETO, Path.CLOSEPOLY]

if not south_border[i]:
path_vertices_l += [(vx[2], vy[2]), (vx[3], vy[3]), (0, 0)]
codes += [Path.MOVETO] + [Path.LINETO] + [Path.CLOSEPOLY]
codes += [Path.MOVETO, Path.LINETO, Path.CLOSEPOLY]

if not west_border[i]:
path_vertices_l += [(vx[3], vy[3]), (vx[0], vy[0]), (0, 0)]
codes += [Path.MOVETO] + [Path.LINETO] + [Path.CLOSEPOLY]
codes += [Path.MOVETO, Path.LINETO, Path.CLOSEPOLY]

path = Path(path_vertices_l, codes)
perimeter_patch = PathPatch(path, **kw_mpl_pathpatch)
if len(path_vertices_l) > 0:
path = Path(path_vertices_l, codes)
perimeter_patch = PathPatch(path, **kw_mpl_pathpatch)

ax.add_patch(perimeter_patch)
_set_wcs(ax, wcs)
ax.add_patch(perimeter_patch)
_set_wcs(ax, wcs)
Loading