Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

DQ support for Cubeviz #2817

Merged
merged 13 commits into from
Apr 26, 2024
Merged

DQ support for Cubeviz #2817

merged 13 commits into from
Apr 26, 2024

Conversation

bmorris3
Copy link
Contributor

@bmorris3 bmorris3 commented Apr 18, 2024

This PR follows #2767 to extend the DQ plugin for Cubeviz.

cubeviz-dq.mov

The plugin has only one difference from Imviz – it assumes that the flux-viewer is the only viewer that will contain the DQ layer. Since the DQ layer will have the same dimensions as the cube, I wanted to make sure no one ever tries to use the cube DQ in the spectrum viewer, for example.

The data dropdown menu offers the DQ layer as a child of the (single) cube loaded into flux-viewer.

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)? 🐱

@github-actions github-actions bot added cubeviz imviz plugin Label for plugins common to multiple configurations labels Apr 18, 2024
@bmorris3 bmorris3 added this to the 3.10 milestone Apr 18, 2024
@bmorris3 bmorris3 force-pushed the cubeviz-dq branch 3 times, most recently from 3787611 to 95fa409 Compare April 18, 2024 19:18
Copy link

codecov bot commented Apr 18, 2024

Codecov Report

Attention: Patch coverage is 93.58974% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 88.94%. Comparing base (a39a0fe) to head (95cf7f2).
Report is 16 commits behind head on main.

Files Patch % Lines
...nfigs/default/plugins/data_quality/data_quality.py 94.56% 5 Missing ⚠️
...z/configs/imviz/plugins/coords_info/coords_info.py 63.63% 4 Missing ⚠️
jdaviz/configs/cubeviz/plugins/parsers.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2817      +/-   ##
==========================================
+ Coverage   88.88%   88.94%   +0.05%     
==========================================
  Files         111      111              
  Lines       16983    17101     +118     
==========================================
+ Hits        15096    15211     +115     
- Misses       1887     1890       +3     

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

@bmorris3 bmorris3 marked this pull request as ready for review April 18, 2024 21:01
@kecnry
Copy link
Member

kecnry commented Apr 19, 2024

The data menu behavior is a little glitchy when adding another cube into the flux viewer (although maybe this is unrelated and just exposed by the new behavior here).

Screen.Recording.2024-04-19.at.7.48.32.AM.mov
Screen.Recording.2024-04-19.at.7.49.26.AM.mov

I'm also seeing the "background" of the flux viewer being white now whereas it was black before (and the uncertainty viewer is still black). Is this intentional/expected?

Unrelated (can also reproduce on main) but noticed in the video above: the moment map is showing rotated wrt the original cube 🤔

Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

Now that we're exposing this, we should probably at least have barebones plugin docs (and update the link in the plugin to point there instead of to plot options docs).

jdaviz/configs/cubeviz/cubeviz.yaml Outdated Show resolved Hide resolved
@bmorris3
Copy link
Contributor Author

@kecnry I'm not positive, but it may be possible the new white background in flux-viewer comes from glue-viz/glue#2482 with glue v0.20 – which version of glue are you using?

@kecnry
Copy link
Member

kecnry commented Apr 22, 2024

The white background does seem to have been introduced in 1.20 - is that a concern with that upstream PR or is it now the preferred behavior? Why does it only happen in the flux viewer and not the uncertainty viewer?

What is the expectation for support in other cube viewers (you did mention "it assumes that the flux-viewer is the only viewer that will contain the DQ layer" in the PR description, but the layer is available to load in the data menu)? This is the current behavior which is confusing (but fixing could probably also be a follow-up):

Screen.Recording.2024-04-22.at.8.26.37.AM.mov

Still also needs:

@bmorris3
Copy link
Contributor Author

The white background does seem to have been introduced in 1.20 - is that a concern with that upstream PR or is it now the preferred behavior? Why does it only happen in the flux viewer and not the uncertainty viewer?

RE @kecnry: The white background occurs in the flux-viewer but not the uncert-viewer because we're opting-in to the corrected glue behavior for DQ layers here:

dq_layer.composite._allow_bad_alpha = True

I didn't opt-in to this feature for all layers everywhere, but we can (and I'd argue that we should). Dark-mode users might complain with default-white out-of-bounds regions though. 🕶

@bmorris3
Copy link
Contributor Author

Here are the rendered DQ plugin docs in Imviz:

Screen Shot 2024-04-23 at 10 57 55

Comment on lines 143 to 145
for layer in uncert_viewer.layers:
layer.composite._allow_bad_alpha = True
layer.force_update()
Copy link
Contributor

Choose a reason for hiding this comment

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

Screen.Recording.2024-04-23.at.1.46.03.PM.mov

I think this is a result of the background preferences, and it may be a null point. The relative opacity of the DQ layer does make the SCI data less visualizable compared to the previous commits and having the less desirable background. I'm unsure of the usability requirements when someone is focused on looking at DQ and if they would be okay toggling the layer on and off through the data menu.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for these points. The DQ information is only useful if you can flip between science and DQ arrays, and see which science data may be affected by artifacts. I agree that it can be visually confusing to have both DQ and SCI open at the same, so we have the opacity slider and visibility in the data menu.

Copy link
Member

Choose a reason for hiding this comment

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

Is the "darkening" of the image due to the DQ layer "fixed" by the upstream changes to glue? Or does that only affect outside the bounds of the DQ layer?

@bmorris3
Copy link
Contributor Author

In 8118066, I added support for one DQ layer across multiple viewers:

cubeviz-dq-multiviewer.mov

@kecnry
Copy link
Member

kecnry commented Apr 24, 2024

Should changing the viewer update the UI to reflect the current state (rather than the latest state of the previously selected viewer)?

Screen.Recording.2024-04-24.at.7.34.51.AM.mov

Now that multi-viewer support exists, this would also probably want to handle mixed state... which is going to get quite complicated for the flags unless the machinery from plot options can be adopted here. We could either live with it as-is for now, or pull multi-viewer support out of this PR and into a follow-up where it can then be fully developed?

Screen.Recording.2024-04-24.at.7.38.02.AM.mov

@bmorris3
Copy link
Contributor Author

bmorris3 commented Apr 24, 2024

@kecnry Default select-all viewers implemented in 66800ba.

cubeviz-dq-all-viewers.mov

@gibsongreen
Copy link
Contributor

gibsongreen commented Apr 25, 2024

For the Science data dropdown, The SCI data has the associated DQ data. The ERR data does not. Should the ERR data populate in this dropdown if it doesn't have DQ data associated with it? Right now it does, and if I try to select it I get a TypeError.

While it doesn't result in a traceback, with this DQ layer, Flags 0 and 9 are the two that are relevant. This is somewhat the same idea as above, but would you want to see all of the Flags even if they don't relate to the DQ that is loaded at the time, or would it be best to only display the flags that are relevant to the DQ?

@gibsongreen
Copy link
Contributor

Screen.Recording.2024-04-25.at.10.16.35.AM.mov

If I have SCI and ERR data loaded into one viewer, I deselect the DQ when SCI is selected, and then display ERR then back to SCI, the DQ comes back on automatically. Should this default to be turned off unless it is set to be on?

@bmorris3
Copy link
Contributor Author

@gibsongreen:

Should this default to be turned off unless it is set to be on?

My opinion isn't very strong, but I prefer that DQ visibility "follows" the science layer by default. I accept though if anyone feels that's inconsistent with the hidden-by-default approach in cubeviz.

Should the ERR data populate in this dropdown if it doesn't have DQ data associated with it?

This is a good point! I've updated the PR in 9e92b40 to limit the science layer data dropdown menu only to data layers that are "roots" (no parents) and that have children. That excludes ERR but includes SCI.

In my view, the ERR array could (and one day should?) be considered a child of the science data, but we can save that for another day.

@gibsongreen
Copy link
Contributor

Screenshot 2024-04-25 at 3 44 57 PM

If I am in the uncertainty-viewer, I am able to have the ERR data and overlay the DQ data. I cannot do this in the flux-viewer with the ERR/DQ combination. Let's say I do the same thing only with a Moment Map/DQ combo, in either viewer DQ won't display with it. I'm looking at the parent/child relationship now to see if I can pinpoint this.

@bmorris3
Copy link
Contributor Author

Good catch, @gibsongreen! The parent visibility changes were being propagated in some cases and not in the one you noticed. I've fixed the logic in the visibility in c5c0a28 to cover this case.

Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

I really like the behavior now - thanks for iterating through all the feedback!

One thing I noticed (but isn't new in this PR), is that the tooltip to change the color says "Change the color of this list" - is "list" the right terminology here? Would "flag" be more intuitive?)

I also left a small number of small questions/suggestions for reusability - but many of them can probably be generalized later if needed.

Comment on lines +82 to +86
def is_image_viewer(viewer):
from jdaviz.configs.imviz.plugins.viewers import ImvizImageView
from jdaviz.configs.cubeviz.plugins.viewers import CubevizImageView

return isinstance(viewer, (ImvizImageView, CubevizImageView))
Copy link
Member

Choose a reason for hiding this comment

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

might be nice to move this into the ViewerSelect directly. There already is an is_image_viewer defined, although it doesn't currently allow for cube viewers. So maybe we can check the current uses for that to see if that can be extended to include either, or if we want a separate is_image_or_cube_viewer?

viewer_filter_names = [filt.__name__ for filt in self.viewer.filters]
if 'is_image_viewer' not in viewer_filter_names:
self.viewer.add_filter(is_image_viewer)
self.viewer._on_viewers_changed()
Copy link
Member

Choose a reason for hiding this comment

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

this is actually a bug in add_filters that I am also fixing in #2827.... if you want to do the same fix here (update add_filter to be self.filters = self.filters + [...] rather than +=) then we can remove this redundant line. We could also make add_filter smart enough to avoid duplication, and the you wouldn't need the if-statement of viewer_filter_names above at all 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

fix in the other PR is currently in this commit (although the link might break on a rebase):

        - self.filters += [filter for filter in filters]
        + self.filters = self.filters + [filter for filter in filters]

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've updated add_filter with your fix, and removed the _on_viewers_changed line above.

Comment on lines 95 to 131
selected_dq = self.dq_layer.selected_obj
selected_dq = self.get_dq_layers()
Copy link
Member

Choose a reason for hiding this comment

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

hmmm why doesn't selected_obj do what you want 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.

get_dq_layers did what I wanted and selected_obj didn't partly because I misunderstood the traceback that I was getting from selected_obj. It's clear to me now that this was because selected_obj can return types I wasn't expecting. In the next commit, I've added a property self.dq_layer_selected_flattened which just reorganizes the up the selected_obj output into the shape and types I expect.

Comment on lines 1440 to 1445
if self.filter_is_root:
# ignore layers that are children in associations:
def filter_is_root(data):
return self.app._get_assoc_data_parent(data.label) is None

# ignore layers that are children in associations:
self.add_filter(filter_is_root)
Copy link
Member

Choose a reason for hiding this comment

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

Just a note to self: I think this really needs to be refactored so that filters are passed directly to the init rather than all these boolean flags, but that can be follow-up since its not being introduced here (I also noticed this while working on #2827)

@gibsongreen
Copy link
Contributor

Screenshot 2024-04-25 at 3 44 57 PM If I am in the uncertainty-viewer, I am able to have the ERR data and overlay the DQ data. I cannot do this in the flux-viewer with the ERR/DQ combination. Let's say I do the same thing only with a Moment Map/DQ combo, in either viewer DQ won't display with it. I'm looking at the parent/child relationship now to see if I can pinpoint this.

With this updated commit, I am still able to reproduce this screenshot

@bmorris3
Copy link
Contributor Author

After 95cf7f2, comments from @kecnry and @gibsongreen have been addressed.

In particular, here's the updated behavior for the data menu, which prevents the user from selecting children of non-selected parent data, and explains itself:

cubeviz-dq-data-menu.mov

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.

I like the data menu update, very intuitive and informative to the user. Everything else looks good to me, great work!

@bmorris3 bmorris3 merged commit 1b72aef into spacetelescope:main Apr 26, 2024
16 checks passed
@bmorris3
Copy link
Contributor Author

Thanks both for the helpful reviews!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cubeviz imviz plugin Label for plugins common to multiple configurations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants