cds-astro / ipyaladin

An IPython Widget for Aladin Lite, the sky viewer.
https://cds-astro.github.io/ipyaladin/
BSD 3-Clause "New" or "Revised" License
126 stars 26 forks source link

Aladin widget does not show coordinates #61

Closed jpbrandtu closed 3 months ago

jpbrandtu commented 1 year ago

Hi,

I am using Aladin widget in Python to show SN coordinates, but it does not work properly (the symbol indicating the coordinates does not appear, even when I provide them in the add_table function). This is the code:

import pandas as pd
import numpy as np
from astropy.table import Table
from IPython.core.display import HTML
import ipyaladin as ipyal
from ipywidgets import Layout, Box, widgets

def start_aladin(survey="P/PanSTARRS/DR1/color-z-zg-g", layout_width=70, fov=0.025):
        aladin = ipyal.Aladin(survey=survey, layout=Layout(width='%s%%' % layout_width), fov=fov)
        info = widgets.HTML()
        box_layout = Layout(display='flex', flex_flow='row', align_items='stretch', width='100%')
        box = Box(children=[aladin, info], layout=box_layout)
        display(box)
        return aladin, info

# start aladin widget
aladin, info = start_aladin()

aladin.target = "%f %f" % (124.487612, 33.766332)

table_cand = Table.from_pandas(pd.DataFrame(data={"ZTF_oid": ["ZTF20aatwyzg"], "RA": [124.487612], "DEC": [33.766332], "cat_name": ["ZTF"]}))
aladin.add_table(table_cand)
display(info, aladin)

And this is the output:

Screen Shot 2023-06-01 at 17 38 33

ManonMarchand commented 1 year ago

Hello and thanks for opening this issue here :slightly_smiling_face:

The function add_table only works to modify an existing widget. It should be called after the cell containing ipyaladin and the table appears in the above cell. See here :

image

(I clicked on the point to highlight it)

Does this answer your question? Or did I get you wrong?

ManonMarchand commented 1 year ago

Hi, Is it ok with you if I close this issue? We will keep that in mind when writing the documentation :slightly_smiling_face:

ale-munozarancibia commented 1 year ago

Hi @ManonMarchand,

Thanks for the reply! Is it therefore mandatory to use functions like add_table in a separate cell? I ask because until recently (maybe a month ago) I was able to run code like this from a separate library (thus everything was in a single cell) but now such code works only sometimes. For instance, sometimes when I set the aladin.target the widget is updated to the object coordinates, but other times it seems to ignore the command and only shows coordinates (0,0). Same happens to me with add_table, sometimes it shows the symbols and others it doesn't. Did something change recently?

If it helps, I include the code versions I'm using:

astropy==5.2.2 astropy-healpix==0.6 ipyaladin==0.2.1 ipykernel==6.22.0 ipython==8.12.0 jupyter==1.0.0 jupyter-console==6.6.3

Thanks in advance!

ManonMarchand commented 1 year ago

Aaaah yes, indeed.

What we do internally is that we have a listener that adds the table to the widget when the boolean table_flag changes.

With this, it can happen that if you do everything in the same cell, the aladin view or the listener does not exist yet when the table is called. It seems to be a computer-dependent issue. A workaround is to call

aladin.table_flag = not aladin.table_flag 

in a next cell, but I'm aware that it does not solve your use case, very sorry :frowning:

Changing this behaviour requires some refactoring and won't be done right now (we're quite busy for the next 2 months) but I opened an issue for the v1 release #63

ale-munozarancibia commented 1 year ago

Thanks @ManonMarchand! I added some time.sleep(2)'s in between commands and that seems to help in my case

bmatthieu3 commented 6 months ago

Hi @jpbrandtu - we recently changed ipyaladin for using anywidget. We will test it to see if things are getting better (I suppose this is because aladin lite instanciation is done async and maybe anywidget fix those types of errors). To be further tested.