Skip to content
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

Merged
merged 25 commits into from
Jan 3, 2025

Conversation

haticekaratay
Copy link
Contributor

@haticekaratay haticekaratay commented Dec 16, 2024

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

  • Is a change log needed? If yes, is it added to 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, maintainer
    should 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.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a milestone set? Set this to bugfix milestone if this is a bug fix and needs to be released ASAP; otherwise, set this to the next major release milestone. Bugfix milestone also needs an accompanying backport label.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@haticekaratay haticekaratay added this to the 4.1 milestone Dec 16, 2024
@github-actions github-actions bot added imviz plugin Label for plugins common to multiple configurations labels Dec 16, 2024
@haticekaratay haticekaratay marked this pull request as ready for review December 19, 2024 04:12
@haticekaratay haticekaratay changed the title WIP: Add functionality to load catalogs from a file Add functionality to load catalogs from a file Dec 19, 2024
CHANGES.rst Outdated Show resolved Hide resolved
@pllim

This comment was marked as resolved.

@kecnry
Copy link
Member

kecnry commented Dec 19, 2024

We should also probably add a section in user docs to document exactly what format of such file the plugin can actually ingest?

Already exists and probably still relevant: https://jdaviz.readthedocs.io/en/latest/imviz/plugins.html#catalog-search. Any specific changes you think are needed?

@pllim
Copy link
Contributor

pllim commented Dec 19, 2024

Re: doc -- OK I was confused by the title of PR and change log. Nvm

@rosteen rosteen modified the milestones: 4.1, 4.2 Dec 23, 2024
@haticekaratay haticekaratay changed the title Add functionality to load catalogs from a file Enhance From File catalog loading to support more columns and improve Clear Table functionality Dec 23, 2024
Copy link
Contributor

@pllim pllim left a 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!

CHANGES.rst Show resolved Hide resolved
docs/imviz/plugins.rst Outdated Show resolved Hide resolved

if 'sky_centroid' not in table.colnames:
return 'Table does not contain required sky_centroid column', {}
if 'sky_centroid' not in table.colnames:
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching that! Honestly, I don’t know what I was thinking when I moved those checks inside the try-except block. You’re absolutely right that they belong outside since they’re not handling exceptions from QTable.read. I’ve fixed it now, and I appreciate your sharp eye for detail!

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
column_names = list(table.colnames)
column_names = table.colnames

I think it is always a list. No need to recast.

https://github.com/astropy/astropy/blob/53b673bb4fd98da7b8972837a9650469bc130b02/astropy/table/table.py#L2218

jdaviz/configs/imviz/plugins/catalogs/catalogs.py Outdated Show resolved Hide resolved
'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,
Copy link
Contributor

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?

jdaviz/configs/imviz/plugins/catalogs/catalogs.py Outdated Show resolved Hide resolved
@pllim
Copy link
Contributor

pllim commented Dec 27, 2024

Somehow the changes here cause ResourceWarning in a catalog test. Unclosed file somewhere? Should investigate.

FAILED jdaviz/configs/imviz/tests/test_catalogs.py::TestCatalogs::test_plugin_image_with_result
...
ResourceWarning: unclosed <ssl.SSLSocket ...>

@@ -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 = {
Copy link
Contributor

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

Copy link
Contributor

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).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export_table is ultimately called which will treat the the TableMixin columns as a QTable

self._qtable.write(filename, overwrite=overwrite)
and write the columns as is, so unless you have a column in our table that is labeled sky_centroid, you wouldn't be able to read it back in after exporting. This is also true if you try exporting Gaia or SDSS.

In the case of 'from file', we already have the sky_centroid column, so we could add the sky_centroid column with the same name to our table, export the table, and then the exported file is able to be reloaded into Imviz.

The other catalogs options could be added in a follow up effort for either writing the sky_centroid column to the loaded catalog table or handle it on export.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to keep it aligned with the other Search options, but I didn't think of the export functionality then. Thanks for the additional context, all; I will keep the existing sky_centroid column in the table.

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

Attention: Patch coverage is 88.57143% with 4 lines in your changes missing coverage. Please review.

Project coverage is 88.12%. Comparing base (e2faabf) to head (7c01d7a).

Files with missing lines Patch % Lines
jdaviz/core/template_mixin.py 75.00% 3 Missing ⚠️
jdaviz/configs/imviz/plugins/catalogs/catalogs.py 95.65% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3359      +/-   ##
==========================================
- Coverage   88.12%   88.12%   -0.01%     
==========================================
  Files         127      127              
  Lines       19702    19727      +25     
==========================================
+ Hits        17362    17384      +22     
- Misses       2340     2343       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Copy link
Contributor

@gibsongreen gibsongreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to me, great work!

@pllim pllim merged commit ce20700 into spacetelescope:main Jan 3, 2025
19 checks passed
rosteen pushed a commit to rosteen/jdaviz that referenced this pull request Jan 6, 2025
… Clear Table functionality (spacetelescope#3359)

* Add functionality to load catalogs from a file

* Fix table and viewer clearing functionality

* Remove redundant 'Clear' button and combine its functionality with 'Clear Table' for intuitive behavior

* Codestyle

* Add change log

* Update tests

* Fix failing test

* Fix the test, ensuring to first select a row before zooming in.

* Update change log

* Preserve the unit when serializing

* Generate default Object IDs when label column is missing

* Update docs related to label column in catalogs

* Update tests after merge

* Update test

* Move changelog to correct milestone

* Adjust test assertions

* Add test for loading catalogs with additional columns

* Update change log

* Update based on feedback

* Apply suggestions from code review

Co-authored-by: P. L. Lim <[email protected]>

* Update CHANGES.rst

Co-authored-by: P. L. Lim <[email protected]>

* Adjust test tolerance

---------

Co-authored-by: P. L. Lim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imviz plugin Label for plugins common to multiple configurations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants