Skip to content

Commit

Permalink
✨ Mark add_overlay_from_stcs as deprecated
Browse files Browse the repository at this point in the history
Fix typing and optional regions dependency
  • Loading branch information
Xen0Xys committed May 14, 2024
1 parent f9ee0e4 commit c9eff43
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
1 change: 0 additions & 1 deletion js/models/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ export default class EventHandler {
add_MOC_from_URL: this.messageHandler.handleAddMOCFromURL,
add_MOC_from_dict: this.messageHandler.handleAddMOCFromDict,
add_overlay: this.messageHandler.handleAddOverlay,
add_overlay_from_stcs: this.messageHandler.handleAddOverlayFromSTCS,
change_colormap: this.messageHandler.handleChangeColormap,
get_JPG_thumbnail: this.messageHandler.handleGetJPGThumbnail,
trigger_rectangular_selection:
Expand Down
17 changes: 4 additions & 13 deletions js/models/message_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,25 @@ export default class MessageHandler {
const infos = msg["infos"];
const options = convertOptionNamesToCamelCase(msg["options"] || {});
const overlay = A.graphicOverlay(options);
this.aladin.addOverlay(overlay);
switch (msg["region_type"]) {
case "stcs":
overlay.addFootprints(A.footprintsFromSTCS(infos.stcs));
break;
case "circle":
this.aladin.addOverlay(overlay);
overlay.add(A.circle(infos.ra, infos.dec, infos.radius));
break;
case "ellipse":
this.aladin.addOverlay(overlay);
overlay.add(
A.ellipse(infos.ra, infos.dec, infos.a, infos.b, infos.theta),
);
break;
case "line":
this.aladin.addOverlay(overlay);
overlay.add(A.line(infos.ra1, infos.dec1, infos.ra2, infos.dec2));
break;
}
}

handleAddOverlayFromSTCS(msg) {
const overlayOptions = convertOptionNamesToCamelCase(
msg["overlay_options"] || {},
);
const stcString = msg["stc_string"];
const overlay = A.graphicOverlay(overlayOptions);
this.aladin.addOverlay(overlay);
overlay.addFootprints(A.footprintsFromSTCS(stcString));
}

handleChangeColormap(msg) {
this.aladin.getBaseImageLayer().setColormap(msg["colormap"]);
}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ requires-python = ">=3.8"

[project.optional-dependencies]
dev = ["pytest", "watchfiles", "jupyterlab", "ruff"]
recommended = ["mocpy"]
recommended = ["mocpy", "regions"]

# automatically add the dev feature to the default env (e.g., hatch shell)
[tool.hatch.envs.default]
Expand Down
33 changes: 23 additions & 10 deletions src/ipyaladin/aladin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
from astropy.table import Table
from astropy.coordinates import SkyCoord, Angle
import traitlets
from regions import CircleSkyRegion, EllipseSkyRegion, LineSkyRegion

try:
from regions import CircleSkyRegion, EllipseSkyRegion, LineSkyRegion
except ImportError:
CircleSkyRegion = None
EllipseSkyRegion = None
LineSkyRegion = None
from traitlets import (
Float,
Int,
Expand Down Expand Up @@ -352,13 +358,22 @@ def add_overlay(
overlay_options: keyword arguments
"""
if not isinstance(region, str) and (
CircleSkyRegion is None or EllipseSkyRegion is None or LineSkyRegion is None
):
raise ValueError(
"A region can be given as an STC-S string or a regions "
"object. To read regions objects, you need to install the regions "
"library with 'pip install regions'."
)

region_type = ""
infos = {}

if isinstance(region, str):
self.add_overlay_from_stcs(region, **overlay_options)
return
if isinstance(region, CircleSkyRegion):
region_type = "stcs"
infos = {"stcs": region}
elif isinstance(region, CircleSkyRegion):
region_type = "circle"
infos = {
"ra": region.center.ra.deg,
Expand Down Expand Up @@ -402,13 +417,11 @@ def add_overlay_from_stcs(self, stc_string: str, **overlay_options: any) -> None
overlay_options: keyword arguments
"""
self.send(
{
"event_name": "add_overlay_from_stcs",
"stc_string": stc_string,
"overlay_options": overlay_options,
}
# Add deprecation warning
warnings.warn(
"add_overlay_from_stcs is deprecated, use add_overlay instead", stacklevel=2
)
self.add_overlay(stc_string, **overlay_options)

def get_JPEG_thumbnail(self) -> None:
"""Create a popup window with the current Aladin view."""
Expand Down

0 comments on commit c9eff43

Please sign in to comment.