def __init__(self, blackboard, patterns): """ @param blackboard: blackboard instance which contains the data that must be plotted @param patterns the patterns corresponding to the data buffers that must be plotted """ if not isinstance(blackboard, Blackboard): raise ValueError("blackboard should be Blackboard instance") if not isinstance(patterns, list): if isinstance(patterns, str): patterns = [patterns] else: raise ValueError( "patterns should be string or list of strings") Subject.__init__(self) DataConsumer.__init__(self, blackboard, patterns) self.blackboard = blackboard self._patterns = patterns self.client = OSC.OSCClient() self.client_port7112 = OSC.OSCClient() self.client.connect( ('127.0.0.1', 7110) ) # connection for openFramework application (radar-visualisation) # self.client.connect(('172.16.10.83', 7110)) # Test connection with PC-system of Pim M. self.client_port7112.connect( ('127.0.0.1', 7112)) # connection for SuperCollider application (audio)
def __init__( self, blackboard, patterns, ax ): """ @param blackboard: blackboard instance which contains the data that must be plotted @param patterns the patterns corresponding to the data buffers that must be plotted @param ax the pyplot Axis instance to draw the plots on """ if not isinstance(blackboard, Blackboard): raise ValueError("blackboard should be Blackboard instance") if not isinstance(patterns, list): if isinstance(patterns, str): patterns = [patterns] else: raise ValueError("patterns should be string or list of strings") Subject.__init__( self ) DataConsumer.__init__( self, blackboard, patterns ) self.blackboard = blackboard self._patterns = patterns self.ax = ax #Initial variables: self.plotConfig( length=512 ) self.reset() self.changed = False
def __init__(self, blackboard, patterns): """ @param blackboard: blackboard instance which contains the data that must be plotted @param patterns the patterns corresponding to the data buffers that must be plotted """ if not isinstance(blackboard, Blackboard): raise ValueError("blackboard should be Blackboard instance") if not isinstance(patterns, list): if isinstance(patterns, str): patterns = [patterns] else: raise ValueError("patterns should be string or list of strings") Subject.__init__( self ) DataConsumer.__init__(self, blackboard, patterns) self.blackboard = blackboard self._patterns = patterns self.client = OSC.OSCClient() self.client_port7112 = OSC.OSCClient() self.client.connect(('127.0.0.1', 7110)) # connection for openFramework application (radar-visualisation) # self.client.connect(('172.16.10.83', 7110)) # Test connection with PC-system of Pim M. self.client_port7112.connect(('127.0.0.1', 7112)) # connection for SuperCollider application (audio)
def unregister_observer(self, observer): """ Overrides from Subject """ Subject.unregister_observer(self, observer) for subject in self.subjects(): subject.unregister_observer( observer )
def __init__(self, blackboard, patterns, ax): """ @param blackboard: blackboard instance which contains the data that must be plotted @param patterns the patterns corresponding to the data buffers that must be plotted @param ax the pyplot Axis instance to draw the plots on """ if not isinstance(blackboard, Blackboard): raise ValueError("blackboard should be Blackboard instance") if not isinstance(patterns, list): if isinstance(patterns, str): patterns = [patterns] else: raise ValueError( "patterns should be string or list of strings") Subject.__init__(self) DataConsumer.__init__(self, blackboard, patterns) self.blackboard = blackboard self._patterns = patterns self.ax = ax #Initial variables: self.plotConfig(length=512) self.reset() self.changed = False
def __init__(self, arg0, marker_pattern=None ): self._counters = [] self._done = [] self._marker_pattern = marker_pattern self._current_time = 0 self.logger = logging.getLogger() if isinstance(arg0, DataSimulator): DataSimulator.__init__( self, arg0.blackboard ) self._observers = arg0._observers else: DataSimulator.__init__( self, arg0 ) Subject.__init__( self )
def __init__(self, arg0, marker_pattern=None): self._counters = [] self._done = [] self._marker_pattern = marker_pattern self._current_time = 0 self.logger = logging.getLogger() if isinstance(arg0, DataSimulator): DataSimulator.__init__(self, arg0.blackboard) self._observers = arg0._observers else: DataSimulator.__init__(self, arg0) Subject.__init__(self)
def __init__(self, arg0): """ @param blackboard: The blackboard on which the simulated data will be presented """ ProcessingThread.__init__(self) Subject.__init__(self) self.clear_data() if isinstance(arg0, DataSimulator): self.blackboard = arg0.blackboard self._observers = arg0._observers return self.blackboard = arg0
def __init__(self): Subject.__init__(self) self.logger = logging.getLogger() width = 1200 height = 600 self.nr_of_channels = 2 # TODO: Rename this to something like 'max_nr_of_signals_per_channel' self.colors = ['white', 'yellow', 'red'] self.root = tk.Tk('EEG KISS') self.root.resizable(width=True, height=True) self.root.minsize(width=800, height=450) self.root.wm_geometry("%dx%d" % (width, height)) self.root.state('zoomed') self.root.wm_title("EEG_Kiss - versie " + Version().getVersionNumber()) #TODO Turn this line off when exporting with py2exe self.root.wm_iconbitmap(bitmap=os.path.dirname(__file__) + "\..\..\icons\EEG_Kiss_icon.ico") self.set_theme_style() screen_width = self.root.winfo_screenwidth() screen_height = self.root.winfo_screenheight() self._frame = ttk.Frame(self.root, width=screen_width, height=screen_height) self._frame.pack_propagate(False) self._frame.pack() self.settings_sreen = None self.init_plot_panel(self._frame) self.init_mode_panel(self._frame) self.init_config_panel(self._frame) self.init_simulation_panel(self._frame) self.init_streaming_panel(self._frame) self.root.bind("<Key>", self.key, False)
def __init__(self, blackboard, patterns, ax, name='No name provided for FrequencyPlot', showLabel=False): """ Initializes the initial values for y-limits and other attributes @param blackboard: blackboard instance which contains the data that must be plotted @param patterns the patterns corresponding to the data buffers that must be plotted @param ax the pyplot Axis instance to draw the plots on """ if not isinstance(blackboard, Blackboard): raise ValueError("blackboard should be Blackboard instance") if not isinstance(patterns, list): if isinstance(patterns, str): patterns = [patterns] else: raise ValueError( "patterns should be string or list of strings") Subject.__init__(self) FftConsumer.__init__(self, blackboard, patterns) self.blackboard = blackboard self._patterns = patterns self.ax = ax self.xLim = 64 self.yoffset = 250 self.ymin = self.yoffset - 2000 self.ymax = self.yoffset + 2000 self.label = name self.showlabel = showLabel self._plotlength = 128 self.changed = False self.reset()
def __init__(self): Subject.__init__( self ) self.logger = logging.getLogger() width = 1200 height = 600 self.nr_of_channels = 2 # TODO: Rename this to something like 'max_nr_of_signals_per_channel' self.colors = ['white','yellow', 'red'] self.root = tk.Tk( 'EEG KISS' ) self.root.resizable(width=True, height=True) self.root.minsize(width=800, height=450) self.root.wm_geometry( "%dx%d" % (width, height) ) self.root.state('zoomed') self.root.wm_title( "EEG_Kiss - versie " + Version().getVersionNumber() ) #TODO Turn this line off when exporting with py2exe self.root.wm_iconbitmap(bitmap = os.path.dirname(__file__) + "\..\..\icons\EEG_Kiss_icon.ico") self.set_theme_style() screen_width = self.root.winfo_screenwidth() screen_height = self.root.winfo_screenheight() self._frame = ttk.Frame( self.root, width=screen_width, height=screen_height ) self._frame.pack_propagate( False ) self._frame.pack( ) self.settings_sreen = None self.init_plot_panel(self._frame) self.init_mode_panel(self._frame) self.init_config_panel(self._frame) self.init_simulation_panel(self._frame) self.init_streaming_panel(self._frame) self.root.bind("<Key>", self.key, False)
def __init__( self, blackboard, pattern ): """ Parameters ========== @param blackboard: Blackboard instance to buffer incoming data @param pattern: The pattern for this headset under which it is buffered on the blackboard """ Subject.__init__( self ) ProcessingThread.__init__( self ) self.reset() self.blackboard = blackboard self._pattern = pattern self._socket = None self._battery = -1 self._serial_state = States.IDLE self._port_state = States.IDLE self.logger = logging.getLogger()
def __init__( self, blackboard, patterns, ax, name='No name provided for FrequencyPlot', showLabel=False ): """ Initializes the initial values for y-limits and other attributes @param blackboard: blackboard instance which contains the data that must be plotted @param patterns the patterns corresponding to the data buffers that must be plotted @param ax the pyplot Axis instance to draw the plots on """ if not isinstance(blackboard, Blackboard): raise ValueError("blackboard should be Blackboard instance") if not isinstance(patterns, list): if isinstance(patterns, str): patterns = [patterns] else: raise ValueError("patterns should be string or list of strings") Subject.__init__( self ) FftConsumer.__init__( self, blackboard, patterns ) self.blackboard = blackboard self._patterns = patterns self.ax = ax self.xLim = 64 self.yoffset = 250 self.ymin = self.yoffset - 2000 self.ymax = self.yoffset + 2000 self.label = name self.showlabel= showLabel self._plotlength =128 self.changed = False self.reset()
def setUp(self): unittest.TestCase.setUp(self) self.ob1 = Observer() self.ob2 = Observer() self.ob3 = Observer() self.sub = Subject()
class TestObserverPattern(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) self.ob1 = Observer() self.ob2 = Observer() self.ob3 = Observer() self.sub = Subject() def test_registration(self): """ Test for adding and removing observers """ self.assertEqual(len(self.sub._observers),0,"Length should be 0") self.sub.register_observer(self.ob1) self.assertEqual(len(self.sub._observers),1,"Length should be 1") self.sub.register_observer(self.ob1) self.assertEqual(len(self.sub._observers),1,"Length should be 1") self.sub.register_observer(self.ob2) self.assertEqual(len(self.sub._observers),2,"Length should be 2") self.sub.unregister_observer(self.ob3) self.assertEqual(len(self.sub._observers),2,"Length should be 2") self.sub.unregister_observer(self.ob2) self.assertEqual(len(self.sub._observers),1,"Length should be 1") self.sub.unregister_observer(self.ob1) self.assertEqual(len(self.sub._observers),0,"Length should be 0") def test_abstract_notification(self): """ Test whether error is raised when abstract notify method is called """ self.sub.register_observer(self.ob1) self.sub.register_observer(self.ob2) self.assertRaises(NotImplementedError, self.sub.notify_observers ) def _test_concrete_notification(self): """ Test whether notify is called in concrete observer """ self.ob1 = SimpleObserver() self.ob2 = SimpleObserver() self.sub.register_observer(self.ob1) self.sub.register_observer(self.ob2) self.assertFalse( self.ob1._notified ) self.assertFalse( self.ob2._notified ) self.sub.notify_observers() self.assertTrue( self.ob1._notified ) self.assertTrue( self.ob2._notified ) def tearDown(self): unittest.TestCase.tearDown(self)
def __init__(self): Subject.__init__( self ) self.nr_of_headsets = 2 self.channels = [1,2,3,4] self.blackboard = Blackboard() self.simulators = [] self.headsets = [] self.processors = [] self.filerecorders = [] self.oscwriters = [] self._connected_headsets = 0 self.timeSettings = TimeSettings() self.frequencySpectrumSettings =SpectrumSettings() self.frequencyBandSettings = FrequencyBandSettings() # Initialize simulators for _ in range( self.nr_of_headsets ): self.simulators.append( TimedSimulator( self.blackboard ) ) # Initialize headsets for headset in range( self.nr_of_headsets ): self.headsets.append( ImecInput( self.blackboard, PatternStrings.SIGNAL_EEG + '%d' % (headset) ) ) # Initialize preprocessing filters for i, channel in enumerate(self.channels): for headset in range( self.nr_of_headsets ): pat = PatternStrings.SIGNAL_EEG + '%d' % (headset) + PatternStrings.CHANNEL + '%d' % (channel) # Add notch filtering notch = FIRFilter( self.blackboard, pat, FilterSettings.NOTCH_NUMTAPS, FilterSettings.NOTCH_FS, FilterSettings.NOTCH_FREQ, 'notch' ) notch.start(name = 'fir_notch' + pat) self.processors.append( notch ) pat += PatternStrings.FILTERNOTCH # Add low-pass filtering lpf = FIRFilter( self.blackboard, pat, FilterSettings.LPF_NUMTAPS, FilterSettings.LPF_FS, FilterSettings.LPF_FREQ, 'lpf' ) lpf.start(name = 'fir_lpf' + pat) self.processors.append( lpf ) # Patterns that will be recorded patterns = [] for headset in range(self.nr_of_headsets): patterns.append( [(PatternStrings.SIGNAL_EEG + '%d' % (headset) + PatternStrings.CHANNEL + '%d' % (i)) for i in self.channels]) names = [SignalNames.RAWSIGNAL for _ in self.channels ] # Initialize recorders for i, pat in enumerate(patterns): rec = FileRecorder( self.blackboard, pat, self.channels, names, writer=IMECWriter() ) rec.start( interval=10, name = 'recorder-%d' % i ) self.filerecorders.append( rec ) # Perform FFT only on raw signals patterns = [] for headset in range(self.nr_of_headsets): patterns.append( [(PatternStrings.SIGNAL_EEG + '%d' % (headset) + PatternStrings.CHANNEL + '%d' % (i)) for i in self.channels] ) # Initialize FFT analyzer freqspec = FFTAnalyzer(self.blackboard, sum(patterns, [])) # NOTE: Could be made faster by using for's i.s.o. sum, but for init-code not really relevant #freqspec.start() DO NOT START FFT AT INIT self.processors.append( freqspec ) # Initialize Arousal processors for headset in range(self.nr_of_headsets): patterns = [] for channel in [1,3]: for freq in [PatternStrings.ALPHA, PatternStrings.BETA]: patterns.append(PatternStrings.SIGNAL_EEG + '%d' % (headset) + PatternStrings.CHANNEL + '%d' % (channel) + freq) # Initialize Arousal processor arousal = ArousalProcessor(self.blackboard, patterns) #arousal.start() DO NOT START ArousalProcessor AT INIT self.processors.append( arousal )
class TestObserverPattern(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) self.ob1 = Observer() self.ob2 = Observer() self.ob3 = Observer() self.sub = Subject() def test_registration(self): """ Test for adding and removing observers """ self.assertEqual(len(self.sub._observers), 0, "Length should be 0") self.sub.register_observer(self.ob1) self.assertEqual(len(self.sub._observers), 1, "Length should be 1") self.sub.register_observer(self.ob1) self.assertEqual(len(self.sub._observers), 1, "Length should be 1") self.sub.register_observer(self.ob2) self.assertEqual(len(self.sub._observers), 2, "Length should be 2") self.sub.unregister_observer(self.ob3) self.assertEqual(len(self.sub._observers), 2, "Length should be 2") self.sub.unregister_observer(self.ob2) self.assertEqual(len(self.sub._observers), 1, "Length should be 1") self.sub.unregister_observer(self.ob1) self.assertEqual(len(self.sub._observers), 0, "Length should be 0") def test_abstract_notification(self): """ Test whether error is raised when abstract notify method is called """ self.sub.register_observer(self.ob1) self.sub.register_observer(self.ob2) self.assertRaises(NotImplementedError, self.sub.notify_observers) def _test_concrete_notification(self): """ Test whether notify is called in concrete observer """ self.ob1 = SimpleObserver() self.ob2 = SimpleObserver() self.sub.register_observer(self.ob1) self.sub.register_observer(self.ob2) self.assertFalse(self.ob1._notified) self.assertFalse(self.ob2._notified) self.sub.notify_observers() self.assertTrue(self.ob1._notified) self.assertTrue(self.ob2._notified) def tearDown(self): unittest.TestCase.tearDown(self)