Skip to content

Commit

Permalink
feat: export selection as list of astropy Tables
Browse files Browse the repository at this point in the history
* feat: Table selection and export

* 💚 Add notebook dependencies to playwright CI

* 📝 Update example 11 with new selection feature

* ✅ Fix example 11 testing

* 📝 Remove usage of Aladin#rectangular_selection in examples

* ci: make playwright only run on demmand

* fix: remove unused import and message handler

* docs: edit example to have two different catalogs
  • Loading branch information
Xen0Xys authored Jul 25, 2024
1 parent ac52603 commit 235a77c
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 113 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/js-tests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Playwright Tests
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:
jobs:
test:
timeout-minutes: 60
Expand All @@ -19,7 +16,7 @@ jobs:
- name: Install dependencies
run: |
npm install
python -m pip install .
python -m pip install .[recommended,notebooks]
python -m pip install jupyterlab
npx playwright install
- name: Install Playwright Browser
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow WCS and 2 axis FoV recovery from `wcs` and `fov_xy` properties (#96)
- monochromatic FITS images can be added to the view with `ipyaladin.Aladin.add_fits`.
The method accepts `astropy.io.fits.HDUList`, `pathlib.Path`, or `string` representing paths (#86)
- New way to make a selection on the view with `selection` method (#100)
- Add selected sources export as `astropy.Table` list with property `selected_objects` (#100)

### Deprecated

- Deprecate `rectangular_selection` method in favor of `selection` method (#100)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion examples/08_Rectangular-selection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
" _: any\n",
" The button widget that triggered the event.\n",
" \"\"\"\n",
" aladin.rectangular_selection()\n",
" aladin.selection(\"rectangle\")\n",
"\n",
"\n",
"button.on_click(on_button_clicked)\n",
Expand Down
218 changes: 138 additions & 80 deletions examples/11_Extracting_information_from_the_view.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,35 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "initial_id",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-24T07:31:43.806466Z",
"start_time": "2024-07-24T07:31:43.804047Z"
}
},
"outputs": [],
"source": [
"from astropy.coordinates import SkyCoord\n",
"import astropy.units as u\n",
"from astroquery.simbad import Simbad\n",
"from astroquery.vizier import Vizier\n",
"\n",
"from ipyaladin import Aladin"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "2e62d34eb8543145",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "68df3ccd903340b4aa8af8aad92c0c20",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"Aladin(init_options=['_fov', '_height', '_target', 'background_color', 'coo_frame', 'full_screen', 'grid_color…"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-24T07:31:44.595633Z",
"start_time": "2024-07-24T07:31:44.580516Z"
}
],
},
"outputs": [],
"source": [
"aladin = Aladin(fov=5, height=600, target=\"M31\")\n",
"aladin"
Expand All @@ -62,30 +61,15 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "84153657cb7cd837",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"WCS Keywords\n",
"\n",
"Number of WCS axes: 2\n",
"CTYPE : 'RA---SIN' 'DEC--SIN' \n",
"CRVAL : 10.6847083 41.26875 \n",
"CRPIX : 843.0 300.5 \n",
"PC1_1 PC1_2 : 1.0 0.0 \n",
"PC2_1 PC2_2 : 0.0 1.0 \n",
"CDELT : -0.0029673590504451 0.002967359050445104 \n",
"NAXIS : 1685 600"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-24T07:31:46.921817Z",
"start_time": "2024-07-24T07:31:46.915120Z"
}
],
},
"outputs": [],
"source": [
"aladin.wcs # Recover the current WCS"
]
Expand All @@ -100,9 +84,14 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "a63f210b-3a64-4860-8e70-42a4c66378fa",
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-24T07:31:48.369339Z",
"start_time": "2024-07-24T07:31:48.361272Z"
}
},
"outputs": [],
"source": [
"aladin.height = 800\n",
Expand All @@ -122,30 +111,15 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "2ddc9637-b5c3-4412-8435-2302b6d86816",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"WCS Keywords\n",
"\n",
"Number of WCS axes: 2\n",
"CTYPE : 'RA---SIN' 'DEC--SIN' \n",
"CRVAL : 80.89416999999995 -69.75611 \n",
"CRPIX : 843.0 400.5 \n",
"PC1_1 PC1_2 : 1.0 0.0 \n",
"PC2_1 PC2_2 : 0.0 1.0 \n",
"CDELT : -0.0029673590504451 0.002967359050445104 \n",
"NAXIS : 1685 800"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-24T07:31:51.277841Z",
"start_time": "2024-07-24T07:31:51.271764Z"
}
],
},
"outputs": [],
"source": [
"aladin.wcs"
]
Expand All @@ -164,24 +138,108 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "9595ae02388b245a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(<Angle 5. deg>, <Angle 2.37388724 deg>)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-24T07:31:53.400986Z",
"start_time": "2024-07-24T07:31:53.389449Z"
}
],
},
"outputs": [],
"source": [
"aladin.fov_xy # Recover the current field of view for the x and y axis"
]
},
{
"cell_type": "markdown",
"id": "5ef087ca59d890ce",
"metadata": {},
"source": [
"## Getting the selection\n",
"First, load two catalogs:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bb48cb19a597e262",
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-24T07:31:55.769334Z",
"start_time": "2024-07-24T07:31:55.496270Z"
}
},
"outputs": [],
"source": [
"m1 = SkyCoord.from_name(\"m1\")\n",
"\n",
"# if these don't work, do `pip install astroquery -U --pre`\n",
"simbad = Simbad.query_region(m1, radius=0.1 * u.deg)\n",
"usno = Vizier(catalog=\"I/284/out\", row_limit=-1).query_region(m1, radius=0.05 * u.deg)[\n",
" 0\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0030a996",
"metadata": {},
"outputs": [],
"source": [
"aladin.add_table(simbad, name=\"simbad\", color=\"purple\", shape=\"circle\", source_size=20)\n",
"aladin.add_table(usno, name=\"usno\", color=\"teal\", shape=\"square\", source_size=20)\n",
"aladin.target = m1\n",
"aladin.fov = 0.3\n",
"aladin.survey = \"CDS/P/PanSTARRS/DR1/g\""
]
},
{
"cell_type": "markdown",
"id": "ab287cf3d87bb5d2",
"metadata": {},
"source": [
"After that, select a region in the Aladin Lite widget (you can also trigger a selection with `right click` then `select sources`):"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3efb33016d863bf7",
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-24T07:31:58.508331Z",
"start_time": "2024-07-24T07:31:58.501683Z"
}
},
"outputs": [],
"source": [
"aladin.selection(\"circle\")"
]
},
{
"cell_type": "markdown",
"id": "4d0fead988d63736",
"metadata": {},
"source": [
"Then, you can recover the selection as a list of astropy.Table objects with:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cda32891dd654568",
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-24T07:32:07.757249Z",
"start_time": "2024-07-24T07:32:07.746282Z"
}
},
"outputs": [],
"source": [
"aladin.selected_objects"
]
}
],
"metadata": {
Expand Down Expand Up @@ -252,7 +310,7 @@
"grid_options": {
"color": {
"b": 0.6980392156862745,
"g": 0.19607843137254902,
"g": 0.19607843137254904,
"r": 0.6980392156862745
},
"enabled": false,
Expand Down
19 changes: 16 additions & 3 deletions js/models/event_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,24 @@ export default class EventHandler {
});

this.aladin.on("select", (catalogs) => {
let objectsData = [];
const selectedObjects = catalogs.map((catalog) => {
return catalog.map((object) => {
return {
ra: object.ra,
dec: object.dec,
data: object.data,
x: object.x,
y: object.y,
};
});
});
this.model.set("_selected_objects", selectedObjects);
this.model.save_changes();

// TODO: this flattens the selection. Each object from different
// catalogs are entered in the array. To change this, maybe change
// upstream what is returned upon selection?
let objectsData = [];
catalogs.forEach((catalog) => {
catalog.forEach((object) => {
objectsData.push({
Expand Down Expand Up @@ -253,8 +267,7 @@ export default class EventHandler {
add_overlay: this.messageHandler.handleAddOverlay,
change_colormap: this.messageHandler.handleChangeColormap,
get_JPG_thumbnail: this.messageHandler.handleGetJPGThumbnail,
trigger_rectangular_selection:
this.messageHandler.handleTriggerRectangularSelection,
trigger_selection: this.messageHandler.handleTriggerSelection,
add_table: this.messageHandler.handleAddTable,
};

Expand Down
7 changes: 5 additions & 2 deletions js/models/message_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ export default class MessageHandler {
this.aladin.exportAsPNG();
}

handleTriggerRectangularSelection() {
this.aladin.select();
handleTriggerSelection(msg) {
let selectionType = msg["selection_type"];
if (selectionType === "rectangle") selectionType = "rect";
else if (selectionType === "polygon") selectionType = "poly";
this.aladin.select(selectionType);
}

handleAddTable(msg, buffers) {
Expand Down
Loading

0 comments on commit 235a77c

Please sign in to comment.