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

Preserve plot options when replacing data from a plugin #2288

Merged
merged 7 commits into from
Jul 13, 2023

Conversation

rosteen
Copy link
Collaborator

@rosteen rosteen commented Jul 6, 2023

This preserves a list of plot options when data is replaced from a plugin, for example when running model fitting a second time with the same output label. There was a decision to be made on whether to preserve percentile or vmin and vmax for images - I decided on the latter since it will be easier to see differences from the prior data.

Opening as draft since I need to add tests still.

@pllim pllim removed their request for review July 6, 2023 19:02
@pllim pllim added this to the 3.6 milestone Jul 6, 2023
@pllim pllim added the plugin Label for plugins common to multiple configurations label Jul 6, 2023
@pllim
Copy link
Contributor

pllim commented Jul 6, 2023

I am out of time for this sprint, so I removed myself from the review pool. FYI.

@rosteen rosteen marked this pull request as draft July 6, 2023 19:03
@rosteen rosteen marked this pull request as ready for review July 7, 2023 13:42
@codecov
Copy link

codecov bot commented Jul 7, 2023

Codecov Report

Patch coverage: 84.61% and project coverage change: +0.07 🎉

Comparison is base (4c859b7) 90.89% compared to head (658ee7b) 90.96%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2288      +/-   ##
==========================================
+ Coverage   90.89%   90.96%   +0.07%     
==========================================
  Files         152      152              
  Lines       17060    17173     +113     
==========================================
+ Hits        15506    15622     +116     
+ Misses       1554     1551       -3     
Impacted Files Coverage Δ
jdaviz/core/tools.py 86.44% <ø> (+0.25%) ⬆️
jdaviz/cli.py 27.90% <60.00%> (+7.90%) ⬆️
jdaviz/core/template_mixin.py 93.09% <88.88%> (+0.22%) ⬆️
...default/plugins/model_fitting/tests/test_plugin.py 99.56% <100.00%> (+0.03%) ⬆️

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

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.

Seems to work quite well! Just have a few small comments/concerns from looking through the diff.

Comment on lines +1917 to +1918
add_to_viewer_refs.append(viewer_ref)
add_to_viewer_vis.append(label in viewer_item['visible_layers'])
Copy link
Member

Choose a reason for hiding this comment

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

couldn't this result in duplicating the entry in the list if there are multiple layers? (I'm trying to think of what the consequences would be to test...)

Copy link
Collaborator Author

@rosteen rosteen Jul 7, 2023

Choose a reason for hiding this comment

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

Hmm, perhaps, you're right that this logic isn't perfectly equivalent to the previous one. How about just adding a break at the end of this else clause?

Copy link
Member

@kecnry kecnry Jul 7, 2023

Choose a reason for hiding this comment

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

I guess since you're only acting on the current viewer, only one layer should ever enter the else, so its probably fine (which explains why I couldn't find a way to break it in testing). It might be more obvious for future us though to do something like

layer = next((layer for layer in viewer.layers if layer.layer.label == label), None)
# everything that is currently in the else

(or maybe we should implement viewer.get_layer(label)?)

Comment on lines 1891 to 1895

# Note that we can only preserve one of percentile or vmin+vmax
preserve_attributes = ("color", "alpha", "bias", "linewidth", "stretch",
"v_min", "v_max", "cmap")

Copy link
Member

Choose a reason for hiding this comment

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

Is there any way to access these programmatically since different layer-types might have different options (thinking for image layers created in cubeviz, or scatter layers in lcviz where keeping this list up-to-date with upstream changes might be difficult and if we are ever short any entries, that could be quite confusing to the user). Maybe using layer.state.as_dict() and just hardcoding certain attributes to ignore instead (like the link to layer.state.layer)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are enough attributes in state that I think listing the ones to ignore would be more annoying than listing the ones we want. I do see the annoyance with needing to potentially update this (and I didn't think of scatter viewers in this list), but I don't see a good programmatic way to do it that is less annoying.

Copy link
Member

Choose a reason for hiding this comment

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

as_dict contains a lot less entries than dir(layer.state) though... we might only need to exclude ['attribute', 'layer']

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's still a pretty big list, and there's some stuff in there that I'm either not sure what it does and/or wasn't sure if we want to preserve it, e.g. c_min, c_max, levels - are these all contour things? And if so, do we want to preserve contour levels? I rate that as a solid maybe. Maybe it is alright to default to keeping everything but the two you mentioned though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Preserving contours might be a PO question.

Copy link
Member

Choose a reason for hiding this comment

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

ok, agreed, let's ask POs (cc @camipacifici). If it is a fixed list, then as-is works with me. If the default should be everything except a few, then I think it makes more sense to hardcode the exceptions than the inclusions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can safely preserve everything (including contour levels).
I do not know why 'attribute' and 'layer' should not be preserved, but I trust you all on this.

@haticekaratay
Copy link
Contributor

I have successfully run tests locally and manually tested the desired behavior. Everything looks good to me. Thanks!

@pllim
Copy link
Contributor

pllim commented Jul 10, 2023

@haticekaratay , do you want to officially approve? Thanks!

@rosteen
Copy link
Collaborator Author

rosteen commented Jul 11, 2023

@kecnry I switched to an ignore list for the attributes instead of an include list.

@rosteen
Copy link
Collaborator Author

rosteen commented Jul 11, 2023

Hmm, test failure looks real but I'm not sure why it's failing in 3.10 and not 3.9.

@pllim
Copy link
Contributor

pllim commented Jul 12, 2023

It is failing because of remote data test that is triggered only on that job, not because of Python version. FYI.

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.

LGTM once tests are green - thanks!

@rosteen
Copy link
Collaborator Author

rosteen commented Jul 13, 2023

Remaining (new) test failure is unrelated, due to an upstream change. Merging.

@rosteen
Copy link
Collaborator Author

rosteen commented Jul 13, 2023

Oh, and the codecov report seems to have picked up lines that weren't new in this PR for some reason.

@rosteen rosteen merged commit cc81032 into spacetelescope:main Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin Label for plugins common to multiple configurations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants