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

EXP: glupyter implementation on abstract class #131

Closed
wants to merge 11 commits into from

Conversation

pllim
Copy link
Member

@pllim pllim commented Feb 24, 2021

This builds on #126 (the abstract class) to implement an additional backend using glue-jupyter and bqplot-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:

  • Glue toolbar cannot be displayed because ipywidgets.VBox only accept basic widgets as children.
  • Glue data collection needs to be cleared before loading new data into the same viewer or APIs like w.stretch = 'log' won't work properly (no error but nothing happens on display).

References:

TODO

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]
@pllim pllim added the enhancement New feature or request label Feb 24, 2021
Copy link
Member

@astrofrog astrofrog left a 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
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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):
Copy link
Member

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):
Copy link
Member

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?

Copy link
Member Author

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):
Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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?
Copy link
Member

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?

Copy link
Member Author

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... 💭

Base automatically changed from master to main March 9, 2021 22:47
@mwcraig
Copy link
Member

mwcraig commented Jun 30, 2021

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 BqplotImageView from glue-jupyter. The other uses the mouse demo notebook from https://github.com/glue-viz/bqplot-image-gl so it is displaying a bqplot figure using the ImageGL mark. In the glue-baed version there is considerable lag when zooming out or panning.

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

glupyter demo

glupyter_demo

bqplot/ImageGL direct demo

bqplot_image_gl_demo

@pllim
Copy link
Member Author

pllim commented Jun 30, 2021

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."

@pllim
Copy link
Member Author

pllim commented Jun 30, 2021

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.

@mwcraig
Copy link
Member

mwcraig commented Jun 30, 2021

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.

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.

@pllim
Copy link
Member Author

pllim commented Jun 30, 2021

@mwcraig , there is also an unresolved comment here: #93 (comment)

@pllim
Copy link
Member Author

pllim commented Jun 16, 2023

Most of the work ended up in Jdaviz. This is no longer relevant.

@pllim pllim closed this Jun 16, 2023
@pllim pllim deleted the abstract-class-glupyter branch June 16, 2023 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants