Skip to content

Commit

Permalink
Catalog Search: Hide markers only
Browse files Browse the repository at this point in the history
when clearing by default
  • Loading branch information
pllim committed Oct 25, 2022
1 parent 6f2e5d7 commit 32f6618
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Cubeviz
Imviz
^^^^^

- Clearing markers in Catalog Search will only hide them, which improves
"Clear" performance. [#1774]

Mosviz
^^^^^^

Expand Down
4 changes: 4 additions & 0 deletions jdaviz/configs/imviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ def layer_is_image_data(layer):
return isinstance(layer, BaseData) and layer.ndim == 2


def layer_is_table_data(layer):
return isinstance(layer, BaseData) and layer.ndim == 1


def get_top_layer_index(viewer):
"""Get index of the top visible image layer in Imviz.
This is because when blinked, first layer might not be top visible layer.
Expand Down
36 changes: 25 additions & 11 deletions jdaviz/configs/imviz/plugins/catalogs/catalogs.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import numpy as np
import numpy.ma as ma
import os

from traitlets import List, Unicode, Bool, Int, observe

import numpy as np
import numpy.ma as ma
from astropy.table import QTable
from astropy.coordinates import SkyCoord
from astroquery.sdss import SDSS
from traitlets import List, Unicode, Bool, Int, observe

from jdaviz.configs.default.plugins.data_tools.file_chooser import FileChooser
from jdaviz.core.registries import tray_registry
Expand Down Expand Up @@ -49,6 +47,7 @@ def __init__(self, *args, **kwargs):
self.components = {'g-file-import': self._file_upload}
self._file_upload.observe(self._on_file_path_changed, names='file_path')
self._cached_table_from_file = {}
self._marker_name = 'catalog_results'

def _on_file_path_changed(self, event):
self.from_file_message = 'Checking if file is valid'
Expand Down Expand Up @@ -127,6 +126,8 @@ def search(self):

# conducts search based on SDSS
if self.catalog_selected == "SDSS":
from astroquery.sdss import SDSS

# queries the region (based on the provided center point and radius)
# finds all the sources in that region
query_region_result = SDSS.query_region(skycoord_center, radius=zoom_radius,
Expand Down Expand Up @@ -186,24 +187,37 @@ def search(self):

# 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='catalog_results')
viewer.add_markers(table=catalog_results, use_skycoord=True, marker_name=self._marker_name)

return skycoord_table

def vue_do_search(self, *args, **kwargs):
# calls self.search() which handles all of the searching logic
self.search()

def clear(self):
if self.results_available:
def clear(self, hide_only=True):
# gets the current viewer
viewer = self.viewer.selected_obj

if not hide_only and self._marker_name in self.app.data_collection.labels:
# resetting values
self.results_available = False
self.number_of_results = 0
# gets the current viewer
viewer = self.viewer.selected_obj

# all markers are removed from the viewer
viewer.reset_markers()
viewer.remove_markers(marker_name=self._marker_name)

elif self.results_available:
from jdaviz.configs.imviz.helper import layer_is_table_data

# resetting values
self.results_available = False
self.number_of_results = 0

# markers still there, just hidden
for lyr in viewer.layers:
if layer_is_table_data(lyr.layer) and lyr.layer.label == self._marker_name:
lyr.visible = False

def vue_do_clear(self, *args, **kwargs):
self.clear()
8 changes: 8 additions & 0 deletions jdaviz/configs/imviz/tests/test_catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,11 @@ def test_offline_ecsv_catalog(imviz_helper, image_2d_wcs, tmp_path):
assert len(out_tbl) == n_entries
assert catalogs_plugin._obj.number_of_results == n_entries
assert len(imviz_helper.app.data_collection) == 2 # image + markers

catalogs_plugin._obj.clear()
assert not catalogs_plugin._obj.results_available
assert len(imviz_helper.app.data_collection) == 2 # markers still there, just hidden

catalogs_plugin._obj.clear(hide_only=False)
assert not catalogs_plugin._obj.results_available
assert len(imviz_helper.app.data_collection) == 1 # markers gone for good

0 comments on commit 32f6618

Please sign in to comment.