def _generate_plots(self): dynamic_plots = [] for kw in [dict(sheet=sheet) for sheet in self.sheets()]: sheet = kw['sheet'] views = topo.sim.views[sheet.name].Maps sv = SheetView(sheet.input_generator(), bounds=sheet.bounds) sv.metadata=AttrDict(timestamp=topo.sim.time()) if 'Activity' not in views: views['Activity'] = NdMapping((topo.sim.time(), sv)) views['Activity'].metadata = AttrDict(precedence=sheet.precedence, row_precedence=sheet.row_precedence, src_name=sheet.name, timestamp=topo.sim.time()) else: views['Activity'][topo.sim.time()] = sv channels = {'Strength': 'Activity','Hue':None,'Confidence':None} view = topo.sim.views[sheet.name].Maps view_dict = {'Strength':view,'Hue':view,'Confidence':view} ### JCALERT! it is not good to have to pass '' here... maybe a test in plot would be better dynamic_plots.append(make_template_plot(channels, view_dict, sheet.xdensity,sheet.bounds,self.normalize, name='')) return self._static_plots[:]+dynamic_plots
def __call__(self, **params): p = ParamOverrides(self, params) name = p.plot_template.keys().pop(0) plot = make_template_plot(p.plot_template, p.sheet.views.Maps, p.sheet.xdensity, p.sheet.bounds, p.normalize, name=p.plot_template[name]) fig = plt.figure(figsize=(5, 5)) if plot: bitmap = plot.bitmap isint = plt.isinteractive( ) # Temporarily make non-interactive for plotting plt.ioff() # Turn interactive mode off plt.imshow(bitmap.image, origin='lower', interpolation='nearest') plt.axis('off') for (t, pref, sel, c) in p.overlay: v = plt.flipud(p.sheet.views.Maps[pref].view()[0]) if (t == 'contours'): plt.contour(v, [sel, sel], colors=c, linewidths=2) if (t == 'arrows'): s = plt.flipud(p.sheet.views.Maps[sel].view()[0]) scale = int(np.ceil(np.log10(len(v)))) X = np.array([x for x in xrange(len(v) / scale)]) v_sc = np.zeros((len(v) / scale, len(v) / scale)) s_sc = np.zeros((len(v) / scale, len(v) / scale)) for i in X: for j in X: v_sc[i][j] = v[scale * i][scale * j] s_sc[i][j] = s[scale * i][scale * j] plt.quiver(scale * X, scale * X, -np.cos(2 * np.pi * v_sc) * s_sc, -np.sin(2 * np.pi * v_sc) * s_sc, color=c, edgecolors=c, minshaft=3, linewidths=1) p.title = '%s overlaid with %s at time %s' % (plot.name, pref, topo.sim.timestr()) if isint: plt.ion() p.filename_suffix = "_" + p.sheet.name self._generate_figure(p) return fig
def _generate_plots(self): dynamic_plots = [] for kw in [dict(sheet=sheet) for sheet in self.sheets()]: sheet = kw["sheet"] new_view = SheetView((sheet.input_generator(), sheet.bounds), sheet.name, sheet.precedence, topo.sim.time()) sheet.sheet_views["Activity"] = new_view channels = {"Strength": "Activity", "Hue": None, "Confidence": None} ### JCALERT! it is not good to have to pass '' here... maybe a test in plot would be better dynamic_plots.append( make_template_plot(channels, sheet.sheet_views, sheet.xdensity, sheet.bounds, self.normalize, name="") ) return self._static_plots[:] + dynamic_plots
def _generate_plots(self): dynamic_plots = [] for kw in [dict(sheet=sheet) for sheet in self.sheets()]: sheet = kw['sheet'] new_view = SheetView((sheet.input_generator(),sheet.bounds), sheet.name,sheet.precedence,topo.sim.time()) sheet.sheet_views['Activity']=new_view channels = {'Strength':'Activity','Hue':None,'Confidence':None} ### JCALERT! it is not good to have to pass '' here... maybe a test in plot would be better dynamic_plots.append(make_template_plot(channels,sheet.sheet_views, sheet.xdensity,sheet.bounds,self.normalize, name='')) return self._static_plots[:]+dynamic_plots
def __call__(self, **params): p=ParamOverrides(self,params) name=p.plot_template.keys().pop(0) plot=make_template_plot(p.plot_template, p.sheet.views.Maps, p.sheet.xdensity,p.sheet.bounds, p.normalize,name=p.plot_template[name]) fig = plt.figure(figsize=(5,5)) if plot: bitmap=plot.bitmap isint=plt.isinteractive() # Temporarily make non-interactive for plotting plt.ioff() # Turn interactive mode off plt.imshow(bitmap.image,origin='lower',interpolation='nearest') plt.axis('off') for (t,pref,sel,c) in p.overlay: v = plt.flipud(p.sheet.views.Maps[pref].view()[0]) if (t=='contours'): plt.contour(v,[sel,sel],colors=c,linewidths=2) if (t=='arrows'): s = plt.flipud(p.sheet.views.Maps[sel].view()[0]) scale = int(np.ceil(np.log10(len(v)))) X = np.array([x for x in xrange(len(v)/scale)]) v_sc = np.zeros((len(v)/scale,len(v)/scale)) s_sc = np.zeros((len(v)/scale,len(v)/scale)) for i in X: for j in X: v_sc[i][j] = v[scale*i][scale*j] s_sc[i][j] = s[scale*i][scale*j] plt.quiver(scale*X, scale*X, -np.cos(2*np.pi*v_sc)*s_sc, -np.sin(2*np.pi*v_sc)*s_sc, color=c, edgecolors=c, minshaft=3, linewidths=1) p.title='%s overlaid with %s at time %s' %(plot.name,pref,topo.sim.timestr()) if isint: plt.ion() p.filename_suffix="_"+p.sheet.name self._generate_figure(p) return fig
def _generate_plots(self): dynamic_plots = [] for kw in [dict(sheet=sheet) for sheet in self.sheets()]: sheet = kw['sheet'] views = topo.sim.views[sheet.name].maps sv = SheetView(sheet.input_generator(), bounds=sheet.bounds, metadata=AttrDict(timestamp=topo.sim.time())) if 'Activity' not in views: views['Activity'] = NdMapping( (topo.sim.time(), sv), precedence=sheet.precedence, row_precedence=sheet.row_precedence, src_name=sheet.name, timestamp=topo.sim.time()) else: views['Activity'][topo.sim.time()] = sv channels = { 'Strength': 'Activity', 'Hue': None, 'Confidence': None } view = topo.sim.views[sheet.name].maps view_dict = {'Strength': view, 'Hue': view, 'Confidence': view} ### JCALERT! it is not good to have to pass '' here... maybe a test in plot would be better dynamic_plots.append( make_template_plot(channels, view_dict, sheet.xdensity, sheet.bounds, self.normalize, name='')) return self._static_plots[:] + dynamic_plots
def setUp(self): ### Simple case: we only pass a dictionary to Plot() ### that does not belong to a Sheet: views = {} time = 0 metadata = AttrDict(timestamp=time) ### SheetView1: ### Find a way to assign randomly the matrix. self.matrix1 = zeros((10, 10), Float) + RandomArray.random((10, 10)) self.bounds1 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5))) sv = SheetView(self.matrix1, self.bounds1, metadata=metadata) self.sheet_view1 = NdMapping((None, sv), src_name='TestInputParam', precedence=0.1, row_precedence=0.1, cyclic_range=None, timestamp=time) self.key1 = 'sv1' views[self.key1] = self.sheet_view1 ### SheetView2: ### Find a way to assign randomly the matrix. self.matrix2 = zeros((10, 10), Float) + 0.3 self.bounds2 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5))) sv = SheetView(self.matrix2, self.bounds2, metadata=metadata) self.sheet_view2 = NdMapping((None, sv), src_name='TestInputParam', precedence=0.2, row_precedence=0.2, cyclic_range=None, timestamp=time) self.key2 = ('sv2', 0, 10) views[self.key2] = self.sheet_view2 ### SheetView3: ### Find a way to assign randomly the matrix. self.matrix3 = zeros((10, 10), Float) + RandomArray.random((10, 10)) self.bounds3 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5))) sv = SheetView(self.matrix3, self.bounds3, metadata=metadata) self.sheet_view3 = NdMapping((None, sv), src_name='TestInputParam', precedence=0.3, row_precedence=0.3, cyclic_range=None, timestamp=time) self.key3 = ('sv3', 0, 'hello', (10, 0)) views[self.key3] = self.sheet_view3 ### SheetView4: for testing clipping + different bounding box ### Find a way to assign randomly the matrix. self.matrix4 = zeros((10, 10), Float) + 1.6 self.bounds4 = BoundingBox(points=((-0.7, -0.7), (0.7, 0.7))) sv = SheetView(self.matrix4, self.bounds4, metadata=metadata) self.sheet_view4 = NdMapping((None, sv), src_name='TestInputParam', precedence=0.4, row_precedence=0.4, cyclic_range=None, timestamp=time) self.key4 = 'sv4' views[self.key4] = self.sheet_view4 self.view_dict = {'Strength': views, 'Hue': views, 'Confidence': views} ### JCALERT! for the moment we can only pass a triple when creating plot ### adding more sheetView to test when plot will be fixed for accepting ### as much as you want. # plot0: empty plot + no sheetviewdict passed: error or empty plot? ### JCALERT! It has to be fixed what to do in this case in plot.. ### disabled test for the moment. #self.plot0 = Plot((None,None,None),None,name='plot0') ### CATCH EXCEPTION plot_channels1 = {'Strength': None, 'Hue': None, 'Confidence': None} # plot1: empty plot self.plot1 = make_template_plot(plot_channels1, self.view_dict, density=10.0, name='plot1') plot_channels2 = { 'Strength': self.key1, 'Hue': None, 'Confidence': None } # plot2: sheetView 1, no normalize, no clipping self.plot2 = make_template_plot(plot_channels2, self.view_dict, density=10.0, name='plot2') plot_channels3 = { 'Strength': self.key1, 'Hue': self.key2, 'Confidence': None } # plot3: sheetView 1+2, no normalize, no clipping self.plot3 = make_template_plot(plot_channels3, self.view_dict, density=10.0, name='plot3') plot_channels4 = { 'Strength': self.key1, 'Hue': self.key2, 'Confidence': self.key3 } # plot4: sheetView 1+2+3, no normalize , no clipping self.plot4 = make_template_plot(plot_channels4, self.view_dict, density=10.0, name='plot4') plot_channels5 = { 'Strength': self.key1, 'Hue': None, 'Confidence': self.key3 } # plot5: sheetView 1+3, no normalize, no clipping self.plot5 = make_template_plot(plot_channels5, self.view_dict, density=10.0, name='plot5') plot_channels6 = { 'Strength': None, 'Hue': self.key2, 'Confidence': self.key3 } # plot6: sheetView 2+3, no normalize , no clipping self.plot6 = make_template_plot(plot_channels6, self.view_dict, density=10.0, name='plot6') plot_channels7 = { 'Strength': self.key4, 'Hue': self.key2, 'Confidence': self.key3 } # plot7: sheetView 1+2+3, no normalize , clipping self.plot7 = make_template_plot(plot_channels7, self.view_dict, density=10.0, name='plot7') plot_channels8 = { 'Strength': self.key1, 'Hue': self.key2, 'Confidence': self.key3 } # plot8: sheetView 1+2+3, normalize , no clipping self.plot8 = make_template_plot(plot_channels8, self.view_dict, density=10.0, normalize=True, name='plot8') ### JCALERT! FOR THE MOMENT I TAKE THE DEFAULT FOR NORMALIZE. ### WE WILL SEE IF IT REMAINS IN PLOT FIRST. ### also makes a sheet to test realease_sheetviews self.sheet = Sheet() self.sheet.views.maps[self.key1] = self.sheet_view1 self.sheet.views.maps[self.key2] = self.sheet_view2 self.sheet.views.maps[self.key3] = self.sheet_view3 self.sheet.views.maps[self.key4] = self.sheet_view4 plot_channels9 = { 'Strength': self.key1, 'Hue': self.key2, 'Confidence': self.key3 } self.plot9 = make_template_plot(plot_channels9, self.sheet.views.maps, density=10.0, name='plot9')
def setUp(self): ### Simple case: we only pass a dictionary to Plot() ### that does not belong to a Sheet: views = {} time = 0 metadata = AttrDict(timestamp=time) ### SheetView1: ### Find a way to assign randomly the matrix. self.matrix1 = np.zeros((10,10),dtype=np.float) + np.random.random((10,10)) self.bounds1 = BoundingBox(points=((-0.5,-0.5),(0.5,0.5))) im = Image(self.matrix1, self.bounds1) im.metadata=metadata self.sheet_view1 = NdMapping((None, im)) self.sheet_view1.metadata = AttrDict(src_name='TestInputParam', precedence=0.1, row_precedence=0.1, cyclic_range=None, timestamp=time) self.key1 = 'IM1' views[self.key1] = self.sheet_view1 ### SheetView2: ### Find a way to assign randomly the matrix. self.matrix2 = np.zeros((10,10),dtype=np.float) + 0.3 self.bounds2 = BoundingBox(points=((-0.5,-0.5),(0.5,0.5))) im = Image(self.matrix2, self.bounds2) im.metadata=metadata self.sheet_view2 = NdMapping((None, im)) self.sheet_view2.metadata = AttrDict(src_name='TestInputParam', precedence=0.2, row_precedence=0.2, cyclic_range=None, timestamp=time) self.key2 = 'IM2' views[self.key2] = self.sheet_view2 ### SheetView3: ### Find a way to assign randomly the matrix. self.matrix3 = np.zeros((10,10),dtype=np.float) + np.random.random((10,10)) self.bounds3 = BoundingBox(points=((-0.5,-0.5),(0.5,0.5))) im = Image(self.matrix3, self.bounds3) im.metadata=metadata self.sheet_view3 = NdMapping((None, im)) self.sheet_view3.metadata = AttrDict(src_name='TestInputParam', precedence=0.3, row_precedence=0.3, cyclic_range=None, timestamp=time) self.key3 = 'IM3' views[self.key3] = self.sheet_view3 ### SheetView4: for testing clipping + different bounding box ### Find a way to assign randomly the matrix. self.matrix4 = np.zeros((10,10),dtype=np.float) + 1.6 self.bounds4 = BoundingBox(points=((-0.7,-0.7),(0.7,0.7))) im = Image(self.matrix4, self.bounds4) im.metadata=metadata self.sheet_view4 = NdMapping((None, im)) self.sheet_view4.metadata = AttrDict(src_name='TestInputParam', precedence=0.4, row_precedence=0.4, cyclic_range=None, timestamp=time) self.key4 = 'IM4' views[self.key4] = self.sheet_view4 self.view_dict = {'Strength': views, 'Hue': views, 'Confidence': views} ### JCALERT! for the moment we can only pass a triple when creating plot ### adding more sheetView to test when plot will be fixed for accepting ### as much as you want. # plot0: empty plot + no sheetviewdict passed: error or empty plot? ### JCALERT! It has to be fixed what to do in this case in plot.. ### disabled test for the moment. #self.plot0 = Plot((None,None,None),None,name='plot0') ### CATCH EXCEPTION plot_channels1 = {'Strength':None,'Hue':None,'Confidence':None} # plot1: empty plot self.plot1 = make_template_plot(plot_channels1,self.view_dict,density=10.0,name='plot1') plot_channels2 = {'Strength':self.key1,'Hue':None,'Confidence':None} # plot2: sheetView 1, no normalize, no clipping self.plot2 = make_template_plot(plot_channels2,self.view_dict,density=10.0,name='plot2') plot_channels3 = {'Strength':self.key1,'Hue':self.key2,'Confidence':None} # plot3: sheetView 1+2, no normalize, no clipping self.plot3 = make_template_plot(plot_channels3,self.view_dict,density=10.0,name='plot3') plot_channels4 = {'Strength':self.key1,'Hue':self.key2,'Confidence':self.key3} # plot4: sheetView 1+2+3, no normalize , no clipping self.plot4 = make_template_plot(plot_channels4,self.view_dict,density=10.0,name='plot4') plot_channels5 = {'Strength':self.key1,'Hue':None,'Confidence':self.key3} # plot5: sheetView 1+3, no normalize, no clipping self.plot5 = make_template_plot(plot_channels5,self.view_dict,density=10.0,name='plot5') plot_channels6 = {'Strength':None,'Hue':self.key2,'Confidence':self.key3} # plot6: sheetView 2+3, no normalize , no clipping self.plot6 = make_template_plot(plot_channels6,self.view_dict,density=10.0,name='plot6') plot_channels7 = {'Strength':self.key4,'Hue':self.key2,'Confidence':self.key3} # plot7: sheetView 1+2+3, no normalize , clipping self.plot7 = make_template_plot(plot_channels7,self.view_dict,density=10.0,name='plot7') plot_channels8 = {'Strength':self.key1,'Hue':self.key2,'Confidence':self.key3} # plot8: sheetView 1+2+3, normalize , no clipping self.plot8 = make_template_plot(plot_channels8,self.view_dict,density=10.0,normalize=True,name='plot8') ### JCALERT! FOR THE MOMENT I TAKE THE DEFAULT FOR NORMALIZE. ### WE WILL SEE IF IT REMAINS IN PLOT FIRST. ### also makes a sheet to test realease_sheetviews self.sheet = Sheet() self.sheet.views.Maps[self.key1]=self.sheet_view1 self.sheet.views.Maps[self.key2]=self.sheet_view2 self.sheet.views.Maps[self.key3]=self.sheet_view3 self.sheet.views.Maps[self.key4]=self.sheet_view4 plot_channels9 = {'Strength':self.key1,'Hue':self.key2,'Confidence':self.key3} self.plot9 = make_template_plot(plot_channels9,self.sheet.views.Maps,density=10.0,name='plot9')
def setUp(self): ### Simple case: we only pass a dictionnary to Plot() ### that does not belong to a Sheet: self.view_dict = {} ### SheetView1: ### Find a way to assign randomly the matrix. self.matrix1 = zeros((10,10),Float) + RandomArray.random((10,10)) self.bounds1 = BoundingBox(points=((-0.5,-0.5),(0.5,0.5))) self.sheet_view1 = SheetView((self.matrix1,self.bounds1), src_name='TestInputParam') self.key1 = 'sv1' self.view_dict[self.key1] = self.sheet_view1 ### SheetView2: ### Find a way to assign randomly the matrix. self.matrix2 = zeros((10,10),Float) + 0.3 self.bounds2 = BoundingBox(points=((-0.5,-0.5),(0.5,0.5))) self.sheet_view2 = SheetView((self.matrix2,self.bounds2), src_name='TestInputParam') self.key2 = ('sv2',0,10) self.view_dict[self.key2] = self.sheet_view2 ### SheetView3: ### Find a way to assign randomly the matrix. self.matrix3 = zeros((10,10),Float) + RandomArray.random((10,10)) self.bounds3 = BoundingBox(points=((-0.5,-0.5),(0.5,0.5))) self.sheet_view3 = SheetView((self.matrix3,self.bounds3), src_name='TestInputParam') self.key3 = ('sv3',0,'hello',(10,0)) self.view_dict[self.key3] = self.sheet_view3 ### SheetView4: for testing clipping + different bounding box ### Find a way to assign randomly the matrix. self.matrix4 = zeros((10,10),Float) + 1.6 self.bounds4 = BoundingBox(points=((-0.7,-0.7),(0.7,0.7))) self.sheet_view4 = SheetView((self.matrix4,self.bounds4), src_name='TestInputParam') self.key4 = 'sv4' self.view_dict[self.key4] = self.sheet_view4 ### JCALERT! for the moment we can only pass a triple when creating plot ### adding more sheetView to test when plot will be fixed for accepting ### as much as you want. # plot0: empty plot + no sheetviewdict passed: error or empty plot? ### JCALERT! It has to be fixed what to do in this case in plot.. ### disabled test for the moment. #self.plot0 = Plot((None,None,None),None,name='plot0') ### CATCH EXCEPTION plot_channels1 = {'Strength':None,'Hue':None,'Confidence':None} # plot1: empty plot self.plot1 = make_template_plot(plot_channels1,self.view_dict,density=10.0,name='plot1') plot_channels2 = {'Strength':self.key1,'Hue':None,'Confidence':None} # plot2: sheetView 1, no normalize, no clipping self.plot2 = make_template_plot(plot_channels2,self.view_dict,density=10.0,name='plot2') plot_channels3 = {'Strength':self.key1,'Hue':self.key2,'Confidence':None} # plot3: sheetView 1+2, no normalize, no clipping self.plot3 = make_template_plot(plot_channels3,self.view_dict,density=10.0,name='plot3') plot_channels4 = {'Strength':self.key1,'Hue':self.key2,'Confidence':self.key3} # plot4: sheetView 1+2+3, no normalize , no clipping self.plot4 = make_template_plot(plot_channels4,self.view_dict,density=10.0,name='plot4') plot_channels5 = {'Strength':self.key1,'Hue':None,'Confidence':self.key3} # plot5: sheetView 1+3, no normalize, no clipping self.plot5 = make_template_plot(plot_channels5,self.view_dict,density=10.0,name='plot5') plot_channels6 = {'Strength':None,'Hue':self.key2,'Confidence':self.key3} # plot6: sheetView 2+3, no normalize , no clipping self.plot6 = make_template_plot(plot_channels6,self.view_dict,density=10.0,name='plot6') plot_channels7 = {'Strength':self.key4,'Hue':self.key2,'Confidence':self.key3} # plot7: sheetView 1+2+3, no normalize , clipping self.plot7 = make_template_plot(plot_channels7,self.view_dict,density=10.0,name='plot7') plot_channels8 = {'Strength':self.key1,'Hue':self.key2,'Confidence':self.key3} # plot8: sheetView 1+2+3, normalize , no clipping self.plot8 = make_template_plot(plot_channels8,self.view_dict,density=10.0,normalize=True,name='plot8') ### JCALERT! FOR THE MOMENT I TAKE THE DEFAULT FOR NORMALIZE. ### WE WILL SEE IF IT REMAINS IN PLOT FIRST. ### also makes a sheet to test realease_sheetviews self.sheet = Sheet() self.sheet.sheet_views[self.key1]=self.sheet_view1 self.sheet.sheet_views[self.key2]=self.sheet_view2 self.sheet.sheet_views[self.key3]=self.sheet_view3 self.sheet.sheet_views[self.key4]=self.sheet_view4 plot_channels9 = {'Strength':self.key1,'Hue':self.key2,'Confidence':self.key3} self.plot9 = make_template_plot(plot_channels9,self.sheet.sheet_views,density=10.0,name='plot9')