Exemplo n.º 1
0
 def _set_sheet_views(instance, state):
     if state['simulation'] is None:
         return None
     name = state['_name_param_value']
     if not hasattr(state['simulation'], 'views'):
         state['simulation'].views = AttrDict()
     if name not in state['simulation'].views:
         if hasattr(instance, 'views'):
             state['views'] = instance.views
         else:
             state['views'] = AttrDict()
         state['simulation'].views[name] = state['views']
     views = state['views']
     views['maps'] = AttrDict()
     views['cfs'] = AttrDict()
     views['rfs'] = AttrDict()
     views['curves'] = AttrDict()
     if 'sheet_views' in state:
         svs = state['sheet_views']
         for key, sv in svs.items():
             data, bounds = sv.view()
             new_sv = Matrix(data, bounds)
             metadata = dict(dimension_labels=['Time'])
             metadata_names = ['cyclic_range', 'precedence',
                               'row_precedence', 'src_name']
             for p in metadata_names:
                 if hasattr(sv, p):
                     metadata[p] = getattr(sv, p)
             state['views'].maps[key] = NdMapping((sv.timestamp, new_sv),
                                               **metadata)
     if 'curve_dict' in state:
         old_curves = state['curve_dict']
         curves = views['curves']
         for key, value in old_curves.items():
             key = key.capitalize()
             for label, item in value.items():
                 labels = unit_value(label)
                 label_name = labels[0].split(' ')[0]
                 l_val = labels[-1]
                 if key not in views['curves']:
                     curves[key] = NdMapping(dimension_labels=['Time'])
                 for f_val, old_sv in item.items():
                     timestamp = old_sv.timestamp
                     curves[key][timestamp] = NdMapping(dimension_labels=[label_name])
                     if l_val not in curves[key][timestamp].keys():
                         curves[key][timestamp] [l_val] = NdMapping(dimension_labels=[key],
                                                                    label=label,
                                                                    timestamp=old_sv.timestamp)
                     data, bounds = old_sv.view()
                     sv = Matrix(data, bounds)
                     curves[key][timestamp][l_val][f_val] = sv
     state.pop('curve_dict', None)
     state.pop('sheet_views', None)
Exemplo n.º 2
0
 def _set_sheet_views(instance, state):
     if state['simulation'] is None:
         return None
     name = state['_name_param_value']
     if not hasattr(state['simulation'], 'views'):
         state['simulation'].views = AttrDict()
     if name not in state['simulation'].views:
         if hasattr(instance, 'views'):
             state['views'] = instance.views
         else:
             state['views'] = AttrDict()
         state['simulation'].views[name] = state['views']
     views = state['views']
     views['maps'] = AttrDict()
     views['cfs'] = AttrDict()
     views['rfs'] = AttrDict()
     views['curves'] = AttrDict()
     if 'sheet_views' in state:
         svs = state['sheet_views']
         for key, sv in svs.items():
             data, bounds = sv.view()
             new_sv = SheetView(data, bounds)
             metadata = dict(dimension_labels=['Time'])
             metadata_names = [
                 'cyclic_range', 'precedence', 'row_precedence', 'src_name'
             ]
             for p in metadata_names:
                 if hasattr(sv, p):
                     metadata[p] = getattr(sv, p)
             state['views'].maps[key] = NdMapping((sv.timestamp, new_sv),
                                                  **metadata)
     if 'curve_dict' in state:
         old_curves = state['curve_dict']
         curves = views['curves']
         for key, value in old_curves.items():
             key = key.capitalize()
             for label, item in value.items():
                 labels = unit_value(label)
                 label_name = labels[0].split(' ')[0]
                 l_val = labels[-1]
                 if key not in views['curves']:
                     curves[key] = NdMapping(dimension_labels=['Time'])
                 for f_val, old_sv in item.items():
                     timestamp = old_sv.timestamp
                     curves[key][timestamp] = NdMapping(
                         dimension_labels=[label_name])
                     if l_val not in curves[key][timestamp].keys():
                         curves[key][timestamp][l_val] = NdMapping(
                             dimension_labels=[key],
                             label=label,
                             timestamp=old_sv.timestamp)
                     data, bounds = old_sv.view()
                     sv = SheetView(data, bounds)
                     curves[key][timestamp][l_val][f_val] = sv
     state.pop('curve_dict', None)
     state.pop('sheet_views', None)
Exemplo n.º 3
0
    def _update_proj_cog(self, p, proj):
        """Measure the CoG of the specified projection and register corresponding SheetViews."""

        sheet = proj.dest
        rows, cols = sheet.activity.shape
        xcog = np.zeros((rows, cols), np.float64)
        ycog = np.zeros((rows, cols), np.float64)

        for r in xrange(rows):
            for c in xrange(cols):
                cf = proj.cfs[r, c]
                r1, r2, c1, c2 = cf.input_sheet_slice
                row_centroid, col_centroid = centroid(cf.weights)
                xcentroid, ycentroid = proj.src.matrix2sheet(
                    r1 + row_centroid + 0.5, c1 + col_centroid + 0.5)

                xcog[r][c] = xcentroid
                ycog[r][c] = ycentroid

        metadata = AttrDict(precedence=sheet.precedence,
                            row_precedence=sheet.row_precedence,
                            src_name=sheet.name)

        timestamp = topo.sim.time()
        lbrt = sheet.bounds.lbrt()
        xsv = Image(xcog,
                    sheet.bounds,
                    label=proj.name,
                    group='X CoG',
                    vdims=[Dimension('X CoG', range=(lbrt[0], lbrt[2]))])
        ysv = Image(ycog,
                    sheet.bounds,
                    label=proj.name,
                    group='Y CoG',
                    vdims=[Dimension('Y CoG', range=(lbrt[1], lbrt[3]))])

        lines = []
        hlines, vlines = xsv.data.shape
        for hind in range(hlines)[::p.stride]:
            lines.append(np.vstack([xsv.data[hind, :].T, ysv.data[hind, :]]).T)
        for vind in range(vlines)[::p.stride]:
            lines.append(np.vstack([xsv.data[:, vind].T, ysv.data[:, vind]]).T)
        cogmesh = Contours(lines,
                           extents=sheet.bounds.lbrt(),
                           label=proj.name,
                           group='Center of Gravity')

        xcog_map = HoloMap((timestamp, xsv), kdims=[features.Time])
        xcog_map.metadata = metadata
        ycog_map = HoloMap((timestamp, ysv), kdims=[features.Time])
        ycog_map.metadata = metadata

        contour_map = HoloMap((timestamp, cogmesh), kdims=[features.Time])
        contour_map.metadata = metadata

        return {'XCoG': xcog_map, 'YCoG': ycog_map, 'CoG': contour_map}
Exemplo n.º 4
0
 def projection_view(self, timestamp=None):
     """Returns the activity in a single projection"""
     if timestamp is None:
         timestamp = self.src.simulation.time()
     return SheetView(self.activity.copy(),
                      self.dest.bounds,
                      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))
Exemplo n.º 5
0
    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

            im = Image(sheet.input_generator(), bounds=sheet.bounds)
            im.metadata = AttrDict(timestamp=topo.sim.time())

            if 'Activity' not in views:
                views['Activity'] = NdMapping((topo.sim.time(), im))
                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()] = im
            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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
 def __init__(self, **params):
     super(ProjectionSheet, self).__init__(**params)
     self.new_input = False
     self.mask.sheet = self
     self.old_a = self.activity.copy() * 0.0
     self.views['rfs'] = AttrDict()
def _reset_views(sheet):
    if hasattr(sheet.views, 'maps'):
        sheet.views.maps = AttrDict()
    if hasattr(sheet.views, 'curves'):
        sheet.views.curves = AttrDict()