Ejemplo n.º 1
0
from hci.gui.utils import start_widget
from hci.streaming.signal_interface import MaskController


class MaskControllerAPI(Frame):
    def __init__(self, master, mask_controller: MaskController):
        super().__init__(master)
        self.mask_controller = mask_controller
        Label(self, text="Control Panel").pack()

        signal_controls = Frame(self)
        signal_controls.pack(side=LEFT, expand=TRUE, fill=Y)
        Label(signal_controls, text='Signals').pack()
        self.mask_variables = []
        for channel in range(self.mask_controller.n_chans):
            var = IntVar(master=self, value=int(mask_controller.mask[channel]))
            control_radiobutton = Checkbutton(signal_controls,
                                              text=str(channel + 1),
                                              variable=var,
                                              command=self.change_mask)
            control_radiobutton.pack(expand=True, fill=BOTH)
            self.mask_variables.append(var)

    def change_mask(self):
        channel_mask = [var.get() > 0 for var in self.mask_variables]
        self.mask_controller.mask = channel_mask


if __name__ == '__main__':
    start_widget(lambda root: MaskControllerAPI(root, MaskController(2)))
Ejemplo n.º 2
0
    def ylim(self):
        return self._ylim

    @ylim.setter
    def ylim(self, limits):
        self._ylim = limits
        self.ax.set_ylim(limits)

    def init_figure(self):
        """Function to clear figure and create empty plot."""
        # It is important, because with blit=True this function is called
        # twice.
        self.figure.clear()
        self.ax = self.figure.add_subplot(111)
        self.xlim = self.default_xlim
        self.ylim = self.default_ylim
        self.line, = self.ax.plot([], [], lw=2)
        self.line.set_data([], [])
        return self.line,

    def animate_figure(self, data):
        """Function for animation process, called on each frame."""
        x = np.linspace(0, 2, 1000)
        y = np.sin(2 * np.pi * (x + 0.01 * data))
        self.line.set_data(x, y)
        return self.line,


if __name__ == '__main__':
    start_widget(lambda root: BasicVisualizer(root, navigation_toolbar=True))
Ejemplo n.º 3
0
        self.lines = self.ax.plot([], [], lw=2)
        self.y = deque(maxlen=len(self.x))
        return self.lines

    def animate_figure(self, data):
        """Function for animation process, called on each frame."""
        if data is not None and len(data) == self.signal_interface.epoch_len and self.predictor is not None:

            self.y.append(self.predictor(data))

            self.lines[0].set_data(self.x[: len(self.y)], self.y)
        return self.lines


if __name__ == "__main__":

    def root2widget(root):
        window = 1.0

        device = Dummy()
        mask_controller = MaskController(device.n_chans)
        stream_inlet = device.get_stream_inlet(timeout=1)
        windowed_signal = WindowedSignal(stream_inlet, window)
        widget = Analyser(
            root, build_analyser=build_analyser, windowed_signal=windowed_signal, mask_controller=mask_controller
        )
        return widget

    start_widget(root2widget)
Ejemplo n.º 4
0
            hundred = (self.x > 95) & (self.x < 105)
            zero = fifty | hundred | beginning

            self.y = self.y.T#np.log(self.y.T)

            self.x = self.x[-zero]
            self.y = self.y[-zero]

            for i, line in enumerate(self.lines):
                if mask[i]:
                    line.set_linewidth(1)
                else:
                    line.set_linewidth(0)

                line.set_data(self.x, self.y[:, i])
            self.auto_ylim(force=True)
        return self.lines


if __name__ == '__main__':
    def root2widget(root):
        window = 1.0

        device = Dummy()
        mask_controller = MaskController(device.n_chans)
        stream_inlet = device.get_stream_inlet(timeout=1)
        signal_interface = WindowedSignal(stream_inlet, window)
        widget = Spectrogram(root, signal_interface, mask_controller)
        return widget
    start_widget(root2widget)