Skip to content

Commit

Permalink
add snackbar message when max_sources used
Browse files Browse the repository at this point in the history
  • Loading branch information
gibsongreen committed Dec 6, 2024
1 parent 12af427 commit ee4735a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion jdaviz/configs/imviz/plugins/catalogs/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def search(self, error_on_fail=False):
# the distance between the longest zoom limits and the center point
zoom_radius = max(skycoord_center.separation(zoom_coordinate))

max_sources_used = False

# conducts search based on SDSS
if self.catalog_selected == "SDSS":
from astroquery.sdss import SDSS
Expand All @@ -161,6 +163,7 @@ def search(self, error_on_fail=False):
data_release=17)
if len(query_region_result) > self.max_sources:
query_region_result = query_region_result[:self.max_sources]
max_sources_used = True

Check warning on line 166 in jdaviz/configs/imviz/plugins/catalogs/catalogs.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/imviz/plugins/catalogs/catalogs.py#L165-L166

Added lines #L165 - L166 were not covered by tests
except Exception as e: # nosec
errmsg = (f"Failed to query {self.catalog_selected} with c={skycoord_center} and "
f"r={zoom_radius}: {repr(e)}")
Expand Down Expand Up @@ -190,6 +193,8 @@ def search(self, error_on_fail=False):
sources = Gaia.query_object(skycoord_center, radius=zoom_radius,

Check warning on line 193 in jdaviz/configs/imviz/plugins/catalogs/catalogs.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/imviz/plugins/catalogs/catalogs.py#L192-L193

Added lines #L192 - L193 were not covered by tests
columns=('source_id', 'ra', 'dec')
)
if len(sources) == self.max_sources:
max_sources_used = True

Check warning on line 197 in jdaviz/configs/imviz/plugins/catalogs/catalogs.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/imviz/plugins/catalogs/catalogs.py#L196-L197

Added lines #L196 - L197 were not covered by tests
self.app._catalog_source_table = sources
skycoord_table = SkyCoord(sources['ra'], sources['dec'], unit='deg')

Expand All @@ -200,6 +205,7 @@ def search(self, error_on_fail=False):
self.app._catalog_source_table = table
if len(table['sky_centroid']) > self.max_sources:
skycoord_table = table['sky_centroid'][:self.max_sources]
max_sources_used = True
else:
skycoord_table = table['sky_centroid']
else:
Expand All @@ -214,6 +220,13 @@ def search(self, error_on_fail=False):
self.app._catalog_source_table = None
return

if max_sources_used:
snackbar_message = SnackbarMessage(
f"{self.catalog_selected} queried, results returned were limited using max_sources = {self.max_sources}.", # noqa
color="success",
sender=self)
self.hub.broadcast(snackbar_message)

# coordinates found are converted to pixel coordinates
pixel_table = viewer.state.reference_data.coords.world_to_pixel(skycoord_table)
# coordinates are filtered out (using a mask) if outside the zoom range
Expand Down Expand Up @@ -252,7 +265,6 @@ def search(self, error_on_fail=False):
if len(self.app._catalog_source_table) == 1 or self.max_sources == 1:
x_coordinates = [x_coordinates]
y_coordinates = [y_coordinates]

for row, x_coord, y_coord in zip(self.app._catalog_source_table,
x_coordinates, y_coordinates):
# Check if the row contains the required keys
Expand Down

0 comments on commit ee4735a

Please sign in to comment.