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

Feature request: to_glue #153

Merged
merged 8 commits into from
Nov 19, 2014
Merged

Conversation

keflavich
Copy link
Contributor

@ChrisBeaumont this is for you, maybe @astrofrog too since you made the successful one-off pvextractor widget.

Would it be possible to open a cube in Glue, or at least with the Glue quick-viewer, from within an existing session? I'm thinking of getting access to on-the-fly coordinate changes within glue, essentially, but starting from a regular old command line application.

@astrofrog
Copy link
Member

I've been thinking that the standalone PV extractor I put together could in fact be a cube viewer (so also have a panel for the spectral extractor) and so to_glue could open this up?

@keflavich
Copy link
Contributor Author

That's basically what I had in mind. I'll work on it if I finish real work today... =)

@ChrisBeaumont
Copy link

I'll work on it if I finish real work today... =)
ouch :)

There are several ways to start glue from the command line. The easiest is qglue http://www.glueviz.org/en/stable/glue_from_python.html#quickly-send-data-to-glue-with-qglue , though it doesn't let you pre-configure viewers. If you want to automatically add a cube view, you have to use something like this: http://www.glueviz.org/en/stable/data_viewer_options.html#programmatically-configuring-plots

@keflavich
Copy link
Contributor Author

@astrofrog @ChrisBeaumont WIP. It works so far in terms of sending data to a Glue application, but it has lots of problems:

  • the spectral axis is not WCS, even though the spatial axes are
  • there are a lot of warnings and logging messages popping up
  • it's not obvious how to send multiple cubes to the same glue app in a nice way - would be best to retrieve the current glue session if possible (the global one as opposed to the SpectralCube._glue_app)
  • Need to auto-open the image viewer

if data_collection is not None:
if name in data_collection:
name = name+"_"
data_collection[name] = result
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is wrong, but it was based off of http://www.glueviz.org/en/stable/glue_from_python.html#usage-examples. I guess catalog is not a DataCollection in that example but something else.

@ChrisBeaumont
Copy link

the spectral axis is not WCS, even though the spatial axes are

Can you elaborate on that -- is the problem that the cube is weird, or that Glue isn't displaying something properly, or...?

there are a lot of warnings and logging messages popping up

I'll take a look. Glue generates lots of logging messages anyways, so it might be benign, and we just need to send them someplace more quietly

it's not obvious how to send multiple cubes to the same glue app in a nice way - would be best to retrieve the current glue session if possible (the global one as opposed to the SpectralCube._glue_app)

return the GlueApplication object?

Need to auto-open the image viewer

The code will look something like

from glue.qt.widgets import ImageWidget
w = glue_app.new_data_viewer(ImageWidget, data=cube_data)

result.coords = coordinates_from_header(self.header)

comp = Component.autotyped(self)
result.add_component(comp, name)

Choose a reason for hiding this comment

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

I'm pretty sure add_component calls autotyped for you, so you can get rid of the line above and pass self in 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.

check

@keflavich
Copy link
Contributor Author

the spectral axis is not WCS, even though the spatial axes are

Can you elaborate on that -- is the problem that the cube is weird, or that Glue isn't displaying something properly, or...?

The slider shows 0...500, but the extracted spectrum is fine, so this is just an issue with the slider. Maybe this is the normal behavior, actually, I don't recall.

there are a lot of warnings and logging messages popping up

I'll take a look. Glue generates lots of logging messages anyways, so it might be benign, and we just need to send them someplace more quietly

Yes, this could be glue interacting with astropy's logging too.

it's not obvious how to send multiple cubes to the same glue app in a nice way - would be best to retrieve the current glue session if possible (the global one as opposed to the SpectralCube._glue_app)

return the GlueApplication object?

This is the problem I described above. For example:

In [2]: gapp = cube303m.to_glue()
Could not parse application stylesheet
UsageError: Invalid GUI request 'inline', valid ones are:['osx', 'qt4', None, 'glut', 'gtk3', 'pyglet', 'wx', 'none', 'qt', 'gtk', 'tk']
In [3]: 2014-10-09 18:22:28.424 python[76840:507] modalSession has been exited prematurely - check for a reentrant call to endModalSession:
/Users/adam/anaconda/envs/astropy27/lib/python2.7/site-packages/matplotlib/text.py:52: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if rotation in ('horizontal', None):
/Users/adam/anaconda/envs/astropy27/lib/python2.7/site-packages/matplotlib/text.py:54: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif rotation == 'vertical':

gapp
Traceback (most recent call last):
  File "<ipython-input-3-284230671efb>", line 1, in <module>
    gapp
NameError: name 'gapp' is not defined

In this case, Glue has started, but gapp is not even defined as a variable. Note that the above should read:

In [3]: gapp
Traceback (most recent call last):
  File "<ipython-input-3-284230671efb>", line 1, in <module>
    gapp
NameError: name 'gapp' is not defined

but there is other output cluttering the In [3]: prompt.

Need to auto-open the image viewer

The code will look something like

from glue.qt.widgets import ImageWidget
w = glue_app.new_data_viewer(ImageWidget, data=cube_data)

That works. Took me a while to figure out what cube_data was (it is result in this context, i.e. a Dataset)

@ChrisBeaumont
Copy link

NameError: name 'gapp' is not defined

Ah I think I know whats going on -- see glue-viz/glue#476

This is orthogonal to this PR, so I wouldn't worry about it for now.

@ChrisBeaumont
Copy link

The slider shows 0...500, but the extracted spectrum is fine, so this is just an issue with the slider.

Yeah that's the intended behavior (slider in pixel coordinates). Maybe it shouldn't be, I'm not sure.

@keflavich
Copy link
Contributor Author

The slider shows 0...500, but the extracted spectrum is fine, so this is just an issue with the slider.

Yeah that's the intended behavior (slider in pixel coordinates). Maybe it shouldn't be, I'm not sure.

It's fine as is, but it would be nice if both could be shown. Especially, for example, a velocity/frequency overlay on the image or titlebar or something of that sort.

@keflavich
Copy link
Contributor Author

So, this works now, but note the slew of warnings:

In [1]: cube = SpectralCube.read('/Users/adam/work/gc/apex/h2co_cubes/APEX_H2CO_303_202.fits')

In [2]: cube2 = SpectralCube.read('/Users/adam/work/gc/apex/h2co_cubes/APEX_H2CO_321_220.fits')

In [3]: gapp = cube.to_glue()
Could not parse application stylesheet
/Users/adam/anaconda/envs/astropy27/lib/python2.7/site-packages/matplotlib/text.py:52: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if rotation in ('horizontal', None):
/Users/adam/anaconda/envs/astropy27/lib/python2.7/site-packages/matplotlib/text.py:54: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif rotation == 'vertical':
UsageError: Invalid GUI request 'inline', valid ones are:['osx', 'qt4', None, 'glut', 'gtk3', 'pyglet', 'wx', 'none', 'qt', 'gtk', 'tk']
In [4]: cube._glue_app.data_collection[0]
Out[4]: Data (label: SpectralCube)

In [5]: cube2.to_glue(dataset=cube._glue_app.data_collection[0])
INFO:glue.core.hub:Broadcasting DataAddComponentMessage:
     Sent from: Data Set: SpectralCubeNumber of dimensions: 3
Shape: 500 x 200 x 1150
Components:
 0) SpectralCube
 1) Pixel z
 2) Pixel y
 3) Pixel x
 4) Vrad
 5) Galactic Latitude
 6) Galactic Longitude
 7) SpectralCube_
INFO:glue.core.hub:Broadcasting ComponentsChangedMessage:
     Sent from: Data Set: SpectralCubeNumber of dimensions: 3
Shape: 500 x 200 x 1150
Components:
 0) SpectralCube
 1) Pixel z
 2) Pixel y
 3) Pixel x
 4) Vrad
 5) Galactic Latitude
 6) Galactic Longitude
 7) SpectralCube_

Also, @ChrisBeaumont, the GUI is somewhat unresponsive right when I start up - I can't grab the corners to drag/expand the viewing window until I've clicked within the image or activated one of the buttons. Also, I can now reproduce the error I mentioned before, kinda (glue-viz/glue#424): right when the cubes open, they are weirdly downsampled.

@keflavich
Copy link
Contributor Author

@ChrisBeaumont assuming we can clean up some of the error messages etc., what's the next step in terms of writing tests?

@ChrisBeaumont
Copy link

it would be nice if both could be shown. Especially, for example, a velocity/frequency overlay on the image or titlebar or something of that sort.

The world velocity coordinates are shown along the bottom of the image view when you mouse hover. I've thought about adding a world label to the slider (although it won't have the option to switch between velocity/frequency, since I don't want to be too astro-specific in the UI)

@keflavich
Copy link
Contributor Author

The world velocity coordinates are shown along the bottom of the image view when you mouse hover. I've thought about adding a world label to the slider (although it won't have the option to switch between velocity/frequency, since I don't want to be too astro-specific in the UI)

Ah, OK. And it's fine to not have a switch in the default glue UI; I was thinking the next step for the SpectralCube->Glue viewer is to build a custom scroller with that capability.

@ChrisBeaumont
Copy link

assuming we can clean up some of the error messages etc., what's the next step in terms of writing tests?

I would add an keyword (at least for testing) that lets you run to_glue without actually opening+running the UI. Then, your tests can just check that the application has the proper datasets, viewers, etc. You can look at GlueApplication.data_collection and .data_viewers to check this.

@ChrisBeaumont
Copy link

glue-viz/glue#501 partially addresses the NameError issue you had before. Glue still hijacks the REPL once you start the UI, but that's only a problem after you stop the glue session, not before you start it. I'm trying to figure out how to address it (it's an IPython thing)

@keflavich
Copy link
Contributor Author

@ChrisBeaumont this has been sitting idle for a while and I don't really have time to dig into it; my side-sprint on the other PR was motivated by immediate need. Do you think this is mergeable or should we just leave it until we can make a reasonable test suite?

@ChrisBeaumont
Copy link

IMO this is straightforward + functional enough that you could merge it if you want.

keflavich added a commit that referenced this pull request Nov 19, 2014
@keflavich keflavich merged commit 841f208 into radio-astro-tools:master Nov 19, 2014
@keflavich keflavich deleted the to_glue branch November 19, 2014 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants