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

Footprints plugin #2341

Merged
merged 32 commits into from
Aug 14, 2023
Merged

Footprints plugin #2341

merged 32 commits into from
Aug 14, 2023

Conversation

kecnry
Copy link
Member

@kecnry kecnry commented Aug 4, 2023

Description

IMPORTANT: this PR currently require pysiaf to be installed or the plugin is disabled. We may want to either remove this dependency entirely or make it an official dependency that is installed with jdaviz.

This pull request implements a new plugin in Imviz to plot an arbitrary number of user-configured footprints from any JWST instrument, adapted from code written by @melanieclarke in https://github.com/spacetelescope/jwst_novt. In the future, this could easily be extended to other instruments or to a generic "overlays" or "regions" plugin.

Basic support for adding and customizing any number of footprints (NOTE some names have been changed to be more general with "overlay"/"preset" instead of "footprint"/"instrument"):

Screen.Recording.2023-08-04.at.2.16.46.PM.mov

Logic for handling multiple viewers:

Screen.Recording.2023-08-04.at.2.20.15.PM.mov

Handling lack of WCS and ability to recenter footprint:

Screen.Recording.2023-08-11.at.10.09.47.AM.mov

Footprints plugin docs

This PR also brings the EditableSelectPluginComponent (which allows the user to name/rename/add/delete an arbitrary number of footprint overlays) originally implemented in spacetelescope/lcviz#19 upstream into jdaviz, as well as implementing the concept of inapplicable_attrs to use within the plugin user APIs (if we adopt this here, we could follow-up with improvements to plot options and other plugins where some traitlets are not always applicable). spacetelescope/lcviz#36 will then update lcviz to depend on the implementation here so that we do not have two duplicate implementations.

TODO

  • docs
  • test coverage
  • screen recordings of inapplicable_attrs (or strip into separate PR since no longer needed now that all instruments are generalized and support the same input arguments)
  • decide what to do with pysiaf dependency
  • consider renaming to "overlays" or "regions" for future expansion
  • miri & niriss support
  • finalize list of apertures (and possibly make user-selectable?), including aperture used for centering
  • decide whether to have NIRCam:short vs long or a separate "path" dropdown that is only applicable for NIRCam (could use Plugin user API: inapplicable attrs #2347)
  • handle change in reference data (and plan what will need to be done with ENH: Image rotation via WCS-only layers #2179)
  • fix renaming resets overlay color
  • rebase and confirm no issues with plot options histogram being laggy (see Footprints plugin #2341 (comment))

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.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@kecnry kecnry added the imviz label Aug 4, 2023
@kecnry kecnry added this to the 3.7 milestone Aug 4, 2023
@github-actions github-actions bot added the documentation Explanation of code and concepts label Aug 4, 2023
@kecnry kecnry force-pushed the plugin-footprints branch 2 times, most recently from 4cfbbff to 5e98f91 Compare August 7, 2023 17:16
@kecnry kecnry force-pushed the plugin-footprints branch from 5e98f91 to a61d36c Compare August 7, 2023 17:59
@melanieclarke
Copy link
Contributor

This looks great! I really like being able to add and configure as many footprints as I want, from all the instruments.

A couple of picky details:

  • NIRCam and NIRSpec are labeled as 'NIRcam' and 'NIRspec' - the capitalization should be fixed
  • in the jwst_footprints code, there are variables named 'nrc_', which looks like a holdover from my code that treated NIRSpec and NIRCam separately. The 'nrc' was short for NIRCam. The variable names might be less confusing without this prefix.

And a couple comments:

  • The footprints plugin seems to interact badly with the plot options histogram, particularly when the "Limit histogram to current zoom limits" option is on. Updates for the histogram are very slow on zooming and the footprints flash on and off repeatedly while waiting.
  • I can't seem to get the footprints to show up in my particular use case in the NOVT application. I'm not sure if it's my custom configuration or layout or something else. I'll keep checking.

@kecnry kecnry force-pushed the plugin-footprints branch 2 times, most recently from bc79cdf to e2ff232 Compare August 7, 2023 19:38
@kecnry
Copy link
Member Author

kecnry commented Aug 7, 2023

Thanks for the feedback @melanieclarke

NIRCam and NIRSpec are labeled as 'NIRcam' and 'NIRspec' - the capitalization should be fixed

Fixed

in the jwst_footprints code, there are variables named 'nrc_', which looks like a holdover from my code that treated NIRSpec and NIRCam separately. The 'nrc' was short for NIRCam. The variable names might be less confusing without this prefix.

Ah yes, I meant to clean that up after generalizing to all instruments and then forgot. Should be fixed now too, thanks!

The footprints plugin seems to interact badly with the plot options histogram, particularly when the "Limit histogram to current zoom limits" option is on. Updates for the histogram are very slow on zooming and the footprints flash on and off repeatedly while waiting.

I think this will be fixed by rebasing on top of #2326 - I'll rebase soon after I get test coverage up and confirm that is the case.

I can't seem to get the footprints to show up in my particular use case in the NOVT application. I'm not sure if it's my custom configuration or layout or something else. I'll keep checking.

Ok, let me know if there's anything I can do to help!

@melanieclarke
Copy link
Contributor

@kecnry - Perfect, thanks!

For the NOVT display, it looks like it's a configuration issue. If I use the Imviz configuration without any customization, the footprints work fine. My footprints appear right on top of yours, with the same parameters, as they should! I'll sort out the config issue on my side.

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Patch coverage: 91.52% and project coverage change: +0.04% 🎉

Comparison is base (45b0127) 90.66% compared to head (a2eed6e) 90.71%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2341      +/-   ##
==========================================
+ Coverage   90.66%   90.71%   +0.04%     
==========================================
  Files         153      157       +4     
  Lines       17576    17969     +393     
==========================================
+ Hits        15935    16300     +365     
- Misses       1641     1669      +28     
Files Changed Coverage Δ
jdaviz/app.py 85.04% <ø> (ø)
jdaviz/core/template_mixin.py 90.13% <73.62%> (-0.88%) ⬇️
...configs/imviz/plugins/footprints/preset_regions.py 88.57% <88.57%> (ø)
...viz/configs/imviz/plugins/footprints/footprints.py 96.82% <96.82%> (ø)
jdaviz/configs/imviz/plugins/__init__.py 100.00% <100.00%> (ø)
...daviz/configs/imviz/plugins/footprints/__init__.py 100.00% <100.00%> (ø)
.../imviz/plugins/footprints/tests/test_footprints.py 100.00% <100.00%> (ø)
jdaviz/configs/imviz/plugins/viewers.py 90.50% <100.00%> (+0.71%) ⬆️
jdaviz/core/marks.py 90.32% <100.00%> (+0.32%) ⬆️
jdaviz/core/user_api.py 92.85% <100.00%> (+0.12%) ⬆️

... and 1 file with indirect coverage changes

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

@kecnry kecnry force-pushed the plugin-footprints branch 2 times, most recently from 982134f to 36e1e87 Compare August 8, 2023 18:12
@kecnry
Copy link
Member Author

kecnry commented Aug 8, 2023

Few open questions to still consider during review:

  • consider renaming plugin to "overlays" or "regions" for future expansion ("From File..." or API import of regions support, etc) (will keep the plugin name but generalize the API)
  • decide what to do with pysiaf dependency (currently does not get installed with jdaviz, but plugin will be disabled until it is manually installed)
  • finalize list of apertures (and possibly make user-selectable?), including aperture used for centering
  • decide whether to have NIRCam:short vs long or a separate "path" dropdown that is only applicable for NIRCam (could use Plugin user API: inapplicable attrs #2347) (will keep as-is)
  • follow-up tickets for any work needed when ENH: Image rotation via WCS-only layers #2179 is rebased on top of this (footprint WCS-mapping will need to be updated on change to reference data)

@kecnry kecnry marked this pull request as ready for review August 8, 2023 18:31
@pllim
Copy link
Contributor

pllim commented Aug 8, 2023

I thought we agreed to bundle footprints data files and not rely on pysiaf at all? All we need is the vector points for polygons, no?

@kecnry
Copy link
Member Author

kecnry commented Aug 8, 2023

I thought we agreed to bundle footprints data files and not rely on pysiaf at all? All we need is the vector points for polygons, no?

We would also need a replacement for pysiaf.utils.rotations.attitude if we are to move the data locally and try to remove pysiaf as a dependency entirely.

@pllim
Copy link
Contributor

pllim commented Aug 8, 2023

Just these 12 lines? I'd rather we bundle this and throw in the pysiaf license here as acknowledgment than requiring the whole package.

    v2d = v2 / 3600.0
    v3d = v3 / 3600.0

    # Get separate rotation matrices
    mv2 = rotate(3, -v2d)
    mv3 = rotate(2, v3d)
    mra = rotate(3, ra)
    mdec = rotate(2, -dec)
    mpa = rotate(1, -pa)

    # Combine as mra*mdec*mpa*mv3*mv2
    m = np.dot(mv3, mv2)
    m = np.dot(mpa, m)
    m = np.dot(mdec, m)
    m = np.dot(mra, m)

    return m

p.s. Do they mean "altitude" instead of "attitude"?

kecnry added 19 commits August 14, 2023 08:15
* ability to set (and update) a list traitlet in the plugin which can then be used to control visibilities of UI elements, but also can be passed to the user API to disable access to those traitlets (or methods)
* will also be useful in other plugins (especially plot options)
* directly from NOVT API docs
* currently with a fixed preset of apertures plotted
* no longer needed in this plugin now that instruments are all generalized to take the same input arguments.  Will include as a separate PR to use elsewhere (or if/when this is extended to support more than just JWST instruments)
* fixes color reverting when renaming footprint
* lcviz still needs callbacks AFTER the selection is changed
* decided to keep the plugin named "Footprints" for now so that it's more easily discoverable.  But at least this way the API won't feel forced when we add more flexibility in the future.
* API calls to traitlets will now update in real-time (even if the plugin is closed) but just won't show the mark.  Toggles to is_active will now only change the visibility (still could result in flickering for extreme browser throttling, but at least won't have expensive calls that would exaggerate the problem)
* especially useful with reference data changing since the defaults were set internally
(unless there is only a single image...)
@rosteen
Copy link
Collaborator

rosteen commented Aug 14, 2023

The footprints shouldn't care that linking is set to Pixel if there's only one dataset loaded in the viewer, right? Right now the footprints plugin remains disabled even if I unload all but one image from the viewer:

Screenshot 2023-08-14 at 8 58 28 AM

@kecnry
Copy link
Member Author

kecnry commented Aug 14, 2023

The footprints shouldn't care that linking is set to Pixel if there's only one dataset loaded in the viewer, right?

That's a good point - right now I do this logic based on how many are in the app's data collection. Alternatively I guess we could have the viewer dropdown to filter based on the number loaded and the linking type, but maybe it makes more sense to push that down the road to the work to better support the pixel-linked case (which in turn is waiting on the rotation work to get merged which should simplify this greatly and probably would mean removing a lot of these guardrails anyways). If you're ok with that, I'll add a comment to that ticket 🐱 so that we can consider this case as well.

@rosteen
Copy link
Collaborator

rosteen commented Aug 14, 2023

If we're potentially removing guardrails later then I'd be fine with this case being future work, as long as you add the comment to the appropriate ticket. In that case, consider my already green review to be extra green.

@kecnry
Copy link
Member Author

kecnry commented Aug 14, 2023

Yes, I think we definitely want to support the pixel-linking case better in the future, its just really not clear how to do so now in a way that will still be compatible with the ongoing rotation work, so I think for now very conservative guardrails make sense so that we can move forward with other planned work for this plugin, and I've added your and @pllim's comments so we make sure we support all (possible) use-cases for pixel-linking in a hopefully self-consistent and intuitive way down the road.

Thanks everyone for the very useful thoughts and reviews!

@kecnry kecnry merged commit 0c97b76 into spacetelescope:main Aug 14, 2023
@kecnry kecnry deleted the plugin-footprints branch August 14, 2023 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Explanation of code and concepts imviz Ready for final review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants