-
Notifications
You must be signed in to change notification settings - Fork 75
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
Enhance From File catalog loading to support more columns and improve Clear Table functionality #3359
base: main
Are you sure you want to change the base?
Enhance From File catalog loading to support more columns and improve Clear Table functionality #3359
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Already exists and probably still relevant: https://jdaviz.readthedocs.io/en/latest/imviz/plugins.html#catalog-search. Any specific changes you think are needed? |
Re: doc -- OK I was confused by the title of PR and change log. Nvm |
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.
Some technical comments/questions.
I like the new test you added that uses local data. Thanks!
@@ -9,6 +9,7 @@ Cubeviz | |||
|
|||
Imviz | |||
^^^^^ | |||
- Enhance the Catalog Search plugin to support additional columns when loading catalog data from files. [#3359] |
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.
- Enhance the Catalog Search plugin to support additional columns when loading catalog data from files. [#3359] | |
- Enhance the Catalog Search plugin to support additional columns when loading catalog data from files. [#3359] |
@@ -382,8 +382,8 @@ To load a catalog from a supported `JWST ECSV catalog file <https://jwst-pipelin | |||
The file must be able to be parsed by `astropy.table.Table.read` and contains the following columns: | |||
|
|||
* ``'sky_centroid'``: Column with `~astropy.coordinates.SkyCoord` sky coordinates of the sources. | |||
* ``'label'``: Column with string identifiers of the sources. If you have numerical identifiers, | |||
they will be recast as string. | |||
* ``'label(optional)'``: Column with string identifiers of the sources. If not provided, unique string identifiers will be generated automatically. |
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.
* ``'label(optional)'``: Column with string identifiers of the sources. If not provided, unique string identifiers will be generated automatically. | |
* ``'label'``: (Optional) Column with string identifiers of the sources. | |
If not provided, unique string identifiers will be generated automatically. |
|
||
if 'sky_centroid' not in table.colnames: | ||
return 'Table does not contain required sky_centroid column', {} | ||
if 'sky_centroid' not in table.colnames: |
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.
Why does this have to be within try
? This check should never fail if table
is successfully read and we already have a blanket except
for that. It would only result in a bool.
In fact, I think all the if
after .read
can be after the try-except block. Unless I missed something here?
@@ -204,6 +207,11 @@ def search(self, error_on_fail=False): | |||
# 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 | |||
column_names = list(table.colnames) |
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.
column_names = list(table.colnames) | |
column_names = table.colnames |
I think it is always a list. No need to recast.
@@ -204,6 +207,11 @@ def search(self, error_on_fail=False): | |||
# 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 | |||
column_names = list(table.colnames) | |||
self.table.headers_avail = self.headers + [ | |||
col for col in column_names if col not in self.headers and col not in ["sky_centroid", "label"] # noqa:E501 |
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.
col for col in column_names if col not in self.headers and col not in ["sky_centroid", "label"] # noqa:E501 | |
col for col in column_names if col not in self.headers and col not in ["sky_centroid", "label"] # noqa: E501 |
p.s. Maybe also make a note here on why "sky_centroid" and "label" get special treatments here?
p.p.s. If the point of this line is to not have duplicates, I wonder if list(set(self.headers + column_names) - {"sky_centroid", "label"})
is easier. 🤔 (You might have to tweak this because I dunno what is the deal with "sky_centroid" and "label".)
'Right Ascension (degrees)': row['sky_centroid'].ra.deg, | ||
'Declination (degrees)': row['sky_centroid'].dec.deg, | ||
'Object ID': str(row.get('label', f"{idx + 1}")), | ||
'id': idx+1, |
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.
I don't grok why there is "Object ID" and then there is "id" but cleaning that up is out of scope here.
That said, I noticed that "id" here is now idx + 1
but still len(self.table)
on L271 above. Should this inconsistency be addressed in this PR or is this also out of scope?
'y_coord': y_coord, | ||
} | ||
for col in table.colnames: | ||
if col not in ['label', 'sky_centroid']: # Skip already processed columns |
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.
I see these 2 column names hardcoded multiple times. Should we store them as a hidden instance attribute instead so it can be reused?
@@ -402,9 +412,13 @@ def vue_do_search(self, *args, **kwargs): | |||
# calls self.search() which handles all of the searching logic | |||
self.search() | |||
|
|||
def clear(self, hide_only=True): | |||
def clear_table(self, hide_only=True): |
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.
I see that clear_table
is already exposed via user API before this PR. Is this fixing an API bug? If so, it could also be added to change log.
If not, is this accidentally overwriting the inherited method from one of the mixin?
return PluginUserApi(self, expose=('clear_table', 'export_table', |
jdaviz/jdaviz/core/template_mixin.py
Line 4816 in 48be154
def clear_table(self): |
If it is an overwrite but not accidental, is this considered API change that also should go into the change log?
Somehow the changes here cause ResourceWarning in a catalog test. Unclosed file somewhere? Should investigate.
|
@@ -271,16 +279,19 @@ 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 idx, (row, x_coord, y_coord) in enumerate(zip(self.app._catalog_source_table, x_coordinates, y_coordinates)): # noqa:E501 | |||
row_info = { |
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 loaded table has to have a 'sky centroid' column, but it is then broken up into ra and dec, which means when its written back out it cant be read back in because it doesn't have 'sky centroid'. would it be possible to add a check when loading if the table already contains a ra and dec column rather than unpacking sky centroid? as it is, a table written out by the app can not be read back in
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.
Does that problem pre-date this PR? Just wondering if round-tripping is in scope here (e.g., writing it out back as sky centroid as a single column in ECSV format).
Description
This pull request introduces:
Catalog Loading from File:
- Users can now load catalog data (e.g., .ecsv files) directly into the table.
Improved Clear Table Functionality:
- The "Clear Table" button now clears the table, removes markers, and resets selected rows in the viewer.
Screen.Recording.2024-12-15.at.10.42.00.PM.mov
Fixes #
Change log entry
CHANGES.rst
? If you want to avoid merge conflicts,list the proposed change log here for review and add to
CHANGES.rst
before merge. If no, maintainershould add a
no-changelog-entry-needed
label.Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
trivial
label.