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 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_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 test_contour_recipie(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_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 hasattr(item, "out"): shaders[item] = getattr(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 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)
def test_heatmap_recipie(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=["Reds-9"], 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_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")
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), points=True, title="Census Tracts (Server Colors)") ar.contours(plot, title="ISO Contours") 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), points=True, title="Census Tracts (Server Colors)") ar.contours(plot, title="ISO Contours") show()
import numpy as np from bokeh.plotting import square, output_server, image, show from bokeh.models 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
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 #from bokeh.transforms import line_downsample output_server("abstractrender") source = ServerDataSource(data_url="fn://uniform", owner_username="******") plot = square('oneA','oneB',color='#FF00FF',source=source) # Simple heat-map: bin the counts ('tis the default configuration....) heatmap =ar.source(plot, palette=["Reds-9"]) image(source=heatmap, title="Heatmap", reserve_val=0, **ar.mapping(heatmap)) #image(source=heatmap, reserve_val=0, reserve_color=0xaaaaaa, **ar.mapping(heatmap)) ###Perceptually corrected heat-map. Cube-root then bin percepmap = ar.source(plot, shader=ar.Cuberoot(), palette=["Reds-9"]) image(source=percepmap, title="Perceptually corrected", reserve_val=0, **ar.mapping(percepmap)) ### Contours come in the same framework, but since the results of the shader are lines you use a different plotting function... #contour = ar.source(glyphs=plot, agg=ar.Count(), info=ar.Const(1), shader=ar.Contour(9)) #multi_line(source=countour, palette=["reds-9"]) # # ##Alternative: aggregator as an incomplete resampler #aggregator = ar.source(ar.count(), ar.const(1), ar.touches()) ### Aggregator is incomplete without shader and glyphs. Can add either to it #shader = ar.Cuberoot()+ar.Interpolate(0,9) + ar.Floor()
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 #from bokeh.transforms import line_downsample output_server("abstractrender") source = ServerDataSource(data_url="fn://gauss", owner_username="******") plot = square('oneA', 'oneB', color='#FF00FF', source=source) # Simple heat-map: bin the counts ('tis the default configuration....) heatmap =ar.source(plot, palette=["Reds-9"]) image(source=heatmap, title="Heatmap", reserve_val=0, **ar.mapping(heatmap)) #Perceptually corrected heat-map. Cube-root then bin percepmap = ar.source(plot, shader=ar.Cuberoot(), palette=["Reds-9"]) image(source=percepmap, title="Perceptually corrected", reserve_val=0, **ar.mapping(percepmap)) # Contours come in the same framework, but since the results of the shader are lines you use a different plotting function... colors = ["#C6DBEF", "#9ECAE1", "#6BAED6", "#4292C6", "#2171B5", "#08519C", "#08306B"] ar.replot(plot, title="ISO Contours", shader=ar.Contour(levels=len(colors)), line_color=colors) #""" #In order to run the 'stocks' example, you have to execute #./bokeh-server -D remotedata # #The remote data directory in the bokeh checkout has the sample data for this example
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 #from bokeh.transforms import line_downsample output_server("Census") #2010 US Census tracts source = ServerDataSource(data_url="/defaultuser/CensusTracts.hdf5", owner_username="******") plot = square( 'LON','LAT',source=source) heatmap = ar.source(plot, palette=["Reds-9"], points=True) image(source=heatmap, title="Census Tracts", reserve_val=0, plot_width=600, plot_height=400, **ar.mapping(heatmap)) show()
#aggregator = ar.source(ar.count(), ar.const(1), ar.touches()) ### Aggregator is incomplete without shader and glyphs. Can add either to it #shader = ar.Cuberoot()+ar.Interpolate(0,9) + ar.Floor() #image(source=plot+aggregator+shader, palette=["reds-9"]) ###Implement aggregator.__radd__ to get a plot and .__add__ to get a shader """ In order to run the 'stocks' 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 """ #Stock-data plotting #source = ServerDataSource(data_url="/defaultuser/AAPL.hdf5", owner_username="******") #plot = square('volume','close',color='#FF00FF',source=source) #percepmap = ar.source(plot, shader=ar.Cuberoot(), palette=["Reds-9"]) #image(source=percepmap, title="Perceptually corrected (Stocks)", reserve_val=0, **ar.mapping(percepmap)) #2010 US Census tracts source = ServerDataSource(data_url="/defaultuser/CensusTracts.hdf5", owner_username="******") plot = square( 'INTPTLONG','INTPTLAT',source=source) heatmap = ar.source(plot, palette=["Reds-9"]) image(source=heatmap, title="Census Tracts", reserve_val=0, **ar.mapping(heatmap)) show()