def display_graph_example(): """Display a simple (probabilistic) graphical model in the browser. """ d = DisplayNode() graph = { 'nodes': [{ 'name': 'A', 'type': 0 }, { 'name': 'B', 'type': 1 }, { 'name': 'C', 'type': 0 }, { 'name': 'D', 'type': 2 }], 'links': [{ 'source': 'A', 'target': 'B', 'type': 't1' }, { 'source': 'A', 'target': 'C', 'type': 't1' }, { 'source': 'C', 'target': 'D', 'type': 't2' }] } d.display_in_browser('graph', graph)
def display(self, axis=None, shrink=None, rotate=None, subsample_slices=None, scales=None, open_browser=None): if axis is None: axis = self._axis if shrink is None: shrink = self._shrink if rotate is None: rotate = self._rotate if subsample_slices is None: subsample_slices = self._subsample_slices if subsample_slices is None: subsample_slices = 1 if scales is None: scales = self._scales if open_browser is None: open_browser = self._open_browser if open_browser is None: open_browser = False D = DisplayNode() images = [] n = 0 N_slices = 0 for j in range(len(self.volumes)): N_slices += self.get_shape(j)[axis] self._progress_bar = ProgressBar(height='6px', width='100%%', background_color=C.LIGHT_GRAY, foreground_color=C.GRAY) for j in range(len(self.volumes)): if scales is None: scale = 255 / (self.get_data(j).max() + 1e-9) else: scale = scales[j] * 255 / (self.get_data(j).max() + 1e-9) images_inner = [] for i in range(0, self.get_shape(j)[axis], subsample_slices): im = self.export_image(j, i, axis, normalise=True, scale=scale, shrink=shrink, rotate=rotate) images_inner.append(im) n += 1 self._progress_bar.set_percentage(n * 100.0 / N_slices * subsample_slices) images.append(images_inner) return D.display('tipix', images, open_browser)
def display_image_example(): """Display an image in the browser using Openseadragon.js """ N = 512 N_tiles = 6 max_iter = 6 d = DisplayNode() print("Wait, generating awesome images .. ") image = Image.new("RGB",(N*N_tiles,N)) for i in range(N_tiles): print("%d / %d "%(i+1,N_tiles)) tile = polygon_fractal(n=i+3,imgx=N,imgy=N,maxIt=max_iter) image.paste(tile,(i*N,0)) d.display_in_browser('image',image)
def display_image_example(): """Display an image in the browser using Openseadragon.js """ N = 512 N_tiles = 6 max_iter = 6 d = DisplayNode() print "Wait, generating awesome images .. " image = Image.new("RGB",(N*N_tiles,N)) for i in range(N_tiles): print "%d / %d "%(i+1,N_tiles) tile = polygon_fractal(n=i+3,imgx=N,imgy=N,maxIt=max_iter) image.paste(tile,(i*N,0)) d.display_in_browser('image',image)
def display(self, axis=None, max_size=256, open_browser=None): if axis is None: axis = self._axis if open_browser is None: open_browser = self._open_browser if open_browser is None: open_browser = False D = DisplayNode() self._progress_bar = ProgressBar(height='6px', width='100%%', background_color=C.LIGHT_GRAY, foreground_color=C.GRAY) volume = self.volumes[0] #FIXME: optionally use other grid # make grid of regularly-spaced points box_min = volume.get_world_grid_min() box_max = volume.get_world_grid_max() span = box_max - box_min max_span = span.max() n_points = numpy.uint32(span / max_span * max_size) grid = volume.get_world_grid(n_points) n = 0 images = [] for index in range(len(self.volumes)): volume = self.volumes[index] resampled = volume.compute_resample_on_grid(grid).data self._resampled = resampled sequence = [] for slice_index in range(n_points[axis]): if axis == 0: a = numpy.float32(resampled[slice_index, :, :].reshape( (resampled.shape[1], resampled.shape[2]))) elif axis == 1: a = numpy.float32(resampled[:, slice_index, :].reshape( (resampled.shape[0], resampled.shape[2]))) else: a = numpy.float32(resampled[:, :, slice_index].reshape( (resampled.shape[0], resampled.shape[1]))) lookup_table = volume.get_lookup_table() im = self.__array_to_im(a, lookup_table) sequence.append(im.rotate(90)) #FIXME: make optional n += 1 self._progress_bar.set_percentage( n * 100.0 / (len(self.volumes) * max_size)) images.append(sequence) if len(images) == 1: return D.display('tipix', images[0], open_browser) else: return D.display('tipix', images, open_browser)
def display(self,scale=None,open_browser=False): data = self.data d = DisplayNode() images = [] progress_bar = ProgressBar(height='6px', width='100%%', background_color=C.LIGHT_GRAY, foreground_color=C.GRAY) if scale is not None: scale = scale*255.0/(data.max()+1e-12) else: scale = 255.0/(data.max()+1e-12) N_projections = self.data.shape[2] N_x = self.data.shape[0] N_y = self.data.shape[1] print "SPECT Projection [N_projections: %d N_x: %d N_y: %d]"%(N_projections,N_x,N_y) for i in range( N_projections ): images.append( self.to_image(data,i,scale=scale,absolute_scale=True) ) progress_bar.set_percentage(i*100.0/N_projections) progress_bar.set_percentage(100.0) return d.display('tipix', images, open_browser)
def display(self,scale=None,open_browser=False): data = self.data d = DisplayNode() images = [] progress_bar = ProgressBar(height='6px', width='100%%', background_color=LIGHT_GRAY, foreground_color=GRAY) if scale is not None: scale = scale * 255.0 / (data.max() + 1e-12) else: scale = 255.0 / (data.max() + 1e-12) N_projections = self.data.shape[2] N_x = self.data.shape[0] N_y = self.data.shape[1] print("SPECT Projection [N_projections: %d N_x: %d N_y: %d]" % (N_projections, N_x, N_y)) for i in range(N_projections): images.append(self.to_image(data, i, scale=scale, absolute_scale=True)) progress_bar.set_percentage(i * 100.0 / N_projections) progress_bar.set_percentage(100.0) return d.display('tipix', images, open_browser)
def display(self,axis=None, max_size=256, open_browser=None): if axis is None: axis = self._axis if open_browser is None: open_browser = self._open_browser if open_browser is None: open_browser = False D = DisplayNode() self._progress_bar = ProgressBar(height='6px', width='100%%', background_color=C.LIGHT_GRAY, foreground_color=C.GRAY) volume = self.volumes[0] #FIXME: optionally use other grid # make grid of regularly-spaced points box_min = volume.get_world_grid_min() box_max = volume.get_world_grid_max() span = box_max-box_min max_span = span.max() n_points = numpy.uint32(span / max_span * max_size) grid = volume.get_world_grid(n_points) n=0 images = [] for index in range(len(self.volumes)): volume = self.volumes[index] resampled = volume.compute_resample_on_grid(grid).data self._resampled = resampled sequence = [] for slice_index in range(n_points[axis]): if axis == 0: a = numpy.float32(resampled[slice_index,:,:].reshape((resampled.shape[1],resampled.shape[2]))) elif axis == 1: a = numpy.float32(resampled[:,slice_index,:].reshape((resampled.shape[0],resampled.shape[2]))) else: a = numpy.float32(resampled[:,:,slice_index].reshape((resampled.shape[0],resampled.shape[1]))) lookup_table = volume.get_lookup_table() im = self.__array_to_im( a, lookup_table ) sequence.append(im.rotate(90)) #FIXME: make optional n+=1 self._progress_bar.set_percentage(n*100.0/(len(self.volumes)*max_size)) images.append(sequence) if len(images)==1: return D.display('tipix', images[0], open_browser) else: return D.display('tipix', images, open_browser)
def display(self,axis=None,shrink=None,rotate=None,subsample_slices=None,scales=None,open_browser=None): if axis is None: axis = self._axis if shrink is None: shrink = self._shrink if rotate is None: rotate = self._rotate if subsample_slices is None: subsample_slices = self._subsample_slices if subsample_slices is None: subsample_slices=1 if scales is None: scales = self._scales if open_browser is None: open_browser = self._open_browser if open_browser is None: open_browser = False D = DisplayNode() images = [] n=0 N_slices = 0 for j in range(len(self.volumes)): N_slices += self.get_shape(j)[axis] self._progress_bar = ProgressBar(height='6px', width='100%%', background_color=C.LIGHT_GRAY, foreground_color=C.GRAY) for j in range(len(self.volumes)): if scales is None: scale = 255/(self.get_data(j).max()+1e-9) else: scale = scales[j]*255/(self.get_data(j).max()+1e-9) images_inner = [] for i in range(0,self.get_shape(j)[axis],subsample_slices): im = self.export_image(j,i,axis,normalise=True,scale=scale,shrink=shrink,rotate=rotate) images_inner.append(im) n+=1 self._progress_bar.set_percentage(n*100.0/N_slices*subsample_slices) images.append(images_inner) return D.display('tipix', images, open_browser)
def _repr_html_(self): d = DisplayNode() d.display('graph', self.make_graph_of_self() ) return d._repr_html_()
def display_geometry_example(): "Under development: webGL display based on three.js " d = DisplayNode() d.display_in_browser("three_cubes",{})
def _repr_html_(self): display_node = DisplayNode() return display_node.display('graph',self.export_dictionary())._repr_html_()
def display_in_browser(self): """Displays the graph in a web browser. """ display_node = DisplayNode() display_node.display_in_browser('graph',self.export_dictionary())
def display_graph_example(): """Display a simple (probabilistic) graphical model in the browser. """ d = DisplayNode() graph = {'nodes':[{'name': 'A', 'type': 0}, {'name': 'B', 'type': 1}, {'name': 'C', 'type': 0}, {'name': 'D', 'type': 2}], 'links': [{'source': 'A', 'target': 'B', 'type': 't1'}, {'source': 'A', 'target': 'C', 'type': 't1'},{'source': 'C', 'target': 'D', 'type': 't2'} ] } d.display_in_browser('graph',graph)