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

Significantly speed up operations that rely on WCS links #765

Merged
merged 3 commits into from
Aug 27, 2021
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
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove WCSLink from import in the cell above too.

" 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