Skip to content

Instantly share code, notes, and snippets.

@ChrisBeaumont
Last active August 29, 2015 14:10
Show Gist options
  • Save ChrisBeaumont/e8d00fbfbb0af3a02aac to your computer and use it in GitHub Desktop.
Save ChrisBeaumont/e8d00fbfbb0af3a02aac to your computer and use it in GitHub Desktop.
MOS demo

Demo for thinking about how to integrate lists of spectra with Glue.

Setup

This demo requires using the in-development "table" branch of GitHub. The best way to set this up is to install Glue in "development" mode:

Checkout glue source code from github:

git clone https://github.com/glue-viz/glue.git
cd glue
git remote update
git checkout table
python setup.py develop

Confirm that you are now using the development version of Glue by cd ~/, starting python, and running

import glue
print glue

The output path should point directly to the glue source code directory, and not something like .../python2.7/site-packages/.... If it doesn't, delete the Glue directory output from this line, and repeat

At this point, Glue will always import from the source code in the Git directory, meaning changes to that directory immediately propagate

Data

Download the http://www2.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/data/pub/GSA-SV/GN-2001B-SV-101 directory, untar it, and cd into GN-2001B-SV-101/proc_logs. The view.py script depends upon NGC6940.fits and mrgN20010813S106_add.fits

Using

Running view.py starts Glue with 2 datasets: an image (normal 2D image), and spectra (a catalog of spectra and associated information. You can Overplot the spectra on the image by dragging the spectra dataset on an image widget, as normal. You can also look at a tabular view of spectra using the Table viewer. The last column of that viewer shows a bunch of 1D data cells, which contain the actual spectral information. Highlighting a set of them and hitting v will display them as spectra.

That's about all it does for now. I don't love the way the spectra are stored in this data set, so I'd like to think of better ways to get that to work. Input on typical datasets and usecases would help

from astropy.io import fits
import numpy as np
from glue.core import Data, Component
from glue import qglue
from glue.core.data_factories import load_data
hdul = fits.open('NGC6940.fits')
spec = np.dtype([('spec', np.float, (3108,))])
d = Data(label='NGC6940')
cat = hdul[1].data
for name in cat.names:
d.add_component(cat[name], name)
specs = np.zeros(d.shape[0], dtype=spec)
for i, h in enumerate(hdul[2:]):
specs['spec'][i] = h.data
d.add_component(Component(specs), 'spec')
d2 = load_data('mrgN20010813S106_add.fits')
def same(*args):
return args
links = [(['image.World 0'], ['spectra.DEC'], same, same),
(['image.World 1'], ['spectra.RA'], same, same)]
qglue(spectra=d, image=d2, links=links)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment