You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Aperture mask plotting over large TPFs is very slow, because lightkurve loops over each masked pixel and use matplotlib Rectangle to highlight pixels. This happens here.
Thanks @astrobatty for pointing this out. The loop is really slowing things down in this case. Changing the function to
if aperture_mask is not None:
aperture_mask = self._parse_aperture_mask(aperture_mask)
in_aperture = np.where(aperture_mask)
if hasattr(ax, "wcs"):
ap_row = in_aperture[0] - 0.5
ap_col = in_aperture[1] - 0.5
else:
ap_row = in_aperture[0] + self.row - 0.5
ap_col = in_aperture[1] + self.column - 0.5
for ii in range(len(ap_row)):
rect=patches.Rectangle((ap_col[ii],ap_row[ii]),1,1, facecolor=none, hatch="//", edgecolor=mask_color)
ax.add_patch(rect)
speeds things up a lot (1min 24s ± 1.96 s per loop to 1.33 s ± 15.1 ms per loop for the original example). I'm testing this now, and will put in a PR if it looks good.
Problem description
Aperture mask plotting over large TPFs is very slow, because
lightkurve
loops over each masked pixel and usematplotlib Rectangle
to highlight pixels. This happens here.Example
Expected behavior
According to this Stack Overflow issue,
lightkurve
should usePolyCollection
instead ofRectangle
.Environment
The text was updated successfully, but these errors were encountered: