-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add functionality to load catalogs from a file #3359
base: main
Are you sure you want to change the base?
Changes from all commits
2f28144
746d8db
485846e
edf93eb
73aad20
d19de55
5ece13a
3fb6df9
640b615
d7d7439
7799594
a96babd
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
from astropy.nddata import NDData | ||
from astropy.coordinates import SkyCoord | ||
from astropy.table import Table, QTable | ||
from numpy.testing import assert_allclose | ||
|
||
|
||
@pytest.mark.remote_data | ||
|
@@ -113,7 +114,7 @@ def test_plugin_image_with_result(self, imviz_helper, tmp_path): | |
prev_results = catalogs_plugin.number_of_results | ||
|
||
# testing that every variable updates accordingly when markers are cleared | ||
catalogs_plugin.vue_do_clear() | ||
catalogs_plugin.vue_do_clear_table() | ||
|
||
assert not catalogs_plugin.results_available | ||
|
||
|
@@ -157,12 +158,16 @@ def test_plugin_image_with_result(self, imviz_helper, tmp_path): | |
assert imviz_helper.viewers['imviz-0']._obj.state.y_min == -0.5 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.y_max == 1488.5 | ||
|
||
# First select a row | ||
catalogs_plugin.table.selected_rows = [ | ||
catalogs_plugin.table.items[0]] | ||
# Then zoom in to the selected | ||
catalogs_plugin.vue_zoom_in() | ||
|
||
assert imviz_helper.viewers['imviz-0']._obj.state.x_min == 858.24969 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.x_max == 958.38461 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.y_min == 278.86265 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.y_max == 378.8691 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.x_min == 1022.5631800000001 | ||
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. Why did the test results change? |
||
assert imviz_helper.viewers['imviz-0']._obj.state.x_max == 1122.56318 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.y_min == 675.29611 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.y_max == 775.29611 | ||
|
||
|
||
def test_from_file_parsing(imviz_helper, tmp_path): | ||
|
@@ -237,23 +242,30 @@ def test_offline_ecsv_catalog(imviz_helper, image_2d_wcs, tmp_path): | |
assert catalogs_plugin.number_of_results == n_entries | ||
assert len(imviz_helper.app.data_collection) == 2 # image + markers | ||
|
||
catalogs_plugin.clear() | ||
catalogs_plugin.clear_table() | ||
|
||
assert not catalogs_plugin.results_available | ||
assert len(imviz_helper.app.data_collection) == 2 # markers still there, just hidden | ||
|
||
catalogs_plugin.clear(hide_only=False) | ||
catalogs_plugin.clear_table(hide_only=False) | ||
assert not catalogs_plugin.results_available | ||
assert len(imviz_helper.app.data_collection) == 1 # markers gone for good | ||
|
||
assert imviz_helper.viewers['imviz-0']._obj.state.x_min == -0.5 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.x_max == 9.5 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.y_min == -0.5 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.y_max == 9.5 | ||
# Re-populate the table with a new search | ||
out_tbl = catalogs_plugin.search() | ||
assert len(out_tbl) > 0 | ||
# Ensure at least one row is selected before zooming | ||
catalogs_plugin.table.selected_rows = [catalogs_plugin.table.items[0]] | ||
assert len(catalogs_plugin.table.selected_rows) > 0 | ||
|
||
# Now zoom in | ||
catalogs_plugin.vue_zoom_in() | ||
|
||
assert imviz_helper.viewers['imviz-0']._obj.state.x_min == -49.99966 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.x_max == 50.00034 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.y_min == -48.99999 | ||
assert imviz_helper.viewers['imviz-0']._obj.state.y_max == 51.00001 | ||
assert_allclose(imviz_helper.viewers['imviz-0']._obj.state.x_min, -49.99966, rtol=1e-6) | ||
assert_allclose(imviz_helper.viewers['imviz-0']._obj.state.x_max, 50.00034, rtol=1e-6) | ||
assert_allclose(imviz_helper.viewers['imviz-0']._obj.state.y_min, -48.99999, rtol=1e-6) | ||
assert_allclose(imviz_helper.viewers['imviz-0']._obj.state.y_max, 51.00001, rtol=1e-6) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4691,12 +4691,20 @@ def float_precision(column, item): | |
return '' | ||
elif isinstance(item, tuple) and np.all([np.isnan(i) for i in item]): | ||
return '' | ||
|
||
elif isinstance(item, float): | ||
return float_precision(column, item) | ||
elif isinstance(item, (list, tuple)): | ||
return [float_precision(column, i) if isinstance(i, float) else i for i in item] | ||
|
||
elif isinstance(item, (np.float32, np.float64)): | ||
return float(item) | ||
elif isinstance(item, u.Quantity): | ||
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. This way we lost the unit info, is that important? Also I wonder if we can take advantage of the JsonCsutomEncoder that astropy already has for some of these: https://github.com/astropy/astropy/blob/93b6f551b9ed00c4a422b754eae0261f1a7552c9/astropy/utils/misc.py#L366 |
||
return {"value": item.value.tolist() if item.size > 1 else item.value, "unit": str(item.unit)} # noqa: E501 | ||
elif isinstance(item, np.bool_): | ||
return bool(item) | ||
elif isinstance(item, np.ndarray): | ||
return item.tolist() | ||
elif isinstance(item, tuple): | ||
return tuple(json_safe(v) for v in item) | ||
return item | ||
|
||
if isinstance(item, QTable): | ||
|
@@ -4738,6 +4746,8 @@ def clear_table(self): | |
Clear all entries/markers from the current table. | ||
""" | ||
self.items = [] | ||
self.selected_rows = [] | ||
self.selected_indices = [] | ||
self._qtable = None | ||
self._plugin.session.hub.broadcast(PluginTableModifiedMessage(sender=self)) | ||
|
||
|
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.
The docs say that the
label
column must exist, but we don't actually enforce that so you are able to load with just thesky_centroid
column. This results in theObject ID
column = N/A, so I think we should add a condition here so we make sure that column also exists.