-
Notifications
You must be signed in to change notification settings - Fork 0
select sources by table #2
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "6b6dc38b-1941-4323-9990-f2caf2330325", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Import Astropy Table\n", | ||
| "This notebook shows how you can import an astropy table as a selection region " | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "04719ca3-019c-4806-9453-0564773099d0", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from ipyaladin import Aladin\n", | ||
| "\n", | ||
| "from astropy.coordinates import SkyCoord\n", | ||
| "from astroquery.mast import Catalogs" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "cc554318-c26d-4f9e-8f2e-9fd1ec19a005", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "%load_ext autoreload\n", | ||
| "%autoreload 2" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "15efe516-e4e1-448c-a5bc-959215682254", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "aladin = Aladin(\n", | ||
| " survey=\"SDSS9 colored\",\n", | ||
| " show_coo_grid=True,\n", | ||
| " target=\"TRAPPIST-1\",\n", | ||
| " coo_frame=\"icrs\",\n", | ||
| " fov=0.05,\n", | ||
| " height=400,\n", | ||
| " samp=True,\n", | ||
| ")\n", | ||
| "aladin" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "5892695a-9915-4835-bd8b-a6f9a049a496", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Add a custom catalog\n", | ||
| "load a custom catalog that we want to select" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "a8c9b374-ede2-46a1-95c1-6e44072dde20", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "target_name = \"TRAPPIST-1\"\n", | ||
| "catalog_data = Catalogs.query_region(\n", | ||
| " coordinates=SkyCoord.from_name(target_name),\n", | ||
| " radius=0.01, # [deg]\n", | ||
| " catalog=\"Panstarrs\",\n", | ||
| ")\n", | ||
| "catalog_data.rename_columns([\"raMean\", \"decMean\"], [\"ra\", \"dec\"])\n", | ||
| "\n", | ||
| "\n", | ||
| "aladin.add_table(\n", | ||
| " catalog_data, name=\"test-table\", color=\"lime\", shape=\"circle\", source_size=10\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "b1d279fc-7a46-4d7e-a4ae-1ff739a6c1a5", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Once the catalog is loaded, you can select all of the sources that match on the provided keys. " | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "67fcab46-281d-4012-bd09-d35652be8045", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "aladin.select_table(catalog_data, keys=[\"objID\"])" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": {}, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,6 +155,27 @@ export default class MessageHandler { | |
| this.aladin.select(selectionType); | ||
| } | ||
|
|
||
| handleTriggerSelectionByTable(msg) { | ||
| let sources = msg["table"]; | ||
| let keys = msg["keys"]; | ||
| let sourcesByCatalog = this.aladin.view.catalogs | ||
| .map((cat) => { | ||
| if (!cat.isShowing) { | ||
| return; | ||
| } | ||
| return cat.getSources().filter((source) => | ||
| sources.some((s) => | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found the name I'd also be tempted to store the |
||
| keys.every((key) => { | ||
| return s[key] == source.data[key]; | ||
| }), | ||
| ), | ||
| ); | ||
| }) | ||
| .filter((n) => n.length); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this filter statement is here to remove any empty lists that may be returned from the first filter statement. If there are multiple catalogs, and the key only matches on some of them, it will return something like the following The empty list needs to be removed for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like there is already enough happening with all the nested functions in the |
||
|
|
||
| this.aladin.view.selectObjects(sourcesByCatalog); | ||
| } | ||
|
|
||
| handleAddTable(msg, buffers) { | ||
| const options = convertOptionNamesToCamelCase(msg["options"] || {}); | ||
| const buffer = buffers[0].buffer; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,8 @@ docs = ["autoapi", | |
| "sphinx-collections", | ||
| "sphinx-copybutton", | ||
| "sphinx-gallery", | ||
| "pydata-sphinx-theme" | ||
| "pydata-sphinx-theme", | ||
| "pandas" | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: we had to add pandas here since we are converting the astropy table to pandas in order to get the json safe dictionary of user defined keys to search on. This is the best way I've found to do this, but I'm open to any suggestions |
||
| ] | ||
|
|
||
| # automatically add the dev feature to the default env (e.g., hatch shell) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be clearer to explicitly return
[].