Пример #1
0
 def apply(self, arr, from_bounds=None, to_bounds=None):
     """Apply the transform to a NumPy array."""
     from_bounds = np.asarray(
         from_bounds if from_bounds is not None else self.from_bounds, dtype=np.float64)
     to_bounds = np.asarray(
         to_bounds if to_bounds is not None else self.to_bounds, dtype=np.float64)
     return range_transform(from_bounds, to_bounds, arr)
Пример #2
0
    def on_request_split(self, sender=None):
        """Return the spikes enclosed by the lasso."""
        if (self.canvas.lasso.count < 3
                or not len(self.cluster_ids)):  # pragma: no cover
            return np.array([], dtype=np.int64)

        # Get all points from all clusters.
        pos = []
        spike_ids = []

        # each item is a Bunch with attribute `pos` et `spike_ids`
        bunchs = self.get_clusters_data(load_all=True)
        if bunchs is None:
            return
        for bunch in bunchs:
            # Skip background points.
            # NOTE: we need to make sure that the bunch has a cluster_id key.
            if 'cluster_id' in bunch and bunch.cluster_id is None:
                continue
            # Load all spikes.
            points = np.c_[bunch.pos]
            pos.append(points)
            spike_ids.append(bunch.spike_ids)
        if not pos:  # pragma: no cover
            logger.warning("Empty lasso.")
            return np.array([])
        pos = np.vstack(pos)
        pos = range_transform([self.data_bounds], [NDC], pos)
        spike_ids = np.concatenate(spike_ids)

        # Find lassoed spikes.
        ind = self.canvas.lasso.in_polygon(pos)
        self.canvas.lasso.clear()
        return np.unique(spike_ids[ind])
Пример #3
0
    def on_request_split(self, sender=None):
        """Return the spikes enclosed by the lasso."""
        if (self.canvas.lasso.count < 3 or not len(self.cluster_ids)):  # pragma: no cover
            return np.array([], dtype=np.int64)

        pos = []
        spike_ids = []

        Ntime = self.wavefs.shape[1]
        x = np.linspace(-Ntime/2/self.Fs, Ntime/2/self.Fs, Ntime)

        for idx,spike in enumerate(self.spike_ids):
            points = np.c_[x,self.gain*self.wavefs[idx,:,self.current_channel_idx]]
            pos.append(points)
            spike_ids.append([spike]*len(x))

        if not pos:  # pragma: no cover
            logger.warning("Empty lasso.")
            return np.array([])
        pos = np.vstack(pos)
        pos = range_transform([self.data_bounds], [NDC], pos)
        spike_ids = np.concatenate(spike_ids)

        # Find lassoed spikes.
        ind = self.canvas.lasso.in_polygon(pos)
        self.canvas.lasso.clear()

        # Return all spikes not lassoed, so the selected cluster is still the same we are working on
        spikes_to_remove = np.unique(spike_ids[ind])
        keepspikes=np.isin(self.spike_ids,spikes_to_remove,assume_unique=True,invert=True)
        A=self.spike_ids[self.spike_ids != spikes_to_remove]
        if len(A)>0:
            return self.spike_ids[keepspikes]
        else:
            return np.array([], dtype=np.int64)
Пример #4
0
 def apply(self, arr, from_bounds=None, to_bounds=None):
     """Apply the transform to a NumPy array."""
     from_bounds = from_bounds if from_bounds is not None else self.from_bounds
     to_bounds = to_bounds if to_bounds is not None else self.to_bounds
     assert not isinstance(from_bounds, str) and not isinstance(to_bounds, str)
     from_bounds = np.atleast_2d(_call_if_callable(from_bounds)).astype(np.float64)
     to_bounds = np.atleast_2d(_call_if_callable(to_bounds)).astype(np.float64)
     assert from_bounds.shape[-1] == 4
     assert to_bounds.shape[-1] == 4
     return range_transform(from_bounds, to_bounds, arr)
Пример #5
0
 def _update_axes(self, bunchs):
     """Update the axes."""
     # Update the axes data bounds.
     _, m, _, M = self.data_bounds
     # Waveform duration, scaled by overlap factor if needed.
     wave_dur = bunchs[0].get('waveform_duration', 1.)
     wave_dur /= .5 * (1 + _overlap_transform(
         1, n=len(self.cluster_ids), overlap=self.overlap))
     x1, y1 = range_transform(self.canvas.boxed.box_bounds[0], NDC,
                              [wave_dur, M - m])
     axes_data_bounds = (0, 0, x1, y1)
     self.canvas.axes.reset_data_bounds(axes_data_bounds, do_update=True)
Пример #6
0
def _iter_channel(positions):
    size = 100
    margin = 5
    boxes = _get_boxes(positions, keep_aspect_ratio=False)
    xmin, ymin = boxes[:, :2].min(axis=0)
    xmax, ymax = boxes[:, 2:].max(axis=0)
    x = boxes[:, [0, 2]].mean(axis=1)
    y = -boxes[:, [1, 3]].mean(axis=1)
    positions = np.c_[x, y]
    tr = [margin, margin, size - margin, size - margin]
    positions_tr = range_transform([-1, -1, 1, 1], tr, positions)
    for x, y in positions_tr:
        yield x, y