Skip to content

Commit

Permalink
Catalogs plugin results table (spacetelescope#2915)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Katherine Carver <kcarver@osx-summer2401.stsci.edu>
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
Co-authored-by: Kyle Conroy <kyleconroy@gmail.com>
Co-authored-by: Ricky O'Steen <39831871+rosteen@users.noreply.github.com>
  • Loading branch information
5 people authored Jul 16, 2024
1 parent 73e54d0 commit 23b3edd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Cubeviz
Imviz
^^^^^

- Added a table with catalog search results. [#2915]

Mosviz
^^^^^^

Expand Down
2 changes: 2 additions & 0 deletions docs/imviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ are not stored. To save the current result before submitting a new query, you ca
The table returned from the API above may cover more sources than shown in the currently zoomed-in
portion of the image. Additional steps will be needed to filter out these points, if necessary.

Performing a search populates a table that contains the
right ascension, declination, and the object ID of the found sources.

.. _imviz-footprints:

Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/default/plugins/markers/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def _on_is_active_changed(self, *args):
else:
viewer.remove_event_callback(callback)

# this is where items are being added to the table
def _on_viewer_key_event(self, viewer, data):
if data['event'] == 'keydown' and data['key'] == 'm':
row_info = self.coords_info.as_dict()
Expand Down
41 changes: 37 additions & 4 deletions jdaviz/configs/imviz/plugins/catalogs/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
FileImportSelectPluginComponent, HasFileImportSelect,
with_spinner)

from jdaviz.core.template_mixin import TableMixin
from jdaviz.core.user_api import PluginUserApi

__all__ = ['Catalogs']


@tray_registry('imviz-catalogs', label="Catalog Search")
class Catalogs(PluginTemplateMixin, ViewerSelectMixin, HasFileImportSelect):
class Catalogs(PluginTemplateMixin, ViewerSelectMixin, HasFileImportSelect, TableMixin):
"""
See the :ref:`Catalog Search Plugin Documentation <imviz-catalogs>` for more details.
Expand All @@ -32,19 +35,34 @@ class Catalogs(PluginTemplateMixin, ViewerSelectMixin, HasFileImportSelect):
results_available = Bool(False).tag(sync=True)
number_of_results = Int(0).tag(sync=True)

# setting the default table headers and values
_default_table_values = {
'Right Ascension (degrees)': np.nan,
'Declination (degrees)': np.nan,
'Object ID': np.nan}

@property
def user_api(self):
return PluginUserApi(self, expose=('clear_table', 'export_table',))

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.catalog = FileImportSelectPluginComponent(self,
items='catalog_items',
selected='catalog_selected',
manual_options=['SDSS', 'From File...'])

# set the custom file parser for importing catalogs
self.catalog._file_parser = self._file_parser

self._marker_name = 'catalog_results'

# initializing the headers in the table that is displayed in the UI
headers = ['Right Ascension (degrees)', 'Declination (degrees)', 'Object ID']

self.table.headers_avail = headers
self.table.headers_visible = headers
self.table._default_values_by_colname = self._default_table_values

@staticmethod
def _file_parser(path):
try:
Expand Down Expand Up @@ -142,13 +160,28 @@ def search(self, error_on_fail=False):
query_region_result['dec'],
unit='deg')

# adding in coords + Id's into table
for row in self.app._catalog_source_table:
row_info = {'Right Ascension (degrees)': row['ra'],
'Declination (degrees)': row['dec'],
'Object ID': row['objid']}
self.table.add_item(row_info)

elif self.catalog_selected == 'From File...':
# all exceptions when going through the UI should have prevented setting this path
# but this exceptions might be raised here if setting from_file from the UI
table = self.catalog.selected_obj
self.app._catalog_source_table = table
skycoord_table = table['sky_centroid']

for row in self.app._catalog_source_table:
# find new to add in a way to append the source id to the table
# 'Object ID': row['label']} ; 'label' is failing tests
row_info = {'Right Ascension (degrees)': row['sky_centroid'].ra,
'Declination (degrees)': row['sky_centroid'].dec,
'Object ID': row.get('label', '')}
self.table.add_item(row_info)

else:
self.results_available = False
self.number_of_results = 0
Expand Down Expand Up @@ -180,8 +213,8 @@ def search(self, error_on_fail=False):

# QTable stores all the filtered sky coordinate points to be marked
catalog_results = QTable({'coord': filtered_skycoord_table})
self.number_of_results = len(catalog_results)

self.number_of_results = len(catalog_results)
# markers are added to the viewer based on the table
viewer.marker = {'color': 'red', 'alpha': 0.8, 'markersize': 5, 'fill': False}
viewer.add_markers(table=catalog_results, use_skycoord=True, marker_name=self._marker_name)
Expand Down
7 changes: 5 additions & 2 deletions jdaviz/configs/imviz/plugins/catalogs/catalogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
<v-row>
<p class="font-weight-bold">Results:</p>
<span style='padding-left: 4px' v-if="results_available">{{number_of_results}}</span>
<v-row>
</v-row>

<jupyter-widget :widget="table_widget"></jupyter-widget>


</j-tray-plugin>
</template>
</template>

0 comments on commit 23b3edd

Please sign in to comment.