Use of functions on ipyaladin widgets#
[1]:
from ipyaladin import Aladin
Home-made functions#
Let’s first write our own functions to apply to a generated sky view. We want to print the clicked object coordinates and informations.
[2]:
aladin = Aladin(
survey="P/DSS2/red",
fov=10,
target="LMC",
reticle_color="#ff89ff",
show_status_bar=True,
)
aladin
[2]:
[3]:
url = (
"https://vizier.unistra.fr/viz-bin/votable?-source=HIP2&-c=LMC&-out.add=_RAJ,_"
"DEJ&-oc.form=dm&-out.meta=DhuL&-out.max=9999&-c.rm=180"
)
options = {"source_size": 12, "color": "#f08080", "on_click": "showTable"}
aladin.add_catalog_from_URL(url, options)
After clicking on a source, you can print its value with:
[4]:
aladin.clicked_object
[4]:
{}
[5]:
def get_object_data(data: dict) -> dict:
"""Print the clicked object data.
Parameters
----------
data : dict
The data of the clicked object.
"""
print("It clicked.")
return data
def get_object_ra_dec_product(data: dict) -> float:
"""Return the product of the ra and dec values of the clicked object.
Parameters
----------
data : dict
The data of the clicked object.
"""
return data["ra"] * data["dec"]
# when triggered, the listeners on the js side of the application will send a
# json object whose parameter data will be used by the python functions
# (data is a literal object on the js side, it will be converted as a dictionary
# object on the python side)
aladin.set_listener("object_hovered", get_object_ra_dec_product)
aladin.set_listener("object_clicked", get_object_data)
Built-in methods#
The Aladin
object also comes with its built-in methods. Here we illustrate one of them.
[6]:
aladin_bis = Aladin(target="269.956288 -23.823863", fov=1)
aladin_bis
[6]:
[7]:
aladin_bis.set_color_map("redtemperature")
[8]:
help(aladin_bis.get_JPEG_thumbnail)
Help on method get_JPEG_thumbnail in module ipyaladin.widget:
get_JPEG_thumbnail() -> None method of ipyaladin.widget.Aladin instance
Create a popup window with the current Aladin view.
This method will only work if you are running a notebook in a browser (for
example, it won't do anything in VSCode).
[9]:
aladin_bis.get_JPEG_thumbnail()
Check that your browser didn’t block the popup window if you don’t see the thumbnail. This will not work in VSCode or other notebooks editors that are not working in a browser.