<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Linking and brushing with bokeh
Linking and brushing is a powerful method for exploratory data analysis.
One way to create linked plots in the notebook is to use Bokeh.
Step1:  We will output to a static html file. 
The output_notebook() function can output to the notebook, 
but with 50,000 points it really slows down.
Step2:  See many examples of configuring plot tools at http
Step3:  Here we'll interact with Glue from the notebook.
Step4:  Now we have access to the data collection in our notebook
Step5:  Now go select the "Western arm" of the star-forming region (in Glue) and make a subset of it
Step6:  We can add something to our catalog and it shows up in Glue.
Step7:  We can define a new subset group here or in Glue
<ASSISTANT_TASK:>
Python Code:
import bokeh
import numpy as np
from astropy.table import Table
sdss = Table.read('data/sdss_galaxies_qsos_50k.fits')
sdss
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, gridplot, output_notebook, output_file, show
umg = sdss['u'] - sdss['g']
gmr = sdss['g'] - sdss['r']
rmi = sdss['r'] - sdss['i']
imz = sdss['i'] - sdss['z']
# create a column data source for the plots to share
source = ColumnDataSource(data=dict(umg=umg, gmr=gmr, rmi=rmi,imz=imz))
Explanation: Linking and brushing with bokeh
Linking and brushing is a powerful method for exploratory data analysis.
One way to create linked plots in the notebook is to use Bokeh.
End of explanation
output_file('sdss_color_color.html')
TOOLS = "pan,wheel_zoom,reset,box_select,poly_select,help"
# create a new plot and add a renderer
left = figure(tools=TOOLS, width=400, height=400, title='SDSS g-r vs u-g', webgl=True)
left.x('umg', 'gmr', source=source)
# create another new plot and add a renderer
right = figure(tools=TOOLS, width=400, height=400, title='SDSS i-z vs r-i')
right.x('rmi', 'imz', source=source)
p = gridplot([[left, right]])
show(p)
Explanation: We will output to a static html file. 
The output_notebook() function can output to the notebook, 
but with 50,000 points it really slows down.
End of explanation
#import glue
# Quick way to launch Glue
#from glue import qglue
#qglue()
Explanation: See many examples of configuring plot tools at http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html
Interacting with Glue
End of explanation
import astropy.io.fits as fits
hdu = fits.open('data/w5.fits')
hdu[0].header
from astropy.table import Table
w5catalog = Table.read('data/w5_psc.vot')
wisecat = Table.read('data/w5_wise.tbl', format='ipac')
%gui qt
#qglue(catalog=catalog, image=hdu, wisecat=wisecat)
from glue.core.data_factories import load_data
from glue.core import DataCollection
from glue.core.link_helpers import LinkSame
from glue.app.qt.application import GlueApplication
#load 2 datasets from files
image = load_data('data/w5.fits')
catalog = load_data('data/w5_psc.vot')
dc = DataCollection([image, catalog])
# link positional information
dc.add_link(LinkSame(image.id['Right Ascension'], catalog.id['RAJ2000']))
dc.add_link(LinkSame(image.id['Declination'], catalog.id['DEJ2000']))
#start Glue
app = GlueApplication(dc)
app.start()
Explanation: Here we'll interact with Glue from the notebook.
End of explanation
dc
dc[0].components
dc[0].id['Right Ascension']
Explanation: Now we have access to the data collection in our notebook
End of explanation
catalog = dc[1]
j_minus_h = catalog['Jmag'] - catalog['Hmag']
Explanation: Now go select the "Western arm" of the star-forming region (in Glue) and make a subset of it
End of explanation
catalog['jmh'] = j_minus_h
hmag = catalog.id['Hmag']
jmag = catalog.id['Jmag']
Explanation: We can add something to our catalog and it shows up in Glue.
End of explanation
jmhred = (jmag - hmag) > 1.5
dc.new_subset_group('j - h > 1.5', jmhred)
dc.subset_groups
dc.subset_groups[2].label
catalog.subsets
catalog.subsets[0]['Jmag']
mask = catalog.subsets[0].to_mask()
new_catalog = w5catalog[mask]
Explanation: We can define a new subset group here or in Glue
End of explanation
<END_TASK>