Created
July 16, 2015 17:42
-
-
Save ChrisBeaumont/d809ee9d24735925c273 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Load dendrograms into a Glue session | |
""" | |
from glue.core.data_factories import load_data | |
try: | |
# v>=0.5 | |
from glue.core.data_factories.dendro_loader import load_dendro | |
from glue.core.data_factories.tables import astropy_tabular_data | |
except ImportError: | |
# v<=0.4 | |
from glue.core.data_factories import load_dendro | |
from glue.core.data_factories import astropy_tabular_data | |
from glue.core import DataCollection | |
from glue.core.link_helpers import LinkSame | |
from glue.qt.glue_application import GlueApplication | |
from glue.core import Data, DataCollection, Component | |
from glue.core.link_helpers import LinkSame, LinkTwoWay | |
from glue.qt.glue_application import GlueApplication | |
from glue.qt.widgets import ScatterWidget, ImageWidget | |
from glue.qt.widgets.dendro_widget import DendroWidget | |
from glue.qt.widgets.image_widget import StandaloneImageWidget | |
from glue import qglue | |
import matplotlib | |
import numpy as np | |
from astropy import units as u | |
from astropy import coordinates | |
from astropy import wcs | |
from astropy.table import Table | |
from astropy.io import ascii | |
try: | |
from paths import mpath,apath,fpath,molpath,hpath | |
except ImportError: | |
hpath = lambda x:x | |
#load 2 datasets from files | |
dendrogram = load_dendro(hpath('DendroMask_H2CO303202.hdf5')) | |
dendro,h2cocube = dendrogram | |
h2cocube.label='H2CO 303202 Cube' | |
cube = load_data(hpath('APEX_H2CO_303_202_bl.fits')) | |
table = ascii.read(hpath('PPV_H2CO_Temperature.ipac'), format='ipac') | |
table['glon'] = table['lon'] - 360*(table['lon'] > 180) | |
table['xpix'] = table['x_cen'] # Glue "eats" these | |
table['ypix'] = table['y_cen'] # Glue "eats" these | |
catalog=Data(parent=table['parent'], label='Fitted Catalog') | |
#catalog=Data() | |
for column_name in table.columns: | |
cc = table[column_name] | |
uu = cc.unit if hasattr(cc, 'unit') else cc.units | |
if cc.name == 'parent': | |
cc.name = 'cat_parent' | |
column_name = 'cat_parent' | |
elif cc.name == 'height': | |
cc.name = 'cat_height' | |
column_name = 'cat_height' | |
elif cc.name == 'peak': | |
cc.name = 'cat_peak' | |
column_name = 'cat_peak' | |
nc = Component.autotyped(cc, units=uu) | |
catalog.add_component(nc, column_name) | |
# if column_name != 'parent' else '_flarent_' | |
dc = DataCollection(dendrogram) | |
dc.append(catalog) | |
dc.merge(dendro, catalog) | |
#dc = DataCollection([cube, dendrogram, catalog]) | |
#dc.merge(cube,h2cocube) | |
#h2cocube.join_on_key(dendro, 'structure', dendro.pixel_component_ids[0]) | |
#dc.merge(catalog, dendro) | |
# UNCOMMENT THIS LINE TO BREAK THE VIEWER (note added July 10: I don't really know what this comment means) | |
app = GlueApplication(dc) | |
cube_viewer = app.new_data_viewer(ImageWidget) | |
cube_viewer.add_data(h2cocube) | |
# link positional information | |
dc.add_link(LinkSame(h2cocube.id['structure'], dendro.id['_idx'])) | |
#dc.add_link(LinkSame(image.id['World y: DEC--TAN'], dendro.id['DEJ2000'])) | |
dc.add_link(LinkSame(cube.id['Galactic Longitude'], dendro.id['x_cen'])) | |
dc.add_link(LinkSame(cube.id['Galactic Latitude'], dendro.id['y_cen'])) | |
def ms_to_kms(x): return x/1e3 | |
def kms_to_ms(x): return x*1e3 | |
dc.add_link(LinkTwoWay(cube.id['Vrad'], dendro.id['v_cen'], ms_to_kms, kms_to_ms)) | |
scatter = app.new_data_viewer(ScatterWidget) | |
scatter.add_data(dendro) | |
scatter.yatt = dendro.id['temperature_chi2'] | |
scatter.xatt = dendro.id['r321303'] | |
dendview = app.new_data_viewer(DendroWidget) | |
dendview.add_data(dendro) | |
#start Glue | |
app.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment