示例#1
0
    def _init_data(self):
        self.cache_dir = self.config_dir
        self.n_samples_waveforms = 31
        self.n_samples_t = 20000
        self.n_channels = 11
        self.n_clusters = 4
        self.n_spikes_per_cluster = 50
        n_spikes_total = self.n_clusters * self.n_spikes_per_cluster
        n_features_per_channel = 4

        self.n_channels = self.n_channels
        self.n_spikes = n_spikes_total
        self.sample_rate = 20000.
        self.duration = self.n_samples_t / float(self.sample_rate)
        self.spike_times = np.arange(0, self.duration, 100. / self.sample_rate)
        self.spike_clusters = np.repeat(np.arange(self.n_clusters),
                                        self.n_spikes_per_cluster)
        assert len(self.spike_times) == len(self.spike_clusters)
        self.cluster_ids = np.unique(self.spike_clusters)
        self.channel_positions = staggered_positions(self.n_channels)

        sc = self.spike_clusters
        self.spikes_per_cluster = lambda c: _spikes_in_clusters(sc, [c])
        self.spike_count = lambda c: len(self.spikes_per_cluster(c))
        self.n_features_per_channel = n_features_per_channel
        self.cluster_groups = {c: None for c in range(self.n_clusters)}

        self.all_traces = artificial_traces(self.n_samples_t, self.n_channels)
        self.all_masks = artificial_masks(n_spikes_total, self.n_channels)
        self.all_waveforms = artificial_waveforms(n_spikes_total,
                                                  self.n_samples_waveforms,
                                                  self.n_channels)
        self.all_features = artificial_features(n_spikes_total,
                                                self.n_channels,
                                                self.n_features_per_channel)
示例#2
0
文件: conftest.py 项目: mspacek/phy
    def _init_data(self):
        self.cache_dir = self.config_dir
        self.n_samples_waveforms = 31
        self.n_samples_t = 20000
        self.n_channels = 11
        self.n_clusters = 4
        self.n_spikes_per_cluster = 200
        n_spikes_total = self.n_clusters * self.n_spikes_per_cluster
        n_features_per_channel = 4

        self.n_channels = self.n_channels
        self.n_spikes = n_spikes_total
        self.sample_rate = 20000.
        self.duration = self.n_samples_t / float(self.sample_rate)
        self.spike_times = np.arange(
            0, self.duration,
            5000. / (self.sample_rate * self.n_spikes_per_cluster))
        self.spike_clusters = np.repeat(np.arange(self.n_clusters),
                                        self.n_spikes_per_cluster)
        assert len(self.spike_times) == len(self.spike_clusters)
        self.cluster_ids = np.unique(self.spike_clusters)
        self.channel_positions = staggered_positions(self.n_channels)
        self.channel_order = np.arange(self.n_channels)

        sc = self.spike_clusters
        self.spikes_per_cluster = lambda c: _spikes_in_clusters(sc, [c])
        self.spike_count = lambda c: len(self.spikes_per_cluster(c))
        self.n_features_per_channel = n_features_per_channel
        self.cluster_groups = {c: None for c in range(self.n_clusters)}

        self.all_traces = artificial_traces(self.n_samples_t, self.n_channels)
        self.all_masks = artificial_masks(n_spikes_total, self.n_channels)
        self.all_waveforms = artificial_waveforms(n_spikes_total,
                                                  self.n_samples_waveforms,
                                                  self.n_channels)
        self.all_features = artificial_features(n_spikes_total,
                                                self.n_channels,
                                                self.n_features_per_channel)
示例#3
0
def test_feature_view(qtbot, tempdir, n_channels):
    nc = n_channels
    ns = 500
    features = artificial_features(ns, nc, 4)
    spike_clusters = artificial_spike_clusters(ns, 4)
    spike_times = np.linspace(0., 1., ns)
    spc = _spikes_per_cluster(spike_clusters)

    def get_spike_ids(cluster_id):
        return (spc[cluster_id] if cluster_id is not None else np.arange(ns))

    def get_features(cluster_id=None,
                     channel_ids=None,
                     spike_ids=None,
                     load_all=None):
        if load_all:
            spike_ids = spc[cluster_id]
        else:
            spike_ids = get_spike_ids(cluster_id)
        return Bunch(
            data=features[spike_ids],
            spike_ids=spike_ids,
            masks=np.random.rand(ns, nc),
            channel_ids=(channel_ids
                         if channel_ids is not None else np.arange(nc)[::-1]),
        )

    def get_time(cluster_id=None, load_all=None):
        return Bunch(
            data=spike_times[get_spike_ids(cluster_id)],
            lim=(0., 1.),
        )

    v = FeatureView(
        features=get_features,
        attributes={'time': get_time},
    )

    v.set_state(GUIState(scaling=None))

    gui = GUI(config_dir=tempdir)
    gui.show()
    v.attach(gui)
    qtbot.addWidget(gui)

    v.on_select([])
    v.on_select([0])
    v.on_select([0, 2, 3])
    v.on_select([0, 2])

    gui.emit('select', [0, 2])
    qtbot.wait(10)

    v.increase()
    v.decrease()

    v.on_channel_click(channel_id=3, button=1, key=2)
    v.clear_channels()
    v.toggle_automatic_channel_selection()

    # Split without selection.
    spike_ids = v.on_request_split()
    assert len(spike_ids) == 0

    # Draw a lasso.
    def _click(x, y):
        qtbot.mouseClick(v.native,
                         Qt.LeftButton,
                         pos=QPoint(x, y),
                         modifier=Qt.ControlModifier)

    _click(10, 10)
    _click(10, 100)
    _click(100, 100)
    _click(100, 10)

    # Split lassoed points.
    spike_ids = v.on_request_split()
    assert len(spike_ids) > 0

    # qtbot.stop()
    gui.close()
示例#4
0
def test_feature_view(qtbot, tempdir, n_channels):
    nc = n_channels
    ns = 500
    features = artificial_features(ns, nc, 4)
    spike_clusters = artificial_spike_clusters(ns, 4)
    spike_times = np.linspace(0., 1., ns)
    spc = _spikes_per_cluster(spike_clusters)

    def get_spike_ids(cluster_id):
        return (spc[cluster_id] if cluster_id is not None else np.arange(ns))

    def get_features(cluster_id=None, channel_ids=None, spike_ids=None,
                     load_all=None):
        if load_all:
            spike_ids = spc[cluster_id]
        else:
            spike_ids = get_spike_ids(cluster_id)
        return Bunch(data=features[spike_ids],
                     spike_ids=spike_ids,
                     masks=np.random.rand(ns, nc),
                     channel_ids=(channel_ids
                                  if channel_ids is not None
                                  else np.arange(nc)[::-1]),
                     )

    def get_time(cluster_id=None, load_all=None):
        return Bunch(data=spike_times[get_spike_ids(cluster_id)],
                     lim=(0., 1.),
                     )

    v = FeatureView(features=get_features,
                    attributes={'time': get_time},
                    )

    v.set_state(GUIState(scaling=None))

    gui = GUI(config_dir=tempdir)
    gui.show()
    v.attach(gui)
    qtbot.addWidget(gui)

    v.on_select([])
    v.on_select([0])
    v.on_select([0, 2, 3])
    v.on_select([0, 2])

    gui.emit('select', [0, 2])
    qtbot.wait(10)

    v.increase()
    v.decrease()

    v.on_channel_click(channel_id=3, button=1, key=2)
    v.clear_channels()
    v.toggle_automatic_channel_selection()

    # Split without selection.
    spike_ids = v.on_request_split()
    assert len(spike_ids) == 0

    # Draw a lasso.
    def _click(x, y):
        qtbot.mouseClick(v.native, Qt.LeftButton, pos=QPoint(x, y),
                         modifier=Qt.ControlModifier)

    _click(10, 10)
    _click(10, 100)
    _click(100, 100)
    _click(100, 10)

    # Split lassoed points.
    spike_ids = v.on_request_split()
    assert len(spike_ids) > 0

    # qtbot.stop()
    gui.close()
示例#5
0
def features(n_spikes, n_channels, n_features_per_channel):
    yield artificial_features(n_spikes, n_channels, n_features_per_channel)
示例#6
0
def features(n_spikes, n_channels, n_features_per_channel):
    yield artificial_features(n_spikes, n_channels, n_features_per_channel)