Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add overlays immediately after creating an Aladin instance, before displaying it? #128

Open
mperrin opened this issue Oct 25, 2024 · 1 comment

Comments

@mperrin
Copy link

mperrin commented Oct 25, 2024

I would like to know if there's a way to add annotations (catalogs, fits images, etc) to an Aladin instance immediately after creating it, with code in the same Jupyter cell. For instance I would like to be able to write a function which creates an Aladin instance and adds various things into it right away. Right now this appears only possible if the code is split across different Jupyter cells? Am I missing some way of doing this, please?

Using one of the examples from the docs, it works to have two separate cells containing this code:
In[1]:

aladin = Aladin(
    survey="P/DSS2/red",
    fov=10,
    target="LMC",
    reticle_color="#ff89ff",
    show_status_bar=True,
)
aladin

In[2]:

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)

On the other hand it does not work to combine those steps in a single cell:

In[3]:

aladin = Aladin(
    survey="P/DSS2/red",
    fov=10,
    target="LMC",
    reticle_color="#ff89ff",
    show_status_bar=True,
)
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)
aladin

The catalog is silently dropped and is not displayed, even after triggering display refresh by clicking on the widget, etc.

I see the function widget_should_be_loaded added in recent PR #107, but am not getting any wait behavior from that; the cell runs immediately without any 1 second pause to load the widget. I'm running on the latest ipyaladin 0.5.1.

Is there some way to trigger the readying of the widgets programmatically, prior to adding catalogs or other image annotations? Thanks much for any help and guidance!

@ManonMarchand
Copy link
Member

Hello,

Thanks for the detailed description.

Short answer:

No, it's not supported yet.

Long answer:

We have some limitations due to what widget can do and how they work. We are really trying to overcome them but it is a long standing issue in the jupyter widget community (see jupyter-widgets/ipywidgets#3039).

It's in our plans, but all the solutions we tested so far were not satisfying.

About widget should be loaded

This is a different issue (also related to this impossibility to wait for something to be finished in the notebook) that was solved there. There is a small time to load the code for the widget when it is displayed. If the two cells (the one displaying the widget and the one adding the table) are executed one after the other too fast without waiting for that time, then the catalog is still not added. So this concerns operations between two different cells.

Hope this answers the question?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants