def _uniscalestim(self, pos, centroids, rates, probs, active, roicount, border, pars): self.square(pos, pars['subsize'], { 'color': 'none', 'stroke': border, 'stroke-width': 2, }) roin = np.zeros(len(roicount)) stims = sorted([(pars['stimuli'][s]['order'], s) for s in pars['stimuli']]) stims = [s[1] for s in stims] for k, stim in enumerate(stims): for i in range(len(centroids)): x = pos[0] + centroids[i][0] y = pos[1] + centroids[i][1] if k == 0: self.circle((x, y), 1, {'color': '#CCCCCC'}) if rates[stim][i] > pars['cutoff'] and active[i]: r = rates[stim][i] * pars['cell-size'][2] + pars[ 'cell-size'][0] clr = self.colorscale2(probs[stim][i], pars['stimuli'][stim]['color']) if roicount[i] > 1: theta = 360.0 / roicount[i] start = -90 + theta * roin[i] self.arc( (x, y), r, (start, start + theta), { 'color': clr, 'stroke': color( pars['stimuli'][stim]['color']), 'stroke-width': 1 }) roin[i] += 1 else: self.circle( (x, y), r, { 'color': clr, 'stroke': color( pars['stimuli'][stim]['color']), 'stroke-width': 1 })
def cellspots(self, centroids, rates, probs, active, match='', pars={}): default = { 'imsize': (768, 512), 'subsize': (300, 200), 'spacing': 10, 'cell-size': (2, 20), 'cutoff': 0.1, 'squarify': True, 'stimuli': { 'plus': { 'color': 'mint', 'order': 1 }, 'minus': { 'color': 'red', 'order': 2 }, 'neutral': { 'color': 'blue', 'order': 3 }, }, } for p in pars: default[p] = pars[p] ssz, isz, csz = default['subsize'], default['imsize'], default[ 'cell-size'] default['scale'] = (float(ssz[0]) / isz[0], float(ssz[1]) / isz[1]) default['cell-size'] = (csz[0], csz[1], float(csz[1] - csz[0])) if default['squarify']: centroids = self._squarify_centroids(centroids, default) else: centroids = [(c[0] * pars['scale'][0], c[1] * pars['scale'][1]) for c in centroids] roicount = self._count_rois(rates, active, [s for s in default['stimuli']], default['cutoff']) border = color(default['stimuli'][match]['color'] ) if match in default['stimuli'] else color('gray') self._uniscalestim((10, 10), centroids, rates, probs, active, roicount, border, default)
def _scalestim(self, pos, centroids, rates, probs, maxclr, active, pars): self.square(pos, pars['subsize'], { 'color': 'none', 'stroke': color(maxclr), 'stroke-width': 2, }) for i in range(len(centroids)): x = pos[0] + centroids[i][0] y = pos[1] + centroids[i][1] if rates[i] > pars['cutoff'] and (len(active) == 0 or active[i]): r = rates[i] * pars['cell-size'][2] + pars['cell-size'][0] clr = self.colorscale2(probs[i], maxclr) self.circle((x, y), r, { 'color': clr, 'stroke': color('gray'), 'stroke-width': 1 }) else: self.circle((x, y), 1, {'color': '#CCCCCC'})
def graph_probability_matrix(self, singlevec, pairmat, stim='', singleframe=[], pairframe=[], pars={}): default = { 'min-double-prob': -1, 'spacing': 0, 'square': (4, 4), 'border': 'none', 'offset-top': 20, 'offset-left': 100, 'offset-between': 4, 'stimuli': { 'plus': { 'color': 'mint' }, 'minus': { 'color': 'red' }, 'neutral': { 'color': 'blue' }, 'other': { 'color': 'gray' } }, } for p in pars: default[p] = pars[p] y = default['offset-top'] for i, s in enumerate(singlevec): x = default['offset-left'] + i * (default['square'][0] + default['spacing']) clr = self.colorscale3(s) clr = 'rgb(%i,%i,%i)' % (clr[0], clr[1], clr[2]) self.square((x, y), default['square'], {'color': clr}) y = default['offset-top'] + default['square'][1] + default[ 'offset-between'] for i in range(np.shape(pairmat)[0]): for j in range(np.shape(pairmat)[1]): x = default['offset-left'] + i * (default['square'][0] + default['spacing']) yy = y + j * (default['spacing'] + default['square'][1]) clr = self.colorscale3(pairmat[i, j]) clr = 'rgb(%i,%i,%i)' % (clr[0], clr[1], clr[2]) self.square((x, yy), default['square'], {'color': clr}) clr = 'gray' if len(stim) == 0 else default['stimuli'][stim]['color'] self._markcells(singleframe, pairframe, color(clr), default)
def ring(self, pos, rad, pars={}): default = { 'stroke': color('gray'), 'stroke-width': 2, 'opacity': 1.0, } for p in pars: default[p] = pars[p] self.t += '<circle cx="%.2f" cy="%.2f" r="%.2f" style="fill: none; stroke-width: %i; stroke: %s; opacity: %f;"/>' % ( pos[0], pos[1], rad, default['stroke-width'], self._hex(default['stroke']), default['opacity'])
def line(self, p1, p2, pars={}): default = { 'stroke': color('gray'), 'stroke-width': 1, 'opacity': 1.0, } for p in pars: default[p] = pars[p] self.t += '<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f" style="stroke-width: %.2f; stroke: %s; opacity: %f;"/>' % ( p1[0], p1[1], p2[0], p2[1], default['stroke-width'], self._hex(default['stroke']), default['opacity'])
def square(self, pos, sz=(4, 4), pars={}): default = { 'color': color('gray'), 'stroke': 'none', 'stroke-width': 0, } for p in pars: default[p] = pars[p] self.t += '<rect x="%i" y="%i" width="%i" height="%i" style="fill:%s; stroke-width: %i; stroke: %s"/>' % ( pos[0], pos[1], sz[0], sz[1], default['color'], default['stroke-width'], default['stroke'])
def quadcurve(self, p1, p2, control, pars={}): default = { 'stroke': color('gray'), 'stroke-width': 1, 'opacity': 1.0, } for p in pars: default[p] = pars[p] self.t += '<path d="M %.2f %.2f Q %.2f %.2f %.2f %.2f" style="fill:none; stroke-width: %.2f; stroke: %s; opacity: %f;"/>' % ( p1[0], p1[1], control[0], control[1], p2[0], p2[1], default['stroke-width'], self._hex( default['stroke']), default['opacity'])
def arc(self, pos, r, a, pars={}): """ Draw an svg arc centered on tuple pos, with radius r, with an arc beginning at a[0] and going to a[1] in degrees. """ d = { 'color': color('gray'), 'stroke': 'none', 'stroke-width': 0, } for p in pars: d[p] = pars[p] start = self._polar_to_cartesian(pos, r, a[0]) end = self._polar_to_cartesian(pos, r, a[1]) sweep = 1 if a[1] - a[0] <= 180 else 0 self.t += '<path d="M%.1f %.1f L%.1f %.1f A%i %i 0 0 %i %.1f %.1f z" style="fill:%s; stroke-width: %i; stroke: %s"></path>' % ( pos[0], pos[1], start[0], start[1], r, r, sweep, end[0], end[1], self._hex(d['color']), d['stroke-width'], self._hex(d['stroke']))
def _rgb(self, val): """Convert string or hex to rgb tuple.""" if isinstance(val, tuple): return val elif val[0] == '#': return self._hex_to_rgb(val) else: return self._hex_to_rgb(color(val))