Spaces:
Sleeping
Sleeping
"""# 🛸 On Click Callback | |
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. | |
Powered by \ | |
[ipyaladin](https://github.com/cds-astro/ipyaladin) and \ | |
[Panel](https://panel.holoviz.org/index.html). | |
Check out the [**App Gallery**](./) | |
""" | |
import panel as pn | |
import requests | |
from ipyaladin import Aladin | |
from ipywidgets import Layout | |
pn.extension("ipywidgets", sizing_mode="stretch_width") | |
LoadingIndicator = "Loading..." | |
aladin = Aladin( | |
layout=Layout(width="100%"), | |
height=800, | |
target="M 36", | |
fov=0.3, | |
show_fullscreen_control=False, | |
) | |
info = pn.pane.HTML("<h2>Click the widget</h2>") | |
image = pn.pane.PNG(embed=True, sizing_mode="fixed") | |
box = pn.Column(aladin, info, image) | |
def process_result(data: dict) -> None: | |
"""Process the result of a click event on the Aladin widget. | |
Parameters | |
---------- | |
data : dict | |
The data returned by the click event. | |
""" | |
box.loading = True | |
info.value = "" | |
ra = data["ra"] | |
dec = data["dec"] | |
query = ( | |
f"SELECT TOP 1 main_id, ra, dec, DISTANCE(POINT('ICRS', {ra}, {dec}), " | |
f"POINT('ICRS', ra, dec)) as d FROM basic " | |
f"WHERE CONTAINS(POINT('ICRS', ra, dec), CIRCLE('ICRS', {ra}, {dec}, {aladin.fov.deg / 10}))=1 " | |
"ORDER BY d ASC" | |
) | |
r = requests.get( | |
"http://simbad.u-strasbg.fr/simbad/sim-tap/sync", | |
params={ | |
"query": query, | |
"request": "doQuery", | |
"lang": "adql", | |
"format": "json", | |
"phase": "run", | |
}, | |
) | |
obj_name = "" | |
obj_coo = None | |
obj_data = r.json()["data"] | |
if len(obj_data) == 0: | |
return | |
obj_name = obj_data[0][0] | |
obj_coo = [obj_data[0][1], obj_data[0][2]] | |
info.object = f"<h2>{obj_name}</h2><br><br>" | |
image.object = f"https://cdsportal.u-strasbg.fr/cgi-bin/PhotVizPreview/plot?ra={obj_coo[0]}&dec={obj_coo[1]}&radius_arcsec=5&w=200&h=150&point_size=4" | |
box.loading = False | |
aladin.set_listener("click", process_result) | |
pn.template.FastListTemplate( | |
site="ipyaladin and Panel", | |
site_url="./", | |
title="On Click Callback", | |
sidebar=[ | |
pn.pane.PNG( | |
"https://avatars.githubusercontent.com/u/26145382?s=200&v=4", | |
link_url="https://cds.unistra.fr/", | |
), | |
__doc__, | |
], | |
main=[box], | |
accent="#296bb5", | |
main_layout=None, | |
).servable() | |