예제 #1
0
 def test_template_view_select(self):
     mouse_click(self.qtbot,
                 self.template_view.canvas, (100, 100),
                 modifiers=('Control', ))
     mouse_click(self.qtbot,
                 self.template_view.canvas, (150, 100),
                 modifiers=('Shift', ))
예제 #2
0
파일: test_base.py 프로젝트: zsong30/phy
 def test_trace_view(self):
     self.trace_view.actions.go_to_next_spike()
     self.trace_view.actions.go_to_previous_spike()
     self.trace_view.actions.toggle_highlighted_spikes(True)
     mouse_click(self.qtbot, self.trace_view.canvas, (100, 100), modifiers=('Control',))
     mouse_click(self.qtbot, self.trace_view.canvas, (150, 100), modifiers=('Shift',))
     emit('select_time', self, 0)
     self.trace_view.actions.next_color_scheme()
예제 #3
0
파일: test_base.py 프로젝트: zsong30/phy
    def test_select_feature(self):
        self.next()

        fv = self.feature_view
        # Select feature in feature view.
        w, h = fv.canvas.get_size()
        w, h = w / 4, h / 4
        x, y = w / 2, h / 2
        mouse_click(self.qtbot, fv.canvas, (x, y), button='Right', modifiers=('Alt',))
예제 #4
0
파일: test_base.py 프로젝트: zsong30/phy
    def test_waveform_select_channel(self):
        self.amplitude_view.amplitudes_type = 'raw'

        fv = self.waveform_view
        # Select channel in waveform view.
        w, h = fv.canvas.get_size()
        w, h = w / 2, h / 2
        x, y = w / 2, h / 2
        mouse_click(self.qtbot, fv.canvas, (x, y), button='Left', modifiers=('Control',))
예제 #5
0
def test_raster_0(qtbot, gui):
    n = 5
    spike_times = np.arange(n)
    spike_clusters = np.arange(n)
    cluster_ids = np.arange(n)

    class Supervisor(object):
        pass

    s = Supervisor()

    v = RasterView(spike_times, spike_clusters)
    v.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

    v.set_cluster_ids(cluster_ids)
    v.plot()
    assert v.status

    v.on_select(cluster_ids=[2], sender=s)
    v.plot()

    v.increase_marker_size()
    v.decrease_marker_size()

    # Simulate cluster selection.
    _clicked = []

    w, h = v.canvas.get_size()

    @connect(sender=v)
    def on_request_select(sender, cluster_ids):
        _clicked.append(cluster_ids)

    @connect(sender=v)
    def on_select_more(sender, cluster_ids):
        _clicked.append(cluster_ids)

    mouse_click(qtbot, v.canvas, pos=(w / 2, 0.), button='Left', modifiers=())
    assert len(_clicked) == 1
    assert _clicked == [[0]]

    mouse_click(qtbot,
                v.canvas,
                pos=(w / 2, h / 2),
                button='Left',
                modifiers=('Shift', ))
    assert len(_clicked) == 2
    assert _clicked[1][0] in (1, 2)

    v.zoom_to_time_range((1., 3.))

    _stop_and_close(qtbot, v)
예제 #6
0
파일: test_scatter.py 프로젝트: zsong30/phy
def test_scatter_view_3(qtbot, gui):
    n = 1000
    v = ScatterView(
        coords=lambda cluster_ids: Bunch(
            pos=np.random.randn(n, 2),
            spike_ids=np.arange(n),
            spike_clusters=np.random.randint(size=n, low=0, high=4),
            data_bounds=None,
        )
    )
    v.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

    v.on_select(cluster_ids=[0, 2])

    a, b = 50, 1000
    mouse_click(qtbot, v.canvas, (a, a), modifiers=('Control',))
    mouse_click(qtbot, v.canvas, (a, b), modifiers=('Control',))
    mouse_click(qtbot, v.canvas, (b, b), modifiers=('Control',))
    mouse_click(qtbot, v.canvas, (b, a), modifiers=('Control',))

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

    _stop_and_close(qtbot, v)
예제 #7
0
파일: test_base.py 프로젝트: zsong30/phy
 def lasso(self, view, scale=1.):
     w, h = view.canvas.get_size()
     w *= scale
     h *= scale
     mouse_click(self.qtbot, view.canvas, (1, 1), modifiers=('Control',))
     mouse_click(self.qtbot, view.canvas, (w - 1, 1), modifiers=('Control',))
     mouse_click(self.qtbot, view.canvas, (w - 1, h - 1), modifiers=('Control',))
     mouse_click(self.qtbot, view.canvas, (1, h - 1), modifiers=('Control',))
예제 #8
0
def test_raster_0(qtbot, gui):
    spike_times = np.arange(4)
    spike_clusters = np.arange(4)
    cluster_ids = np.arange(4)

    cluster_meta = Bunch(fields=('group', ), get=lambda f, cl: cl % 4)
    cluster_metrics = {'quality': lambda c: 3. - c}
    c = ClusterColorSelector(cluster_meta=cluster_meta,
                             cluster_metrics=cluster_metrics,
                             cluster_ids=cluster_ids)

    class Supervisor(object):
        pass

    s = Supervisor()

    v = RasterView(spike_times, spike_clusters, cluster_color_selector=c)
    v.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

    v.set_cluster_ids(cluster_ids)
    v.plot()

    v.on_select(cluster_ids=[2], sender=s)
    c.set_color_mapping('quality', 'categorical')
    v.plot()

    v.increase()
    v.decrease()

    # Simulate channel selection.
    _clicked = []

    @connect(sender=v)
    def on_cluster_click(sender, cluster_id=None, button=None):
        _clicked.append((cluster_id, button))

    mouse_click(qtbot,
                v.canvas,
                pos=(0., 0.),
                button='Left',
                modifiers=('Control', ))

    assert _clicked == [(1, 'Left')]

    _stop_and_close(qtbot, v)
예제 #9
0
def test_amplitude_view_2(qtbot, gui):
    n = 1000
    v = AmplitudeView(
        amplitudes={
            'amp1':
            lambda cluster_ids, load_all=False: [
                Bunch(amplitudes=15 + np.random.randn(n),
                      spike_ids=np.arange(n),
                      spike_times=artificial_spike_samples(n) / 20000.)
                for c in cluster_ids
            ],
            'amp2':
            lambda cluster_ids, load_all=False: [
                Bunch(amplitudes=10 + np.random.randn(n),
                      spike_ids=np.arange(n),
                      spike_times=artificial_spike_samples(n) / 20000.)
                for c in cluster_ids
            ],
        })
    v.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

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

    v.next_amplitude_type()
    v.previous_amplitude_type()

    v.set_state(v.state)

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

    a, b = 50, 1000
    mouse_click(qtbot, v.canvas, (a, a), modifiers=('Control', ))
    mouse_click(qtbot, v.canvas, (a, b), modifiers=('Control', ))
    mouse_click(qtbot, v.canvas, (b, b), modifiers=('Control', ))
    mouse_click(qtbot, v.canvas, (b, a), modifiers=('Control', ))

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

    _stop_and_close(qtbot, v)
예제 #10
0
파일: test_scatter.py 프로젝트: zsong30/phy
def test_scatter_view_2(qtbot, gui):
    n = 1000
    v = ScatterView(
        coords=lambda cluster_ids, load_all=False: [Bunch(
            x=np.random.randn(n),
            y=np.random.randn(n),
            spike_ids=np.arange(n),
            data_bounds=None,
        ) for c in cluster_ids]
    )
    v.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

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

    v.set_state(v.state)

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

    a, b = 50, 1000
    mouse_click(qtbot, v.canvas, (a, a), modifiers=('Control',))
    mouse_click(qtbot, v.canvas, (a, b), modifiers=('Control',))
    mouse_click(qtbot, v.canvas, (b, b), modifiers=('Control',))
    mouse_click(qtbot, v.canvas, (b, a), modifiers=('Control',))

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

    _stop_and_close(qtbot, v)
예제 #11
0
def test_cluster_scatter_view_1(qtbot, tempdir, gui):
    n_clusters = 1000
    cluster_ids = np.arange(n_clusters)[2::3]

    class Supervisor(object):
        pass

    s = Supervisor()

    def cluster_info(cluster_id):
        np.random.seed(cluster_id)
        return Bunch({
            'fet1': np.random.randn(),
            'fet2': np.random.randn(),
            'fet3': np.random.uniform(low=5, high=20)
        })

    bindings = Bunch({'x_axis': 'fet1', 'y_axis': 'fet2', 'size': 'fet3'})

    v = ClusterScatterView(cluster_info=cluster_info,
                           cluster_ids=cluster_ids,
                           bindings=bindings)
    v.add_color_scheme(lambda cluster_id: RandomState(cluster_id).rand(),
                       name='depth',
                       colormap='linear',
                       cluster_ids=cluster_ids)
    v.show()
    v.plot()
    v.color_scheme = 'depth'
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

    @connect(sender=v)
    def on_request_select(sender, cluster_ids):
        v.on_select(sender, cluster_ids)

    @connect(sender=v)
    def on_select_more(sender, cluster_ids):
        v.on_select(sender, list(np.concatenate((v.cluster_ids, cluster_ids))))

    v.on_select(s, list(cluster_ids[1::50]))

    up = Bunch(all_cluster_ids=cluster_ids[3::20])
    emit('cluster', s, up)

    v.on_select(s, list(cluster_ids[3::40]))

    v.actions.change_x_axis_to_fet1()
    v.set_x_axis('fet1')
    v.set_y_axis('fet2')
    v.set_size('fet3')

    v.actions.get('Toggle log scale for x_axis').trigger()
    v.actions.get('Toggle log scale for y_axis').trigger()
    v.actions.get('Toggle log scale for size').trigger()

    v.increase_marker_size()
    assert v.status

    # Simulate cluster selection.
    _clicked = []

    w, h = v.canvas.get_size()

    @connect(sender=v)  # noqa
    def on_request_select(sender, cluster_ids):
        _clicked.append(cluster_ids)

    @connect(sender=v)  # noqa
    def on_select_more(sender, cluster_ids):
        _clicked.append(cluster_ids)

    mouse_click(qtbot,
                v.canvas,
                pos=(w / 2, h / 2),
                button='Left',
                modifiers=())
    assert len(_clicked) == 1

    mouse_click(qtbot,
                v.canvas,
                pos=(w / 2, h / 2),
                button='Left',
                modifiers=('Shift', ))
    assert len(_clicked) == 2

    mouse_click(qtbot,
                v.canvas,
                pos=(w * .3, h * .3),
                button='Left',
                modifiers=('Control', ))
    mouse_click(qtbot,
                v.canvas,
                pos=(w * .7, h * .3),
                button='Left',
                modifiers=('Control', ))
    mouse_click(qtbot,
                v.canvas,
                pos=(w * .7, h * .7),
                button='Left',
                modifiers=('Control', ))
    mouse_click(qtbot,
                v.canvas,
                pos=(w * .3, h * .7),
                button='Left',
                modifiers=('Control', ))

    assert len(v.cluster_ids) >= 1

    _stop_and_close(qtbot, v)
예제 #12
0
def test_amplitude_view_2(qtbot, gui):
    n = 1000
    st1 = artificial_spike_samples(n) / 20000.
    st2 = artificial_spike_samples(n) / 20000.
    v = AmplitudeView(amplitudes={
        'amp1':
        lambda cluster_ids, load_all=False: [
            Bunch(
                amplitudes=15 + np.random.randn(n),
                spike_ids=np.arange(n),
                spike_times=st1,
            ) for c in cluster_ids
        ],
        'amp2':
        lambda cluster_ids, load_all=False: [
            Bunch(
                amplitudes=10 + np.random.randn(n),
                spike_ids=np.arange(n),
                spike_times=st2,
            ) for c in cluster_ids
        ],
    },
                      duration=max(st1.max(), st2.max()))
    v.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

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

    v.next_amplitudes_type()
    v.previous_amplitudes_type()

    v.set_state(v.state)

    w, h = v.canvas.get_size()

    _times = []

    @connect(sender=v)
    def on_select_time(sender, time):
        _times.append(time)

    mouse_click(qtbot, v.canvas, (w / 3, h / 2), modifiers=('Alt', ))
    assert len(_times) == 1
    assert np.allclose(_times[0], .5, atol=.01)

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

    a, b = 50, 1000
    mouse_click(qtbot, v.canvas, (a, a), modifiers=('Control', ))
    mouse_click(qtbot, v.canvas, (a, b), modifiers=('Control', ))
    mouse_click(qtbot, v.canvas, (b, b), modifiers=('Control', ))
    mouse_click(qtbot, v.canvas, (b, a), modifiers=('Control', ))

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

    _stop_and_close(qtbot, v)
예제 #13
0
파일: test_feature.py 프로젝트: GrohLab/phy
def test_feature_view(qtbot, gui, n_channels):
    nc = n_channels
    ns = 10000
    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.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

    v.set_grid_dim(_get_default_grid())

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

    assert v.status

    v.increase()
    v.decrease()

    v.increase_marker_size()
    v.decrease_marker_size()

    v.on_select_channel(channel_id=3, button='Left', key=None)
    v.on_select_channel(channel_id=3, button='Right', key=None)
    v.on_select_channel(channel_id=3, button='Right', key=2)
    v.clear_channels()
    v.toggle_automatic_channel_selection(True)

    # Test feature selection with Alt+click.
    _l = []

    @connect(sender=v)
    def on_select_feature(sender, dim=None, channel_id=None, pc=None):
        _l.append((dim, channel_id, pc))

    for i, j, dim_x, dim_y in v._iter_subplots():
        for k, button in enumerate(('Left', 'Right')):
            # Click on the center of every subplot.
            w, h = v.canvas.get_size()
            w, h = w / 4, h / 4
            x, y = w / 2, h / 2
            mouse_click(qtbot,
                        v.canvas, (x + j * w, y + i * h),
                        button=button,
                        modifiers=('Alt', ))
            assert _l[-1][0] == v.grid_dim[i][j].split(',')[k]

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

    a, b = 10, 100
    mouse_click(qtbot, v.canvas, (a, a), modifiers=('Control', ))
    mouse_click(qtbot, v.canvas, (a, b), modifiers=('Control', ))
    mouse_click(qtbot, v.canvas, (b, b), modifiers=('Control', ))
    mouse_click(qtbot, v.canvas, (b, a), modifiers=('Control', ))

    # Split lassoed points.
    spike_ids = v.on_request_split()

    # HACK: this seems to fail because qtbot.mouseClick is not working??
    # assert len(spike_ids) > 0

    v.set_state(v.state)

    _stop_and_close(qtbot, v)
예제 #14
0
def test_waveform_view(qtbot, tempdir, gui):
    nc = 5
    ns = 10

    w = 10 + 100 * artificial_waveforms(ns, 20, nc)

    def get_waveforms(cluster_id):
        return Bunch(data=w,
                     masks=np.random.uniform(low=0., high=1., size=(ns, nc)),
                     channel_ids=np.arange(nc),
                     channel_labels=['%d' % (ch * 10) for ch in range(nc)],
                     channel_positions=staggered_positions(nc))

    v = WaveformView(
        waveforms={
            'waveforms': get_waveforms,
            'mean_waveforms': get_waveforms
        },
        sample_rate=10000.,
    )
    v.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

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

    v.toggle_waveform_overlap(True)
    v.toggle_waveform_overlap(False)

    v.toggle_show_labels(False)
    v.toggle_show_labels(True)

    v.next_waveforms_type()
    v.previous_waveforms_type()
    v.toggle_mean_waveforms(True)
    v.toggle_mean_waveforms(False)

    # Box scaling.
    bs = v.boxed.box_size
    v.increase()
    v.decrease()
    v.reset_scaling()
    ac(v.boxed.box_size, bs)

    bs = v.boxed.box_size
    v.widen()
    v.narrow()
    ac(v.boxed.box_size, bs)

    # Probe scaling.
    bp = v.boxed.box_pos
    v.extend_horizontally()
    v.shrink_horizontally()
    ac(v.boxed.box_pos, bp)

    bp = v.boxed.box_pos
    v.extend_vertically()
    v.shrink_vertically()
    ac(v.boxed.box_pos, bp)

    a, b = v.probe_scaling
    v.probe_scaling = (a, b * 2)
    ac(v.probe_scaling, (a, b * 2))

    a, b = v.box_scaling
    v.box_scaling = (a * 2, b)
    ac(v.box_scaling, (a * 2, b))

    # Simulate channel selection.
    _clicked = []

    @connect(sender=v)
    def on_select_channel(sender, channel_id=None, button=None, key=None):
        _clicked.append((channel_id, button, key))

    key_press(qtbot, v.canvas, '2')
    mouse_click(qtbot, v.canvas, pos=(0., 0.), button='Left')
    key_release(qtbot, v.canvas, '2')

    assert _clicked == [(2, 'Left', 2)]

    v.set_state(v.state)

    _stop_and_close(qtbot, v)
예제 #15
0
def test_template_view_1(qtbot, tempdir, gui):
    n_samples = 50
    n_clusters = 10
    channel_ids = np.arange(n_clusters + 2)
    cluster_ids = np.arange(n_clusters)

    def get_templates(cluster_ids):
        return {i: Bunch(
            template=artificial_waveforms(1, n_samples, 2)[0, ...],
            channel_ids=np.arange(i, i + 2),
        ) for i in cluster_ids}

    class Supervisor(object):
        pass
    s = Supervisor()

    v = TemplateView(templates=get_templates, channel_ids=channel_ids, cluster_ids=cluster_ids)
    v.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

    v.update_color()  # should call .plot() instead as update_color() is for subsequent updates

    v.on_select(cluster_ids=[], sender=s)
    v.on_select(cluster_ids=[0], sender=s)
    assert v.status

    v.update_cluster_sort(cluster_ids[::-1])

    # Simulate cluster selection.
    _clicked = []

    w, h = v.canvas.get_size()

    @connect(sender=v)
    def on_request_select(sender, cluster_ids):
        _clicked.append(cluster_ids)

    @connect(sender=v)
    def on_select_more(sender, cluster_ids):
        _clicked.append(cluster_ids)

    mouse_click(qtbot, v.canvas, pos=(0, 0.), button='Left', modifiers=())
    assert len(_clicked) == 1
    assert _clicked[0] in ([4], [5])

    mouse_click(qtbot, v.canvas, pos=(0, h / 2), button='Left', modifiers=('Shift',))
    assert len(_clicked) == 2
    assert _clicked[1] == [9]

    cluster_ids = np.arange(2, n_clusters + 2)
    v.set_cluster_ids(cluster_ids)
    v.plot()

    v.update_color()

    v.increase()
    v.decrease()
    v.scaling = v.scaling

    _stop_and_close(qtbot, v)
예제 #16
0
 def test_create_raster_view(self):
     view = self.gui.create_and_add_view('RasterView')
     mouse_click(self.qtbot, view.canvas, (10, 10), modifiers=('Control', ))
예제 #17
0
파일: test_trace.py 프로젝트: ycanerol/phy
def test_trace_view_1(qtbot, tempdir, gui):
    nc = 5
    ns = 20
    sr = 2000.
    duration = 1.
    st = np.linspace(0.1, .9, ns)
    sc = artificial_spike_clusters(ns, nc)
    traces = 10 * artificial_traces(int(round(duration * sr)), nc)

    def get_traces(interval):
        out = Bunch(
            data=select_traces(traces, interval, sample_rate=sr),
            color=(.75, .75, .75, 1),
        )
        a, b = st.searchsorted(interval)
        out.waveforms = []
        k = 20
        for i in range(a, b):
            t = st[i]
            c = sc[i]
            s = int(round(t * sr))
            d = Bunch(
                data=traces[s - k:s + k, :],
                start_time=(s - k) / sr,
                channel_ids=np.arange(5),
                spike_id=i,
                spike_cluster=c,
                select_index=0,
            )
            out.waveforms.append(d)
        return out

    def get_spike_times():
        return st

    v = TraceView(
        traces=get_traces,
        spike_times=get_spike_times,
        n_channels=nc,
        sample_rate=sr,
        duration=duration,
        channel_positions=linear_positions(nc),
    )
    v.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

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

    v.stacked.add_boxes(v.canvas)

    ac(v.stacked.box_size, (.950, .165), atol=1e-3)
    v.set_interval((.375, .625))
    assert v.time == .5
    qtbot.wait(1)

    v.go_to(.25)
    assert v.time == .25
    qtbot.wait(1)

    v.go_to(-.5)
    assert v.time == .125
    qtbot.wait(1)

    v.go_left()
    assert v.time == .125
    qtbot.wait(1)

    v.go_right()
    ac(v.time, .150)
    qtbot.wait(1)

    v.jump_left()
    qtbot.wait(1)

    v.jump_right()
    qtbot.wait(1)

    v.go_to_next_spike()
    qtbot.wait(1)

    v.go_to_previous_spike()
    qtbot.wait(1)

    # Change interval size.
    v.interval = (.25, .75)
    ac(v.interval, (.25, .75))
    qtbot.wait(1)

    v.widen()
    ac(v.interval, (.1875, .8125))
    qtbot.wait(1)

    v.narrow()
    ac(v.interval, (.25, .75))
    qtbot.wait(1)

    v.go_to_start()
    qtbot.wait(1)
    assert v.interval[0] == 0

    v.go_to_end()
    qtbot.wait(1)
    assert v.interval[1] == duration

    # Widen the max interval.
    v.set_interval((0, duration))
    v.widen()
    qtbot.wait(1)

    v.toggle_show_labels(True)
    v.go_right()

    # Check auto scaling.
    db = v.data_bounds
    v.toggle_auto_scale(False)
    v.narrow()
    qtbot.wait(1)
    # Check that ymin and ymax have not changed.
    assert v.data_bounds[1] == db[1]
    assert v.data_bounds[3] == db[3]

    v.toggle_auto_update(True)
    assert v.do_show_labels
    qtbot.wait(1)

    v.toggle_highlighted_spikes(True)
    qtbot.wait(50)

    # Change channel scaling.
    bs = v.stacked.box_size
    v.decrease()
    qtbot.wait(1)

    v.increase()
    ac(v.stacked.box_size, bs, atol=.05)
    qtbot.wait(1)

    v.origin = 'bottom'
    v.switch_origin()
    assert v.origin == 'top'
    qtbot.wait(1)

    # Simulate spike selection.
    _clicked = []

    @connect(sender=v)
    def on_select_spike(sender,
                        channel_id=None,
                        spike_id=None,
                        cluster_id=None,
                        key=None):
        _clicked.append((channel_id, spike_id, cluster_id))

    mouse_click(qtbot,
                v.canvas,
                pos=(0., 0.),
                button='Left',
                modifiers=('Control', ))

    v.set_state(v.state)

    assert len(_clicked[0]) == 3

    # Simulate channel selection.
    _clicked = []

    @connect(sender=v)
    def on_select_channel(sender, channel_id=None, button=None):
        _clicked.append((channel_id, button))

    mouse_click(qtbot,
                v.canvas,
                pos=(0., 0.),
                button='Left',
                modifiers=('Shift', ))
    mouse_click(qtbot,
                v.canvas,
                pos=(0., 0.),
                button='Right',
                modifiers=('Shift', ))

    assert _clicked == [(2, 'Left'), (2, 'Right')]

    _stop_and_close(qtbot, v)
예제 #18
0
def test_template_view_1(qtbot, tempdir, gui):
    n_samples = 50
    n_clusters = 10
    channel_ids = np.arange(n_clusters + 2)
    cluster_ids = np.arange(n_clusters)

    def get_templates(cluster_ids):
        return {
            i: Bunch(
                template=artificial_waveforms(1, n_samples, 2)[0, ...],
                channel_ids=np.arange(i, i + 2),
            )
            for i in cluster_ids
        }

    cluster_color_selector = ClusterColorSelector(cluster_ids=cluster_ids)

    class Supervisor(object):
        pass

    s = Supervisor()

    v = TemplateView(templates=get_templates,
                     channel_ids=channel_ids,
                     cluster_ids=cluster_ids,
                     cluster_color_selector=cluster_color_selector)
    v.show()
    qtbot.waitForWindowShown(v.canvas)
    v.attach(gui)

    v.update_color(
    )  # should call .plot() instead as update_color() is for subsequent updates

    v.on_select(cluster_ids=[], sender=s)
    v.on_select(cluster_ids=[0], sender=s)

    v.update_cluster_sort(cluster_ids[::-1])

    # Simulate channel selection.
    _clicked = []

    @connect(sender=v)
    def on_cluster_click(sender, cluster_id=None, button=None, modifiers=None):
        _clicked.append((cluster_id, button))

    mouse_click(qtbot,
                v.canvas,
                pos=(10., 10.),
                button='Left',
                modifiers=('Control', ))

    assert _clicked == [(9, 'Left')]

    cluster_ids = np.arange(2, n_clusters + 2)
    v.set_cluster_ids(cluster_ids)
    v.plot()

    cluster_color_selector.set_color_mapping(colormap='linear')
    v.update_color()

    v.increase()
    v.decrease()
    v.scaling = v.scaling

    _stop_and_close(qtbot, v)