Skip to content
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
170 changes: 170 additions & 0 deletions examples/13_Export_Region_Selection.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
Comment thread
pcuste1 marked this conversation as resolved.
Comment thread
pcuste1 marked this conversation as resolved.
Comment thread
pcuste1 marked this conversation as resolved.
"cells": [
{
"cell_type": "markdown",
"id": "fb39c230",
"metadata": {},
"source": [
"# Export Region Selection\n",
"This notebook shows how you can export the region selections you have made within ipyaladin"
]
},
{
"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"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b377a777-af46-4af3-b874-94726a45acd5",
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "43c0c170",
"metadata": {},
"outputs": [],
"source": [
"aladin = Aladin(\n",
" survey=\"SDSS9 colored\",\n",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I realized that this isn't actually working since Aladin sets the HiPS survey using the unique ID (or URL) rather than the name of the survey displayed in the choices available in the UI. Since Aladin doesn't recognize the survey name, it just uses the default survey.

(I've added this issue to our new discussion page.)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

maybe we remove this from the example ipynb then too

" 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": [
"After that, select a region in the Aladin Lite widget (you can also trigger a selection with `right click` then `select sources`):"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f290b822",
"metadata": {},
"outputs": [],
"source": [
"aladin.selection(\"circle\")"
]
},
{
"cell_type": "markdown",
"id": "bc529c0a",
"metadata": {},
"source": [
"You can then access the list of selections made as astropy regions"
]
},
{
"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": "d3835c52",
"metadata": {},
"source": [
"and access the list of graphic overlays drawn this way"
]
},
{
"cell_type": "markdown",
"id": "3fc74ebf-1d21-4cf1-818d-03ce4d79e58f",
"metadata": {},
"source": [
"### Reselect an old selected region\n",
"We can revisit the selected regions and trigger a new selection by passing one of them in. For this example, lets re-select our first selection."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b024622e-cbb0-424a-8ae0-db939c3ca317",
"metadata": {},
"outputs": [],
"source": [
"aladin.select_region(aladin.selected_regions[0])"
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
8 changes: 8 additions & 0 deletions js/models/event_handler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import MessageHandler from "./message_handler";
import { divNumber, setDivNumber, Lock, setDivHeight } from "../utils";
import { SelectorToJson } from "./selection_handler";

export default class EventHandler {
/**
Expand Down Expand Up @@ -244,6 +245,12 @@ export default class EventHandler {
event_type: "select",
content: objectsData,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

revisit with further discussion

this.model.set("_selected_regions", [
...(this.model.get("_selected_regions") ?? []),
SelectorToJson(this.aladin),
]);
this.model.save_changes();
});

/* Aladin functionalities */
Expand Down Expand Up @@ -279,6 +286,7 @@ export default class EventHandler {
change_colormap: this.messageHandler.handleChangeColormap,
get_JPG_thumbnail: this.messageHandler.handleGetJPGThumbnail,
trigger_selection: this.messageHandler.handleTriggerSelection,
trigger_select_region: this.messageHandler.handleTriggerSelectRegion,
add_table: this.messageHandler.handleAddTable,
};

Expand Down
5 changes: 5 additions & 0 deletions js/models/message_handler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { convertOptionNamesToCamelCase } from "../utils";
import { SelectRegion } from "./selection_handler";
import A from "../aladin_lite";

let imageCount = 0;
Expand Down Expand Up @@ -155,6 +156,10 @@ export default class MessageHandler {
this.aladin.select(selectionType);
}

handleTriggerSelectRegion(msg) {
SelectRegion(msg, this.aladin);
}

handleAddTable(msg, buffers) {
const options = convertOptionNamesToCamelCase(msg["options"] || {});
const buffer = buffers[0].buffer;
Expand Down
Loading
Loading