Skip to content

Commit

Permalink
✨ Implement oriented ellipse error type in add_table method
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Aug 7, 2024
1 parent 8612e25 commit 84ff138
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
15 changes: 14 additions & 1 deletion js/models/message_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,26 @@ export default class MessageHandler {

handleAddTable(msg, buffers) {
const options = convertOptionNamesToCamelCase(msg["options"] || {});
const errorDict = options.errorDict;
const buffer = buffers[0].buffer;
const decoder = new TextDecoder("utf-8");
const blob = new Blob([decoder.decode(buffer)]);
const url = URL.createObjectURL(blob);
options.onClick = "showTable";
if (errorDict)
options.shape = (s) => {
if (errorDict["pa"] && s.data[errorDict["pa"]["col"]])
return A.ellipse(
s.ra,
s.dec,
s.data[errorDict["smaj"]["col"]],
s.data[errorDict["smin"]["col"]],
s.data[errorDict["pa"]["col"]],
);
};
A.catalogFromURL(
url,
Object.assign(options, { onClick: "showTable" }),
options,
(catalog) => {
this.aladin.addCatalog(catalog);
},
Expand Down
24 changes: 24 additions & 0 deletions src/ipyaladin/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from astropy.table import Table
from astropy.io import fits as astropy_fits
from astropy.io.fits import HDUList
import astropy.units as u
from astropy.units import Unit
from astropy.wcs import WCS
import numpy as np
import traitlets
Expand Down Expand Up @@ -633,6 +635,23 @@ def add_moc_from_dict(
moc_options = {}
self.add_moc(moc_dict, **moc_options)

def _convert_table_units(
self, table: Union[QTable, Table], error_dict: Dict, unit_to: Unit = u.deg
) -> Union[QTable, Table]:
table = table.copy()
for _, error_spec in error_dict.values():
col_name = error_spec["col"]
unit_from = error_spec["unit"]
table[col_name].unit = unit_from
for row in table:
if row[col_name] != "--" and not np.isnan(row[col_name]):
row[col_name] = (
Angle(row[col_name], unit=unit_from).to(unit_to).value
)
table[col_name].unit = unit_to

return table

def add_table(self, table: Union[QTable, Table], **table_options: any) -> None:
"""Load a table into the widget.
Expand All @@ -646,6 +665,11 @@ def add_table(self, table: Union[QTable, Table], **table_options: any) -> None:
<https://cds-astro.github.io/aladin-lite/global.html#CatalogOptions>`_
"""
if table_options.get("error_dict"):
table = self._convert_table_units(table, table_options["error_dict"])
# remove unit sub-key for all the keys
for key in table_options["error_dict"]:
table_options["error_dict"][key].pop("unit")
table_bytes = io.BytesIO()
table.write(table_bytes, format="votable")
self.send(
Expand Down

0 comments on commit 84ff138

Please sign in to comment.