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
EXP: glupyter implementation on abstract class #131
Conversation
Separated out the Ginga implementation. Re-organized and updated tests.
TST: Update test matrix and added a test. DOC: Re-organized doc and notebooks. DOC: Update example notebooks
DOC: Cannot use automodapi for Ginga API because we need to inherit docstring. DOC: Do not display inherited members because too confusing. [ci skip]
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.
All the NotImplementedError
things are possible (though for the markers it will require a little bit of code to either keep track of the markers in this class or interface with a glue catalog dataset). Happy to provide examples for various parts of this if needed.
self._link_image_to_cb() | ||
|
||
def center_on(self, point): | ||
raise NotImplementedError # FIXME |
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.
You can find and set the current limits with viewer.state.x_min
, viewer.state.x_max
, viewer.state.y_min
and viewer.state.y_max
so you could use that to compute dx and dy (the field of view) then set e.g. viewer.state.x_min = point[0] - dx/2
and so on if point
is in pixel coordinates
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.
Given that the viewer size and display scale is already known, is it sufficient if I just set x_min
and y_min
and then let glupyter take care of recomputing the rest, or is that not a thing?
I am guessing, it takes x/y_min/max
that is out of range? Otherwise, I cannot center on edges.
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.
The math isn't quite right. It slowly zooms the image out.
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.
Okay. I think it is because I am setting only x_min
and y_min
and let it auto adjust for the max. Is that not the right way to do this?
def center_on(self, point): | ||
raise NotImplementedError # FIXME | ||
|
||
def offset_to(self, dx, dy, skycoord_offset=False): |
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.
Similar to center_on
raise NotImplementedError # FIXME | ||
|
||
@property | ||
def zoom_level(self): |
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.
you could get x_min/x_max/y_min/y_max as in center_on and compute the fraction of the image shown and return that as zoom level?
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 am surprised that zoom info isn't already built into Glue. You have a zoom/pan button after all.
raise NotImplementedError # FIXME | ||
|
||
@zoom_level.setter | ||
def zoom_level(self, value): |
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.
Again you can do this by setting x_min/x_max/y_min/y_max
|
||
@marker.setter | ||
def marker(self, value): | ||
raise NotImplementedError # FIXME |
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.
For all the marker stuff you could do it two ways - keep track of the markers in the astrowidgets layer and use the bqplot Scatter
class to show the markers (you can add/remove markers by setting the x
and y
properties on the scatter object). I can show you an example if needed. Another option would be to actually make the list of markers be a glue data object and add it to the image viewer as a normal glue dataset - the advantage of this is that it shows up in the image viewer layers and you can control the appearance of the markers. There is a glue message you can fire if you want to update the glue dataset to force the viewer to refresh so let me know if you decide to go that route.
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 the latter makes more sense. Currently in the Ginga implementation, it creates Ginga canvas objects, and then extracts them back from the Ginga canvas, so this is consistent.
What isn't clear to me is how you control the looks of the Glue markers. For example, how do I ask Glue to draw blue X or red circle? How do I only extract markers that are red circle? How do I extract all the markers irrespective of shape/color?
|
||
def get_markers_by_name(self, marker_name, x_colname='x', y_colname='y', | ||
skycoord_colname='coord'): | ||
raise NotImplementedError # FIXME |
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 be possible if the above is implemented (in both options)
def add_markers(self, table, x_colname='x', y_colname='y', | ||
skycoord_colname='coord', use_skycoord=False, | ||
marker_name=None): | ||
raise NotImplementedError # FIXME |
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.
Also possible
raise NotImplementedError # FIXME | ||
|
||
def remove_markers_by_name(self, marker_name): | ||
raise NotImplementedError # FIXME |
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.
Also possible
|
||
@property | ||
def autocut_options(self): | ||
raise NotImplementedError # FIXME: Does Glue support this? |
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 understand what this does but you can set the percentile values in glue to automatically determine the levels/cuts in the image viewer. Could you clarify what this should return?
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.
For Ginga, this is what happens:
>>> w.autocut_options
('minmax', 'median', 'histogram', 'stddev', 'zscale')
>>> w.cuts = 'zscale' # Automatically sets the cut levels according to this algorithm
But if this does not make sense for Glue (or other future backends), then maybe I'll take autocut_options
out of the abstract class and make it a Ginga-only option... 💭
I'm finally taking a look at this batch of PRs and decided to start with this one. There are two videos below, one with the implementation in this PR that uses the Is there a way to eliminate the lag in rendering in when zooming out or panning? (maybe an @astrofrog question since the answer is likely in glupyter demobqplot/ImageGL direct demo |
Re: lag -- It is the same problem as spacetelescope/jdaviz#564 and @astrofrog said there, "This is going to be harder to fix though we can try and profile it to see why it's slow. Essentially whenever you pan or zoom, we re-compute a fixed resolution buffer and send it to the front-end. We do this because for large images, sending the whole image to the GPU is not feasible. Essentially we behave a little like Google maps does. Having said this, we could imagine computing a buffer that extends beyond the current image limits so that the experience is a little nicer. I would personally advocate for that being a little lower priority compared to other features but it would be good to improve at some point." |
As for the abstract class, I am not sure how to proceed with this PR. I think @astrofrog disagree with some low level implementations here that would warrant refactor even on Ginga's implementation, so there is a high barrier. For now, we have decided on a "shim" over at Jdaviz. Also see spacetelescope/jdaviz#631 and related PRs over there. |
I might take another shot at it this week -- I have some time through SciPy to devote to it. I started with this PR because I found it easier to think about the base class after seeing a second implementation of the viewer. |
@mwcraig , there is also an unresolved comment here: #93 (comment) |
Most of the work ended up in Jdaviz. This is no longer relevant. |
This builds on #126 (the abstract class) to implement an additional backend using
glue-jupyter
andbqplot-image-gl
.Most of the changes are from #126 (they will go away once that PR is merged). The meat of this PR is in:
astrowidgets/glupyter.py
example_notebooks/glupyter/
Known limitations:
ipywidgets.VBox
only accept basic widgets as children.w.stretch = 'log'
won't work properly (no error but nothing happens on display).References:
TODO
click_center
flagclick_drag
flagscroll_pan
flag -- see if feat: compose MouseInteraction with other interacts glue-viz/bqplot-image-gl#45 workscenter_on()
offset_to()
zoom()
andzoom_level
autocut_options
pixel_offset
usage makes sensecursor
positioning still worksexample_notebooks/glupyter/
and polish up notebook narrativesglue-jupyter
(and maybebqplot-image-gl
too?) release before we can merge this, and also have to pin relevant minversions insetup.cfg