Skip to content

Commit

Permalink
✨ Implement WCS and 2 axis FoV recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jul 15, 2024
1 parent e99e599 commit cbb375e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
7 changes: 7 additions & 0 deletions js/models/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class EventHandler {
}
jsTargetLock.lock();
const raDec = [position.ra, position.dec];
this.model.set("_wcs", this.aladin.getViewWCS());
this.model.set("_target", `${raDec[0]} ${raDec[1]}`);
this.model.save_changes();
});
Expand All @@ -68,7 +69,13 @@ export default class EventHandler {
}
jsFovLock.lock();
// fov MUST be cast into float in order to be sent to the model
this.model.set("_wcs", this.aladin.getViewWCS());
this.model.set("_fov", parseFloat(fov.toFixed(5)));
const fov_xy = this.aladin.getFov();
this.model.set("_fov_xy", {
x: fov_xy[0],
y: fov_xy[1],
});
this.model.save_changes();
});

Expand Down
9 changes: 9 additions & 0 deletions js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ function initAladinLite(model, el) {
const raDec = initOptions["target"].split(" ");
aladin.gotoRaDec(raDec[0], raDec[1]);

// Set current FoV and WCS
const FoV = aladin.getFov();
model.set("_fov_xy", {
x: FoV[0],
y: FoV[1],
});
model.set("_wcs", aladin.getViewWCS());
model.save_changes();

el.appendChild(aladinDiv);
return { aladin, aladinDiv };
}
Expand Down
36 changes: 35 additions & 1 deletion src/ipyaladin/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import pathlib
import typing
from typing import ClassVar, Union, Final, Optional
from typing import ClassVar, Union, Final, Optional, Tuple
import warnings

import anywidget
from astropy.table.table import QTable
from astropy.table import Table
from astropy.coordinates import SkyCoord, Angle
import traitlets
from astropy.wcs import WCS

try:
from regions import (
Expand Down Expand Up @@ -122,6 +123,10 @@ class Aladin(anywidget.AnyWidget):
grid_opacity = Float(0.5).tag(sync=True, init_option=True)
grid_options = traitlets.Dict().tag(sync=True, init_option=True)

# Values
_wcs = traitlets.Dict().tag(sync=True)
_fov_xy = traitlets.Dict().tag(sync=True)

# content of the last click
clicked_object = traitlets.Dict().tag(sync=True)
# listener callback is on the python side and contains functions to link to events
Expand Down Expand Up @@ -161,6 +166,35 @@ def _handle_custom_message(self, _: any, message: dict, __: any) -> None:
elif event_type == "select" and "select" in self.listener_callback:
self.listener_callback["select"](message_content)

@property
def wcs(self) -> WCS:
"""The world coordinate system of the Aladin Lite widget.
Returns
-------
WCS
An astropy WCS object representing the world coordinate system.
"""
if "RADECSYS" in self._wcs: # RADECSYS keyword is deprecated for astropy.WCS
self._wcs["RADESYS"] = self._wcs.pop("RADECSYS")
return WCS(self._wcs)

@property
def fov_xy(self) -> Tuple[Angle, Angle]:
"""The field of view of the Aladin Lite along the two axis.
Returns
-------
tuple[Angle, Angle]
A tuple of astropy.units.Angle objects representing the field of view.
"""
return (
Angle(self._fov_xy["x"], unit="deg"),
Angle(self._fov_xy["y"], unit="deg"),
)

@property
def fov(self) -> Angle:
"""The field of view of the Aladin Lite widget along the horizontal axis.
Expand Down

0 comments on commit cbb375e

Please sign in to comment.