{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# On click callback\n", "\n", "Once all cells are executed, click anywhere to get the closest star name. Be patient and the associated photometric points appear after a few seconds." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipyaladin import Aladin\n", "import requests\n", "from ipywidgets import Layout, Box, widgets\n", "\n", "aladin = Aladin(layout=Layout(width=\"70%\"), target=\"M 36\", fov=0.3)\n", "info = widgets.HTML()\n", "\n", "\n", "box_layout = Layout(\n", " display=\"flex\", flex_flow=\"row\", align_items=\"stretch\", width=\"100%\"\n", ")\n", "box = Box(children=[aladin, info], layout=box_layout)\n", "box" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def process_result(data: dict) -> None:\n", " \"\"\"Process the result of a click event on the Aladin widget.\n", "\n", " Parameters\n", " ----------\n", " data : dict\n", " The data returned by the click event.\n", " \"\"\"\n", " info.value = \"\"\n", " ra = data[\"ra\"]\n", " dec = data[\"dec\"]\n", " query = \"\"\"SELECT TOP 1 main_id, ra, dec, DISTANCE(POINT('ICRS', %f, %f),\n", " POINT('ICRS', ra, dec)) as d FROM basic\n", " WHERE CONTAINS(POINT('ICRS', ra, dec), CIRCLE('ICRS', %f, %f, %f))=1\n", " ORDER BY d ASC\"\"\" % (\n", " ra,\n", " dec,\n", " ra,\n", " dec,\n", " aladin.fov.deg / 10,\n", " )\n", "\n", " r = requests.get(\n", " \"http://simbad.u-strasbg.fr/simbad/sim-tap/sync\",\n", " params={\n", " \"query\": query,\n", " \"request\": \"doQuery\",\n", " \"lang\": \"adql\",\n", " \"format\": \"json\",\n", " \"phase\": \"run\",\n", " },\n", " )\n", " obj_name = \"\"\n", " obj_coo = None\n", " obj_data = r.json()[\"data\"]\n", " if len(obj_data) == 0:\n", " return\n", "\n", " obj_name = obj_data[0][0]\n", " obj_coo = [obj_data[0][1], obj_data[0][2]]\n", "\n", " sed_img = (\n", " ''\n", " % (obj_coo[0], obj_coo[1])\n", " )\n", " info.value = \"

%s



%s\" % (obj_name, sed_img)\n", "\n", "\n", "aladin.set_listener(\"click\", process_result)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3" }, "vscode": { "interpreter": { "hash": "85bb43f988bdbdc027a50b6d744a62eda8a76617af1f4f9b115d38242716dbac" } } }, "nbformat": 4, "nbformat_minor": 4 }