def _update_proj_cog(self,proj): """Measure the CoG of the specified projection and register corresponding SheetViews.""" sheet=proj.dest rows,cols=sheet.activity.shape xpref=zeros((rows,cols),Float) ypref=zeros((rows,cols),Float) 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) xpref[r][c]= xcentroid ypref[r][c]= ycentroid sheet.sheet_views['XCoG']=SheetView((xpref,sheet.bounds), sheet.name, sheet.precedence,topo.sim.time(),sheet.row_precedence) sheet.sheet_views['YCoG']=SheetView((ypref,sheet.bounds), sheet.name, sheet.precedence,topo.sim.time(),sheet.row_precedence)
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 = dict(precedence=sheet.precedence, row_precedence=sheet.row_precedence, src_name=sheet.name, dimension_labels=['Time'], key_type=[topo.sim.time.time_type]) timestamp = topo.sim.time() xsv = SheetView(xcog, sheet.bounds) ysv = SheetView(ycog, sheet.bounds) 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) xcog_stack = SheetStack((timestamp, xsv), **metadata) ycog_stack = SheetStack((timestamp, ysv), **metadata) contour_stack = SheetStack( (timestamp, SheetLines(lines, sheet.bounds)), **metadata) if 'XCoG' in sheet.views.maps: sheet.views.maps['XCoG'].update(xcog_stack) else: sheet.views.maps['XCoG'] = xcog_stack if 'YCoG' in sheet.views.maps: sheet.views.maps['YCoG'].update(ycog_stack) else: sheet.views.maps['YCoG'] = ycog_stack if 'CoG' in sheet.views.maps: sheet.views.maps['CoG'].update(contour_stack) else: sheet.views.maps['CoG'] = contour_stack return {'XCoG': xcog_stack, 'YCoG': ycog_stack, 'CoG': contour_stack}
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}
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 = dict(precedence=sheet.precedence, row_precedence=sheet.row_precedence, src_name=sheet.name, dimension_labels=['Time'], key_type=[topo.sim.time.time_type]) timestamp = topo.sim.time() xsv = SheetView(xcog, sheet.bounds) ysv = SheetView(ycog, sheet.bounds) 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) xcog_stack = SheetStack((timestamp, xsv), **metadata) ycog_stack = SheetStack((timestamp, ysv), **metadata) contour_stack = SheetStack((timestamp, SheetLines(lines, sheet.bounds)), **metadata) if 'XCoG' in sheet.views.maps: sheet.views.maps['XCoG'].update(xcog_stack) else: sheet.views.maps['XCoG'] = xcog_stack if 'YCoG' in sheet.views.maps: sheet.views.maps['YCoG'].update(ycog_stack) else: sheet.views.maps['YCoG'] = ycog_stack if 'CoG' in sheet.views.maps: sheet.views.maps['CoG'].update(contour_stack) else: sheet.views.maps['CoG'] = contour_stack return {'XCoG': xcog_stack, 'YCoG': ycog_stack, 'CoG': contour_stack}
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', value_dimensions=[Dimension('X CoG', range=(lbrt[0], lbrt[2]))]) ysv = Image(ycog, sheet.bounds, label=proj.name, group='Y CoG', value_dimensions=[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), key_dimensions=[features.Time]) xcog_map.metadata = metadata ycog_map = HoloMap((timestamp, ysv), key_dimensions=[features.Time]) ycog_map.metadata = metadata contour_map = HoloMap((timestamp, cogmesh), key_dimensions=[features.Time]) contour_map.metadata = metadata return {'XCoG': xcog_map, 'YCoG': ycog_map, 'CoG': contour_map}