def update_sheet_activity(sheet_name, force=False): """ Update the '_activity_buffer' SheetStack for a given sheet by name. If force is False and the existing Activity SheetView isn't stale, the existing view is returned. """ name = 'ActivityBuffer' sheet = topo.sim.objects(Sheet)[sheet_name] view = sheet.views.Maps.get(name, False) time = topo.sim.time() metadata = AttrDict(precedence=sheet.precedence, row_precedence=sheet.row_precedence, src_name=sheet.name, shape=sheet.activity.shape, timestamp=time) if not view: sv = SheetView(np.array(sheet.activity), sheet.bounds) sv.metadata=metadata view = SheetStack((time, sv), dimensions=[Time]) view.metadata = metadata sheet.views.Maps[name] = view else: if force or view.dim_range('Time')[1] < time: sv = SheetView(np.array(sheet.activity), sheet.bounds) sv.metadata=metadata view[time] = sv return view
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 projection_view(self, timestamp=None): """Returns the activity in a single projection""" if timestamp is None: timestamp = self.src.simulation.time() sv = SheetView(self.activity.copy(), self.dest.bounds, label='Activity', title='%s {label}' % self.name) sv.metadata=AttrDict(proj_src_name=self.src.name, precedence=self.src.precedence, proj_name=self.name, row_precedence=self.src.row_precedence, src_name=self.dest.name, timestamp=timestamp) return sv
def update_rgb_activities(): """ Make available Red, Green, and Blue activity matrices for all appropriate sheets. """ for sheet in topo.sim.objects(Sheet).values(): metadata = AttrDict(src_name=sheet.name, precedence=sheet.precedence, row_precedence=sheet.row_precedence, timestamp=topo.sim.time()) for c in ['Red','Green','Blue']: # should this ensure all of r,g,b are present? if hasattr(sheet,'activity_%s'%c.lower()): activity_copy = getattr(sheet,'activity_%s'%c.lower()).copy() new_view = SheetView(activity_copy, bounds=sheet.bounds) new_view.metadata=metadata sheet.views.Maps['%sActivity'%c]=new_view
def __getitem__(self, coords): metadata = AttrDict(precedence=self.precedence, row_precedence=self.row_precedence, timestamp=self.simulation.time()) if self._channel_data: arr = np.dstack(self._channel_data) else: arr = self.activity.copy() sv = SheetView(arr, self.bounds, label=self.name + ' Activity', value='Activity')[coords] sv.metadata = metadata return sv
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 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) sv.metadata=metadata self.sheet_view1 = NdMapping((None, sv)) self.sheet_view1.metadata = AttrDict(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) sv.metadata=metadata self.sheet_view2 = NdMapping((None, sv)) self.sheet_view2.metadata = AttrDict(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) sv.metadata=metadata self.sheet_view3 = NdMapping((None, sv)) self.sheet_view3.metadata = AttrDict(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) sv.metadata=metadata self.sheet_view4 = NdMapping((None, sv)) self.sheet_view4.metadata = AttrDict(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))) sv = SheetView(self.matrix1, self.bounds1) sv.metadata = metadata self.sheet_view1 = NdMapping((None, sv)) self.sheet_view1.metadata = AttrDict(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 = np.zeros((10, 10), dtype=np.float) + 0.3 self.bounds2 = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5))) sv = SheetView(self.matrix2, self.bounds2) sv.metadata = metadata self.sheet_view2 = NdMapping((None, sv)) self.sheet_view2.metadata = AttrDict(src_name='TestInputParam', precedence=0.2, row_precedence=0.2, cyclic_range=None, timestamp=time) self.key2 = 'SV2' 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))) sv = SheetView(self.matrix3, self.bounds3) sv.metadata = metadata self.sheet_view3 = NdMapping((None, sv)) self.sheet_view3.metadata = AttrDict(src_name='TestInputParam', precedence=0.3, row_precedence=0.3, cyclic_range=None, timestamp=time) self.key3 = 'SV3' 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))) sv = SheetView(self.matrix4, self.bounds4) sv.metadata = metadata self.sheet_view4 = NdMapping((None, sv)) self.sheet_view4.metadata = AttrDict(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')