-
Notifications
You must be signed in to change notification settings - Fork 74
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
viewer user-APIs exposing zoom/limit options #2563
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2563 +/- ##
==========================================
- Coverage 91.47% 91.46% -0.01%
==========================================
Files 160 160
Lines 19438 19477 +39
==========================================
+ Hits 17780 17815 +35
- Misses 1658 1662 +4 ☔ View full report in Codecov by Sentry. |
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.
In general, if we want to expose API to users, we need to define the API in concepts that users understand. If I were a naive user, I won't know at a glance what x_min
and x_max
is supposed to be. I would only care about zooming to a feature of interest, say, between 5000-6000 Angstrom (which might or might not be the unit the viewer is currently displaying).
if isinstance(self, AstrowidgetsImageViewerMixin): | ||
expose = ['zoom', 'zoom_level'] | ||
else: | ||
expose = ['set_lims'] |
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 set_lims
and not set_limits
?
Also, is this unit aware? What if data of native different units are loaded? Or does this only care about the currently displayed units?
Would set_spectral_axis_limits
and set_flux_limits
make more sense as separate methods for 1D spectrum viewer? Though I am not sure about the 2D spectrum viewer or the Mosviz table viewer.
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 set_lims and not set_limits?
No good reason, that's what we have in the plugin plots, but if we would prefer limits, we can change them both here, I don't think that is considered public API.
Also, is this unit aware? What if data of native different units are loaded? Or does this only care about the currently displayed units?
This is axes limits (based on the current axes units) - if there is no opposition to this, I'll update the docstring accordingly and throw errors for passing quantities. We could of course support quantities in the future by converting within the method, I can see how that would be useful. (EDIT: docstring and type-check added).
Mosviz table viewer.
Good point - I need to either have the table viewer not inherit this method or at least exclude it from the user API. (EDIT: done).
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 set_lims and not set_limits?
Glue does use reset_lims
(not limits), so I think that is where the plot options API adopted this. (Similarly for the choice of x_min
vs xmin
to match glue-state).
I don't know if that's true. I think setting limits on a viewer is a common thing and is useful to be able to set specific units from the notebook for reproducible workflows (this is the exact use-case that motivated this PR). We can of course create more methods that automate the selection of limits though. |
Reproducible workflow in notebook cells that can be run out of order is... ambitious. What if someone run an extra cell to change the viewer unit, and then run the API call with the numbers for the previous unit? |
The same could be said about any API command. They do what they say they do, if you add something in between, you will get different results, that is ok and expected. |
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'm ambivalent about set_lims
vs set_limits
but otherwise I think this is a net positive. It's nice to have such simple access to the viewers!
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.
Need change log and maybe also tests?
Do we also need to update user docs?
@property | ||
def user_api(self): | ||
# default exposed user APIs. Can override this method in any particular viewer. | ||
if isinstance(self, BqplotImageView): |
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.
Hmm. What about Astrowidgets API?
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.
what about it?
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.
Should they be exposed here?
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 think this would be the place to expose them, but maybe not quite yet since you said they are still actively changing, and exposing them here would commit us to supporting/deprecating/etc?
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.
Hmm, I have to think about the implications here a bit more. It also won't do if we disallow people to use the API this way.
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.
It also won't do if we disallow people to use the API this way.
Can you elaborate what you mean?
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 know yet. Lemme try to use it. Will let you know soon. 😆
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.
See #2563 (review)
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.
This is pretty confusing when Astrowidgets API is involved. For example, this is the behavior with this PR as it currently stands:
imviz.default_viewer.stretch = "sqrt" # OK
imviz.default_viewer.stretch_options # Returns list of str
vv = imviz.viewers["imviz-0"] # As far as user is concerned, this is still default viewer
vv.stretch = "linear" # No error but does nothing
vv.stretch_options # Error
Is We probably could also forbid setting a non-existing attribute, but I'd argue that is out-of-scope for this PR as we should consider it for the plugins as well. |
To disallow Astrowidgets API now would be a step backward. I would say it is public as per @eteq's request. If anything is changed upstream, I would have to deprecate accordingly anyway to match those changes, regardless of this PR or not. |
See #2577 for preventing the case shown in your example. With that in place... would you rather we expose all of astrowidgets API here as well and have |
Yes. And since this would be the recommended way to access viewer API going forward, I also say in this PR, you should update the docs and notebooks. |
90e85fc
to
8e7dcb5
Compare
Ok, I've added in the astrowidgets methods/attributes for Imviz and have |
(I'll need to update a bunch of tests which used |
Sorry for the extra work, but if we want this to be public, might as well go all the way? 😬 |
729f810
to
28118cf
Compare
28118cf
to
848014c
Compare
* to use public API where possible, and otherwise go through ._obj
848014c
to
89db77e
Compare
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.
Example Imviz notebook works and diff LGTM. Thanks!
Remote timeout is unrelated but it did cancel the OSX job, so I restarted them to be sure. |
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.
Thank you for the improvements, looks good!
* viewer user-APIs exposing zoom/limit options * defer exposing astrowidgets API in cubeviz * no public API (yet) for table viewers * docstring and type-checks for set_lims * set_lims > set_limits * changelog and basic test coverage * include astrowidgets API * add blink_once and reset_limits to user API * update internal calls to default_viewer * to use public API where possible, and otherwise go through ._obj
Description
This pull request adds access to viewer user-APIs (in the same way that plugin user-APIs are handled) with access to
zoom
/zoom_level
(as well as all astrowidgets API methods that were previously available throughimviz.default_viewer
) for image viewers andset_lims(x_min=None, x_max=None, y_min=None, y_max=None)
for other viewers. This also pointimviz.default_viewer
to this user-API layer for consistency and to prevent accessing methods/attributes that are not currently considered public.In order to addzoom
/zoom_level
to image viewers in Cubeviz, this also adds the astrowidgets mixin to the image viewers in cubeviz.For example:
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.