forked from cds-astro/ipyaladin
-
Notifications
You must be signed in to change notification settings - Fork 0
Export selection and drawn regions as astropy regions #1
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
Draft
pcuste1
wants to merge
22
commits into
dev
Choose a base branch
from
CST-180
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ed743c2
add export region selection functionality
pcuste1 74fff24
add export selection
pcuste1 a88fdfe
export list of region selections
pcuste1 cdf9957
export regions drawn to aladin-lite
pcuste1 3493ccb
add export region selection functionality
pcuste1 39828a4
add export selection
pcuste1 a3f0cc1
export list of region selections
pcuste1 06bd9ab
export regions drawn to aladin-lite
pcuste1 74c7e8b
add polygon selection
pcuste1 f2895f8
Merge branch 'CST-180' of github.com:pcuste1/ipyaladin into CST-180
pcuste1 aa9a157
add comments to notebook
pcuste1 f2b441b
change `graphic_regions_list` to `graphic_overlays`
pcuste1 2687f10
remove unused cell
pcuste1 720ecc9
add comments to selection handler
pcuste1 45fec7c
update comments in selection handler
pcuste1 a53307c
add the ability to import a astropy region as a selection
pcuste1 1633a37
x and y to ra and dec where appropriate
pcuste1 44aa05d
remove console log
pcuste1 3bd67c0
account for spherical coordinate issues with circle and rect
pcuste1 89f69e7
calculate radius with pixel coordinates, not world
pcuste1 8df4537
update the notebook per review comments
pcuste1 6873b7e
update comment per review
pcuste1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "fb39c230", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Programatic Region Selection\n", | ||
| "This notebook shows how you can select all of the sources within an astropy region as a selection, export the selection region, and draw a graphic overlay of the exported region." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "72180ae5-f9ec-4355-9497-200439da187b", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from ipyaladin import Aladin\n", | ||
| "\n", | ||
| "from astropy.coordinates import SkyCoord\n", | ||
| "from astroquery.mast import Catalogs\n", | ||
| "\n", | ||
| "from regions import CircleSkyRegion\n", | ||
| "from astropy import units as u" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "43c0c170", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "aladin = Aladin(\n", | ||
| " show_coo_grid=True,\n", | ||
| " target=\"TRAPPIST-1\",\n", | ||
| " coo_frame=\"icrs\",\n", | ||
| " fov=0.05,\n", | ||
| " height=400,\n", | ||
| " samp=True,\n", | ||
| ")\n", | ||
| "aladin" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "30b5ab5a", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Extract region selections\n", | ||
| "First, load a custom catalog that will provide the sources to select from" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "e1dc08de", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "target_name = \"TRAPPIST-1\"\n", | ||
| "catalog_data = Catalogs.query_region(\n", | ||
| " coordinates=SkyCoord.from_name(target_name),\n", | ||
| " radius=0.01, # [deg]\n", | ||
| " catalog=\"Panstarrs\",\n", | ||
| ")\n", | ||
| "catalog_data.rename_columns([\"raMean\", \"decMean\"], [\"ra\", \"dec\"])\n", | ||
| "\n", | ||
| "aladin.add_table(\n", | ||
| " catalog_data, name=\"test-table\", color=\"lime\", shape=\"circle\", source_size=10\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "018d9426", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Import a selection region\n", | ||
| "We then define a region to select within the aladin viewer" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "f290b822", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "selection_region = CircleSkyRegion(SkyCoord.from_name(target_name), radius=0.01 * u.deg)\n", | ||
| "aladin.select_region(selection_region)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "5e1450cb-4d6e-440f-b72c-97d8a20127a6", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Note: Aladin also supports selections from `RectangleSkyRegions` and `PolygonSkyRegions`" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "bc529c0a", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Export a selection region\n", | ||
| "The list of selection made in the aladin viewer is made available through a property on the aladin instance" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "89624109", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "aladin.selected_regions" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "4c5f9ed8", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Display the selected regions as graphic overlays \n", | ||
| "You can then display those selected regions as graphic overlays" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "a95e51c7", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "aladin.add_graphic_overlay_from_region(aladin.selected_regions)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "267eec63-a782-4ecd-b944-5be61e484cb1", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "The list of graphic overlays drawn is available through a property on the aladin instance" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "43b6c363-7d6d-49ac-99b9-86b5270ea41a", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "aladin.graphic_overlays" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "ab82cfb5-cc72-402a-b7e0-5844d49b82a4", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [] | ||
| } | ||
| ], | ||
| "metadata": {}, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revisit with further discussion