{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example of interactive rectangular selection\n", "\n", "Once all the cells below have been executed, you will be able to press the _Select_ button, drag a rectangle enclosing the sources you wish to select and see their names in the table at the right of the ipyaladin view.\n", "\n", "![ipyaladin example](gifs/demo-select-button.gif)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipyaladin import Aladin\n", "from ipywidgets import Layout, Box, widgets\n", "\n", "from astroquery.simbad import Simbad\n", "import astropy.units as u\n", "\n", "aladin = Aladin(\n", " layout=Layout(width=\"50%\"),\n", " target=\"M 1\",\n", " fov=0.2,\n", " show_projection_control=False,\n", " show_fullscreen_control=False,\n", ")\n", "button = widgets.Button(description=\"Select\")\n", "\n", "\n", "def on_button_clicked(_: any) -> None:\n", " \"\"\"Button click event callback.\n", "\n", " It will trigger the rectangular selection in the Aladin widget.\n", "\n", " Parameters\n", " ----------\n", " _: any\n", " The button widget that triggered the event.\n", " \"\"\"\n", " aladin.rectangular_selection()\n", "\n", "\n", "button.on_click(on_button_clicked)\n", "table_info = widgets.HTML(layout=Layout(height=\"auto\", overflow=\"auto\"))\n", "\n", "box_layout = Layout(\n", " display=\"flex\",\n", " flex_flow=\"row\",\n", " align_items=\"stretch\",\n", " width=\"100%\",\n", " position=\"relative\",\n", ")\n", "box = Box(children=[aladin, button, table_info], layout=box_layout)\n", "box" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table = Simbad.query_region(\"M 1\", radius=0.1 * u.deg)\n", "aladin.add_table(table)\n", "\n", "\n", "def process_result(sources: dict) -> None:\n", " \"\"\"Process the sources selected in the Aladin widget and display them in the table.\n", "\n", " Parameters\n", " ----------\n", " sources: dict\n", " The sources selected in the Aladin widget.\n", " \"\"\"\n", " s = '
MAIN_ID | RA | DEC |
---|---|---|
%s | %s | %s |