def new_update_view(*args, **kwargs):
     global x0, x1
     _update_view_orig(*args, **kwargs)
     s = 'toolbar_event'
     event = Event(s, canvas)
     canvas.callbacks.process(s, Event('toolbar_event', canvas))
     x0, x1 = mainplot.get_xlim()
 def new_release_pan(*args, **kwargs):
     global x0, x1
     release_pan_orig(*args, **kwargs)
     s = 'toolbar_event'
     event = Event(s, canvas)
     canvas.callbacks.process(s, Event('toolbar_event', canvas))
     x0, x1 = mainplot.get_xlim()
Exemplo n.º 3
0
 def set_history_buttons(self):
     can_backward = self._nav_stack._pos > 0
     can_forward = self._nav_stack._pos < len(self._nav_stack._elements) - 1
     self._actions['back'].setEnabled(can_backward)
     self._actions['forward'].setEnabled(can_forward)
     event = Event('history', self)
     self.canvas.callbacks.process('history', event)
Exemplo n.º 4
0
def networkOnclick():
	event = Event("mockEvent",network.fig.canvas);
	event.xdata = float(request.args['startX'])
	event.ydata = float(request.args['startY'])
	event.button = int(request.args['type'])
	network.on_button(event)
	event.xdata = float(request.args['endX'])
	event.ydata = float(request.args['endY'])
	event.button = int(request.args['type'])
	network.off_button(event)
	return ""
Exemplo n.º 5
0
def test_query_grid_on_button_press():
    
    rmg = RasterModelGrid((5, 5))
    imshow_grid(rmg, rmg.nodes, cmap='RdYlBu')
    
    # Programmatically create an event near the grid center.
    event = Event('simulated_event', gcf().canvas)
    event.xdata = int(rmg.number_of_node_columns * 0.5)
    event.ydata = int(rmg.number_of_node_rows * 0.5)
    
    results = query_grid_on_button_press(event, rmg)
    x_coord = results['grid location']['x_coord']
    y_coord = results['grid location']['x_coord']
    
    msg = 'Items: Simulated matplotlib event and query results.'
    assert_equal(x_coord, event.xdata, msg)
    assert_equal(y_coord, event.ydata, msg)
    
    msg = 'Items: Node ID and grid coordinates of simulated matplotlib event.'
    node = rmg.grid_coords_to_node_id(event.xdata, event.ydata)
    assert_equal(results['node']['ID'], node, msg)
Exemplo n.º 6
0
def test_query_grid_on_button_press():

    rmg = RasterModelGrid((5, 5))
    imshow_grid(rmg, rmg.nodes, cmap="RdYlBu")

    # Programmatically create an event near the grid center.
    event = Event("simulated_event", gcf().canvas)
    event.xdata = int(rmg.number_of_node_columns * 0.5)
    event.ydata = int(rmg.number_of_node_rows * 0.5)

    results = query_grid_on_button_press(event, rmg)
    x_coord = results["grid location"]["x_coord"]
    y_coord = results["grid location"]["x_coord"]

    msg = "Items: Simulated matplotlib event and query results."
    assert_equal(x_coord, event.xdata, msg)
    assert_equal(y_coord, event.ydata, msg)

    msg = "Items: Node ID and grid coordinates of simulated matplotlib event."
    node = rmg.grid_coords_to_node_id(event.xdata, event.ydata)
    assert_equal(results["node"]["ID"], node, msg)
Exemplo n.º 7
0
def systemOnclick():
	event = Event("mockEvent",system.fig.canvas)
	event.xdata = float(request.args['startX'])
	event.ydata = float(request.args['startY'])
	system.on_button(event)
	event.xdata = float(request.args['endX'])
	event.ydata = float(request.args['endY'])
	event.button = int(request.args['type'])
	system.off_button(event)
	return ""
Exemplo n.º 8
0
def test_query_grid_on_button_press():

    rmg = RasterModelGrid((5, 5))
    imshow_grid(rmg, rmg.nodes, cmap='RdYlBu')

    # Programmatically create an event near the grid center.
    event = Event('simulated_event', gcf().canvas)
    event.xdata = int(rmg.number_of_node_columns * 0.5)
    event.ydata = int(rmg.number_of_node_rows * 0.5)

    results = query_grid_on_button_press(event, rmg)
    x_coord = results['grid location']['x_coord']
    y_coord = results['grid location']['x_coord']

    msg = 'Items: Simulated matplotlib event and query results.'
    assert_equal(x_coord, event.xdata, msg)
    assert_equal(y_coord, event.ydata, msg)

    msg = 'Items: Node ID and grid coordinates of simulated matplotlib event.'
    node = rmg.grid_coords_to_node_id(event.xdata, event.ydata)
    assert_equal(results['node']['ID'], node, msg)
def new_release_zoom(self, *args, **kwargs):
    s = 'release_zoom_event'
    event = Event(s, self)
    event.foo = 3
    self.canvas.callbacks.process(s, event)
    release_zoom(self, *args, **kwargs)
def new_press_zoom(self, *args, **kwargs):
    s = 'press_zoom_event'
    event = Event(s, self)
    event.foo = 2
    self.canvas.callbacks.process(s, event)
    press_zoom(self, *args, **kwargs)
def new_home(self, *args, **kwargs):
    s = 'home_event'
    event = Event(s, self)
    event.foo = 0
    self.canvas.callbacks.process(s, event)
    home(self, *args, **kwargs)
 def leave_notify_event(self, guiEvent=None):
     event = Event('figure_leave_event', self, guiEvent)
     self.callbacks.process('figure_leave_event', event)
 def enter_notify_event(self, guiEvent=None, xy=None):
     event = Event('figure_enter_event', self, guiEvent)
     self.callbacks.process('figure_enter_event', event)
Exemplo n.º 14
0
 def new_update_view(self, *args, **kwargs):
     self._update_view_orig(*args, **kwargs)
     s = 'toolbar_event'
     event = Event(s, self)
     self.canvas.callbacks.process(s, Event('toolbar_event', self))
 def new_forward(self, *args, **kwargs):
     s = 'forward_event'
     event = Event(s, self)
     event.foo = 3
     self.canvas.callbacks.process(s, event)
     forward(self, *args, **kwargs)
Exemplo n.º 16
0
 def new_func(self, *args, **kwargs):
     toolbar_function(self, *args, **kwargs)
     event = Event(event_name, self)
     self.canvas.callbacks.process(event_name, event)
Exemplo n.º 17
0
def new_backward(self, *args, **kwargs):
    s = 'backward_event'
    event = Event(s, self)
    event.foo = 100
    self.canvas.callbacks.process(s, event)
Exemplo n.º 18
0
 def notify(self, event_name, **kwargs):
     event = Event(event_name, self)
     event.kwargs = kwargs
     self.canvas.callbacks.process(event_name, event)
Exemplo n.º 19
0
 def new_release_pan(self, *args, **kwargs):
     self.release_pan_orig(*args, **kwargs)
     s = 'toolbar_event'
     event = Event(s, self)
     self.canvas.callbacks.process(s, Event('toolbar_event', self))
Exemplo n.º 20
0
def eval_task_reconstruct(model: FilterbankModule, num_to_show: int):
    model.eval()
    model.to(device)
    train_data, eval_data, dataset = util.load_datasets(device)

    # plt.figure(figsize=(10, 8))
    height = round(math.ceil(math.sqrt(num_to_show) * 0.7))
    width = num_to_show // height
    actual_num = width * height
    # rand = random.randint(0, min(dataset.max_samples - actual_num, 1000))

    fig, axs = plt.subplots(nrows=height * 2, ncols=width)

    # register this callback to scroll pages of results by clicking on far left or far right of plot
    # matplotlib should really let you hijack those < > buttons instead, but they don't generate events
    def onclick(event: Event):
        global viz_data_index

        if event.guiEvent is not None:
            for i in range(height):
                for j in range(width):
                    axs[2 * i, j].clear()
                    axs[2 * i + 1, j].clear()

            if event.guiEvent.x < 200:
                viz_data_index = max(0, viz_data_index - actual_num)
            elif event.guiEvent.x > event.canvas.figure.get_figwidth() - 200:
                viz_data_index = min(dataset.max_samples - 1,
                                     viz_data_index + actual_num)

        samples = torch.Tensor(actual_num, model.window_size)
        for i in range(actual_num):
            if i < actual_num // 2:
                samples[i] = eval_data[i + viz_data_index]
            else:
                samples[i] = train_data[i + viz_data_index]

        # make sure this tensor is on the same device as the module
        samples = samples.to(device)

        # add 'channel' dim
        padded_samples = samples.unsqueeze(1)
        recons, lincombs = model.forward(padded_samples)

        for i in range(height):
            for j in range(width):
                index = i * width + j

                # squeeze to pop off the batch dim
                sample_np = samples[index].cpu().detach().numpy()
                combin_np = lincombs[index].cpu().detach().numpy()
                recon_np = recons[index].cpu().detach().numpy()

                axis_win = [x for x in range(model.window_size)]
                axis_lincomb = [x for x in range(model.wavelet_kernels)]

                axs[i * 2, j].plot(axis_win, recon_np)
                axs[i * 2, j].plot(axis_win, sample_np)
                axs[i * 2 + 1, j].plot(axis_lincomb, combin_np)
        event.canvas.draw()

    onclick(Event('fake-click', fig.canvas))

    fig.canvas.mpl_connect('button_press_event', onclick)
    plt.subplots_adjust(wspace=0.1, hspace=0)
    plt.show()