def test_heatmap_recipe(self): source = ServerDataSource(data_url="fn://bivariate", owner_username="******") plot = square('A', 'B', source=source, plot_width=600, plot_height=400, title="Test Title") plot2 = ar_downsample.heatmap(plot, palette="Reds9", reserve_val=0, points=True, client_color=True, title="Test Title 2") source2 = self._find_source(plot2) self.assertEquals("Test Title 2", plot2.title) self.assertEquals(type(source2), ServerDataSource) transform = source2.transform self.assertEquals(type(transform['info']), ar_downsample.Const) self.assertEquals(type(transform['agg']), ar_downsample.Count) self.assertEquals(type(transform['shader']), ar_downsample.Seq) self.assertEquals(transform['shader'].out, "image")
def test_replot_result_type(self): ar_downsample._loadAR() source = ServerDataSource(data_url="fn://bivariate", owner_username="******") plot = square('A', 'B', source=source) expected = { "image": "Image", "image_rgb": "ImageRGBA", "multi_line": "MultiLine" } shaders = dict() for name in dir(ar_downsample): item = getattr(ar_downsample, name) if isinstance(item, ar_downsample.Shader): shaders[item] = item.out for shader_class in shaders: shader = shader_class() rslt = ar_downsample.replot(plot, shader=shader) self.assertEquals( expected[shader.out], self._glyphspec(rslt)['type'], "Error with {0}. Expected {1}, recieved {2}".format( str(shader_class), expected[shader.out], self._glyphspec(rslt)))
def data_source(self, name, dataframe=None, array=None): if dataframe is not None: fname = self._prep_data_source_df(name, dataframe) target_name = name + ".pandas" else: fname = self._prep_data_source_numpy(name, array) target_name = name + ".table" url = urljoin(self.root_url, "bokeh/data/upload/%s/%s" % (self.username, target_name)) with open(fname) as f: result = self.http_session.post(url, files={'file': (target_name, f)}) return ServerDataSource(owner_username=self.username, data_url=result.content)
def data_source(self, name, dataframe=None, array=None): """Makes a server data source and uploads it to the server The server must be configured with a data directory for this to work """ if dataframe is not None: fname = self._prep_data_source_df(name, dataframe) target_name = name + ".pandas" else: fname = self._prep_data_source_numpy(name, array) target_name = name + ".table" url = urljoin(self.root_url, "bokeh/data/upload/%s/%s" % (self.username, target_name)) with open(fname) as f: result = self.http_session.post(url, files={'file' : (target_name, f)}) return ServerDataSource(owner_username=self.username, data_url=result.content)
def test_replot_remove(self): self.assertIsNotNone(self.bokeh_server, "Server failed to start, cannot tests") ar_downsample._loadAR() output_server("Census") source = ServerDataSource(data_url="fn://bivariate", owner_username="******") plot = square('A', 'B', source=source) ar_downsample.replot(plot, remove_original=False) self.assertTrue(plot in curdoc().context.children, "Not retained") ar_downsample.replot(plot, remove_original=True) self.assertTrue(plot not in curdoc().context.children, "Not removed") try: ar_downsample.replot(plot, remove_original=True) except: self.assertTrue(False, "Error reploting plot not in curdoc")
def make_object(): source = ServerDataSource(data_url="IonXpress_004_rawlib.sam", owner_username="******", transform={ 'resample': 'genomic_coverage', 'primary_column': 'coverage', 'domain_name': 'chr5' }, data={}) x_range = Range1d(start=0, end=249250621) plot1 = line('chr5', 'counts', tools="pan,wheel_zoom,box_zoom,reset,previewsave", plot_width=800, plot_height=350, source=source, x_range=x_range) plot2 = make_plot(x_range) return VBox(children=[plot1, plot2])
def test_contour_recipe(self): source = ServerDataSource(data_url="fn://bivariate", owner_username="******") plot = square('A', 'B', source=source, plot_width=600, plot_height=400, title="Test Title") plot2 = ar_downsample.contours(plot, title="Contour") source2 = self._find_source(plot2) self.assertEquals("Contour", plot2.title) self.assertEquals(type(source2), ServerDataSource) transform = source2.transform self.assertEquals(type(transform['info']), ar_downsample.Const) self.assertEquals(type(transform['agg']), ar_downsample.Count) self.assertEquals(type(transform['shader']), ar_downsample.Seq) self.assertEquals(transform['shader'].out, "multi_line")
def test_replot_property_transfer(self): self.assertIsNotNone(self.bokeh_server, "Server failed to start, cannot tests") ar_downsample._loadAR() output_server("Census") source = ServerDataSource(data_url="fn://bivariate", owner_username="******") plot_width = 612 plot_height = 408 plot_title = "Test title" plot = square('A', 'B', source=source, plot_width=plot_width, plot_height=plot_height, title=plot_title) ar_plot = ar_downsample.replot(plot) self.assertEquals(ar_plot.plot_width, plot_width, "Plot width not transfered") self.assertEquals(ar_plot.plot_height, plot_height, "Plot height not transfered") self.assertEquals(ar_plot.title, plot_title, "Plot title not transfered") plot_width = 612 plot_height = 408 plot_title = "Test title" ar_plot = ar_downsample.replot(plot, title=plot_title, plot_width=plot_width, plot_height=plot_height) self.assertEquals(ar_plot.plot_width, plot_width, "Plot width override failed") self.assertEquals(ar_plot.plot_height, plot_height, "Plot height override failed") self.assertEquals(ar_plot.title, plot_title, "Plot title override failed")
def test_source(self): ar_downsample._loadAR() source = ServerDataSource(data_url="fn://bivariate", owner_username="******") plot = square('A', 'B', source=source) agg = ar_downsample.CountCategories() info = ar_downsample.Const(val=1) shader = ar_downsample.InterpolateColor() new_source = ar_downsample.source(plot, agg=agg, info=info, shader=shader) self.assertIsNotNone(new_source.transform) trans = new_source.transform self.assertEquals(trans['resample'], 'abstract rendering') self.assertEquals(trans['agg'], agg) self.assertEquals(trans['info'], info) self.assertEquals(trans['shader'], shader) self.assertEquals(trans['glyphspec'], self._glyphspec(plot)) self.assertEquals(trans['points'], False)
N = 1000 x = np.linspace(0, 10, N) y = np.linspace(0, 10, N) xx, yy = np.meshgrid(x, y) d = np.sin(xx) * np.cos(yy) output_server("remote_image") source = ServerDataSource(data_url="/defaultuser/array.table/array", owner_username="******", data={ 'x': [0], 'y': [0], 'global_x_range': [0, 10], 'global_y_range': [0, 10], 'global_offset_x': [0], 'global_offset_y': [0], 'dw': [10], 'dh': [10], 'palette': ["Spectral-11"] }) image(source=source, image="image", x="x", y="y", dw="dw", dh="dh", width=200, height=200,
# The plot server must be running # Go to http://localhost:5006/bokeh to view this plot import numpy as np from bokeh.plotting import * from bokeh.objects import ServerDataSource """ In order to run this example, you have to execute ./bokeh-server -D remotedata the remote data directory in the bokeh checkout has the sample data for this example In addition, you must install ArrayManagement from this branch (soon to be master) https://github.com/ContinuumIO/ArrayManagement """ output_server("remotedata") source = ServerDataSource(data_url="/defaultuser/AAPL.hdf5", owner_username="******") line('date', 'close', x_axis_type="datetime", color='#A6CEE3', tools="pan,wheel_zoom,box_zoom,reset,previewsave", source=source, legend='AAPL') show()
from bokeh.plotting import square, output_server, show from bokeh.objects import ServerDataSource import bokeh.transforms.ar_downsample as ar """ In order to run this example, you have to execute ./bokeh-server -D remotedata the remote data directory in the bokeh checkout has the sample data for this example In addition, you must install ArrayManagement from this branch (soon to be master) https://github.com/ContinuumIO/ArrayManagement """ output_server("Census") # 2010 US Census tracts source = ServerDataSource(data_url="/defaultuser/CensusTracts.hdf5", owner_username="******") plot = square('LON', 'LAT', source=source, plot_width=600, plot_height=400, title="Census Tracts") ar.heatmap(plot, palette=["Reds-9"], reserve_val=0, points=True, client_color=True, title="Census Tracts (Client Colors)") ar.heatmap(plot, low=(255, 200, 200),
import numpy as np from bokeh.plotting import square, output_server, image, show from bokeh.objects import ServerDataSource import bokeh.transforms.ar_downsample as ar output_server("abstractrender") source = ServerDataSource(data_url="fn://gauss", owner_username="******") plot = square('oneA', 'oneB', color='#FF00FF', source=source) #Server-side colored heatmap ar.heatmap(plot, spread=3, transform=None, title="Server-rendered, uncorrected") ar.heatmap(plot, spread=3, transform="Log", title="Server-rendered, log transformed") ar.heatmap(plot, spread=3, title="Server-rendered, perceptually corrected") ar.replot(plot, agg=ar.Count(), info=ar.Const(val=1), shader=ar.Spread(factor=3) + ar.Cuberoot() + ar.InterpolateColor(low=(255, 200, 200), high=(255, 0, 0)), points=True, title="Manually process: perceptually corrected", reserve_val=0) # Client-side colored heatmap