def _tomap(self, attr, *keys, layout=False, cols=2, **kwa): mykeys = list( keys if keys else self._keys if self._keys else self.tracks.keys()) fcn = partial(attr, **kwa) if kwa else attr if layout: return hv.Layout([fcn(i) for i in mykeys]).cols(cols) dmap = hv.DynamicMap(fcn, kdims=['key']).redim.values(key=mykeys) return dmap
def beadextent(self, *beads): """ The extension from phase 1 to phase 3 should be similar for all cycles for each bead individually. A drift is an indicator of a drift in zmag measures versus the force applied. In such a case, beads will behave differently for each cycle. """ return (hv.DynamicMap(self._beadextent, kdims=['bead']).redim.values( bead=list(beads if beads else self.tracks.commonbeads())))
def _display(self, beads): stable = [self.tsample(), self.vcap()] def _fcn(bead): ext = self._beadextent(bead) return (stable[0] + stable[1] + ext.BoxWhisker.I + ext.NdOverlay.I).cols(1) return (hv.DynamicMap(_fcn, kdims=['bead']).redim.values( bead=list(beads if beads else self.tracks.commonbeads())))
def map(self, fcn, kdim=None, **kwa): # pylint: disable=redefined-builtin,function-redefined "returns a hv.DynamicMap with beads or cycles, as well as kwargs in the kdims" if kdim is None: kdim = 'cycle' if ('cycle' in kwa and 'bead' not in kwa) else 'bead' if kdim == 'bead': kwa.setdefault(kdim, list(set(i for _, i in self.keys()))) elif kdim == 'cycle': kwa.setdefault(kdim, list(set(i for i, _ in self.keys()))) return hv.DynamicMap(partial(fcn, self), kdims=list(kwa)).redim.values(**kwa)
def fixed(self, display=True, zrange=(-.02, .04), **kwa): "displays aligned cycles for fixed beads only" data = super().fixed(**kwa) if display: alg = FixedBeadDetection(**kwa) hmap = getattr(data.withphases(*alg.diffphases), 'display').display() spread = lambda x: hv.Curve( np.diff(self.fixedspread(x, **kwa), axis=0).ravel(), label="spread").redim(y="z", x="frames") hmap = hmap * hv.DynamicMap(spread, kdims=['bead']) return hmap.redim.range(z=zrange) if zrange else hmap return data
def display( self, # pylint: disable=too-many-arguments beads=None, calib=None, cmap='YlGn', colorbar=True): """ displays the FoV with bead positions as well as calibration images. """ if calib is None: calib = any(x.image is not None and x.image.size != 0 for x in self.beads.values()) bnd = self.bounds() beads = list(self.beads.keys() ) if beads is None or beads is Ellipsis else list(beads) if len(beads) and np.isscalar(beads[0]): beads = (beads, ) itms = [ hv.Image(self.image[::-1], bounds=bnd).options(colorbar=colorbar, cmap=cmap) ] for grp in beads: if grp is None or grp is Ellipsis: grp = list(self.beads.keys()) good = {i: j.position[:2] for i, j in self.beads.items() if i in grp} xvals = [i for i, _ in good.values()] yvals = [i for _, i in good.values()] txt = [f'{i}' for i in good.keys()] itms.append(hv.Points((xvals, yvals))) itms.extend(hv.Text(*i) for i in zip(xvals, yvals, txt)) top = hv.Overlay(itms).redim(x='x (μm)', y='y (μm)') top = top.options({"Points": {"size": 10, "alpha": .6}}) if not calib: return top bottom = hv.DynamicMap( lambda bead: self.beads[bead].display(colorbar=colorbar), kdims=['bead']).redim.values(bead=beads) return (top + bottom).cols(1)
def consensus(self, opts=None, hmap=True, normalize=True, **kwa): "return average bead" data = self.dataframe(False, normalize=normalize, **kwa) RampConsensusBeadProcessor.consensus(data, normalize, self.beads("ok")) data.columns = [self._name(i) for i in data.columns] cols = [ i for i in data.columns if not any(j in i for j in ("zmag", "@low", "@high", "consensus")) ] _crv = partial( self._crv, data, (dict(color="gray", alpha=.25) if opts is None else opts), "Z (% bead length)" if normalize else "Z (µm)") if hmap: crvs = {int(i.split()[1]): _crv(i) for i in cols} mean = _crv("consensus") return (hv.DynamicMap(lambda x: crvs[x] * mean, kdims=['bead' ]).redim.values(bead=list(crvs))) return hv.Overlay([_crv(i) for i in cols + ["consensus"]])
def map(self, fcn, **kwa): # pylint: disable=redefined-builtin "returns a hv.DynamicMap with beads and kwargs in the kdims" kwa.setdefault('bead', list(i for i in self.keys())) return hv.DynamicMap(partial(fcn, self), kdims=list(kwa)).redim.values(**kwa)