Skip to content

Commit

Permalink
Merge pull request #765 from astrofrog/speedup-wcs-links
Browse files Browse the repository at this point in the history
Significantly speed up operations that rely on WCS links
  • Loading branch information
pllim authored Aug 27, 2021
2 parents 9c0bdf9 + 5835780 commit 87bd85e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
6 changes: 3 additions & 3 deletions jdaviz/configs/imviz/plugins/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from glue.config import viewer_tool
from glue_jupyter.bqplot.common.tools import Tool
from glue.viewers.common.tool import CheckableTool
from glue.plugins.wcs_autolinking.wcs_autolinking import wcs_autolink, WCSLink
from glue.plugins.wcs_autolinking.wcs_autolinking import wcs_autolink, WCSLink, AffineLink
from glue_jupyter.bqplot.common.tools import BqplotPanZoomMode

__all__ = []
Expand Down Expand Up @@ -54,13 +54,13 @@ def activate(self):
for link in wcs_links:
exists = False
for existing_link in self.viewer.session.data_collection.external_links:
if isinstance(existing_link, WCSLink):
if isinstance(existing_link, (AffineLink, WCSLink)):
if (link.data1 is existing_link.data1
and link.data2 is existing_link.data2):
exists = True
break
if not exists:
self.viewer.session.data_collection.add_link(link)
self.viewer.session.data_collection.add_link(link.as_affine_link())

# Set the reference data in other viewers to be the same as the current viewer.
# If adding the data to the viewer, make sure it is not actually shown since the
Expand Down
20 changes: 6 additions & 14 deletions notebooks/ImvizExample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"from astropy.coordinates import SkyCoord, Angle\n",
"from astropy.table import Table\n",
"from astropy.utils.data import download_file\n",
"from glue.plugins.wcs_autolinking.wcs_autolinking import wcs_autolink, WCSLink\n",
"from glue.plugins.wcs_autolinking.wcs_autolinking import wcs_autolink\n",
"from photutils import CircularAperture, SkyCircularAperture\n",
"from regions import PixCoord, CirclePixelRegion, CircleSkyRegion\n",
"\n",
Expand Down Expand Up @@ -114,19 +114,11 @@
"viewer = imviz.app.get_viewer('viewer-1')\n",
"\n",
"# Manually link the data. We can remove this when Imviz auto-linking issue is resolved.\n",
"# This is necessary for blink to function properly.\n",
"# This is necessary for blink to function properly. We add affine approximations to the\n",
"# links instead of the full WCS links.\n",
"wcs_links = wcs_autolink(viewer.session.data_collection)\n",
"for link in wcs_links:\n",
" exists = False\n",
" for existing_link in viewer.session.data_collection.external_links:\n",
" if isinstance(existing_link, WCSLink):\n",
" if (link.data1 is existing_link.data1\n",
" and link.data2 is existing_link.data2):\n",
" exists = True\n",
" break\n",
" # Add only those links that don't already exist\n",
" if not exists:\n",
" viewer.session.data_collection.add_link(link)\n",
" viewer.session.data_collection.add_link(link.as_affine_link())\n",
"\n",
"# Because linking happens after load, the image display is broken a little.\n",
"# So, please do this manually **after** running this cell.\n",
Expand Down Expand Up @@ -582,7 +574,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -596,7 +588,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.9.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 87bd85e

Please sign in to comment.