class AlphaSignalPlotter(RawSignalPlotter): def __init__(self, person, eegData, signals, filePath, save=True, plot=True, logScale=False): RawSignalPlotter.__init__(self, person, eegData, signals, filePath, save, plot, logScale, name="alpha") self.eegUtil = EEGUtil() def _getData(self, signal): column = self.eegData.getColumn(signal) samplingRate = self.eegData.getSamplingRate() return self.eegUtil.getAlphaWaves(column, samplingRate)
class EEGProcessor(object): def __init__(self, verbose=False): self.samplingRate = ConfigProvider().getEmotivConfig().get("samplingRate") self.qualUtil = QualityUtil() self.eegUtil = EEGUtil() self.verbose = verbose def process(self, proc): alpha = self.eegUtil.getAlphaWaves(proc, self.samplingRate) invalid = self.qualUtil.isInvalidData(alpha) return alpha, invalid
class FeatureExtractor(object): ''' Controls the processing chain and fetches the values needed for the classificator ''' def __init__(self, dataCollector): self.inputQueue = Queue() self.outputQueue = Queue() self.extractQueue = Queue() self.sigUtil = SignalUtil() self.eegUtil = EEGUtil() self.collector = dataCollector self.collectorThread = threading.Thread(target=self.collector.collectData) self.processor = DataProcessor(self.inputQueue, self.outputQueue) self.processingThread = threading.Thread(target=self.processor.processData) self.extract = True def start(self): '''setting data handler and starts collecting''' print("%s: starting feature extractor" % self.__class__.__name__) self.collector.setHandler(self.handleDataSet) self.collectorThread.start() self.processingThread.start() while self.extract: try: procData = self.outputQueue.get(timeout=1) self.extractFeatures(procData) except Empty: pass def extractFeatures(self, data): features = [] for _, sigData in data.iteritems(): theta = self.eegUtil.getThetaChannel(sigData["fft"]) features.extend(theta) self.extractQueue.put(array(features)) def handleDataSet(self, data): '''Add the given data to the processingQueue''' self.inputQueue.put(data) def close(self): self.processor.close() self.processingThread.join() self.collector.close() self.collectorThread.join() print("%s: closing feature extractor" % self.__class__.__name__)
class DeltaSignalPlotter(RawSignalPlotter): def __init__(self, person, eegData, signals, filePath, save=True, plot=True, logScale=False): RawSignalPlotter.__init__(self, person, eegData, signals, filePath, save, plot, logScale, name="delta") self.chain = SignalProcessor() self.eegUtil = EEGUtil() def _getData(self, signal): raw = self.eegData.getColumn(signal) qual = self.eegData.getQuality(signal) samplingRate = self.eegData.getSamplingRate() proc, _ = self.chain.process(raw, qual) proc = QualityUtil().replaceNans(proc) return self.eegUtil.getDeltaWaves(proc, samplingRate)
def __init__(self, dataCollector): self.inputQueue = Queue() self.outputQueue = Queue() self.extractQueue = Queue() self.sigUtil = SignalUtil() self.eegUtil = EEGUtil() self.collector = dataCollector self.collectorThread = threading.Thread(target=self.collector.collectData) self.processor = DataProcessor(self.inputQueue, self.outputQueue) self.processingThread = threading.Thread(target=self.processor.processData) self.extract = True
def plotEEGChannel(self, fft, channel, freqRange, axChan): eeg_util = EEGUtil() channels = eeg_util.getChannels(fft) axChan.doPlot(range(*freqRange), channels[channel], color='k') axChan.set_xlabel('Frequency (Hz)') axChan.set_ylabel(channel)
def __init__(self, verbose=False): self.samplingRate = ConfigProvider().getEmotivConfig().get("samplingRate") self.qualUtil = QualityUtil() self.eegUtil = EEGUtil() self.verbose = verbose
def __init__(self, person, eegData, signals, filePath, save=True, plot=True, logScale=False): RawSignalPlotter.__init__(self, person, eegData, signals, filePath, save, plot, logScale, name="alpha") self.eegUtil = EEGUtil()
def setUp(self): self.util = EEGUtil()
class TestEEGUtil(unittest.TestCase): def setUp(self): self.util = EEGUtil() def test__getSliceParams(self): for _, freqRange in self.util.channel_ranges.iteritems(): self.assertEqual(type(self.util._getSliceParam(freqRange)[0]), int) def test_getChannels_short(self): data = [1, 2, 3, 4, 5, 6, 7, 8] channels = self.util.getChannels(data) self.assertTrue(len(channels) == 5) self.assertTrue(len(channels["delta"]) > 0) self.assertTrue(len(channels["theta"]) > 0) self.assertTrue(len(channels["alpha"]) == 0) def test_getChannels(self): fft = TEST_DATA_12000Hz channels = self.util.getChannels(fft) flattenChannels = np.hstack(channels.values()) self.assertTrue(all([x in fft for x in flattenChannels])) self.assertTrue(len(flattenChannels) <= len(fft)) def test_getSingleChannels(self): fft = TEST_DATA_12000Hz channels = self.util.getChannels(fft) delta = self.util.getDeltaChannel(fft) # TODO delta range from 0.5 to 4Hz, actual range from 1 - 4Hz self.assertEqual(len(delta), 3) self.assertTrue(all([x in channels["delta"] for x in delta])) theta = self.util.getThetaChannel(fft) self.assertEqual(len(theta), 4) self.assertTrue(all([x in channels["theta"] for x in theta])) alpha = self.util.getAlphaChannel(fft) self.assertEqual(len(alpha), 5) self.assertTrue(all([x in channels["alpha"] for x in alpha])) beta = self.util.getBetaChannel(fft) self.assertEqual(len(beta), 17) self.assertTrue(all([x in channels["beta"] for x in beta])) gamma = self.util.getGammaChannel(fft) self.assertEqual(len(gamma), len(range(*self.util.channel_ranges["gamma"]))) self.assertTrue(all([x in channels["gamma"] for x in gamma])) def test_getWaves(self): eegData = EEGTableFileUtil().readFile(PATH + "example_32.csv") eeg = eegData.getColumn("F3") nEeg = len(eeg) waves = self.util.getWaves(eeg, eegData.getSamplingRate()) self.assertEqual(len(waves), 5) for _, wave in waves.iteritems(): self.assertEqual(len(wave), nEeg) def test_getSingleWaves(self): eegData = EEGTableFileUtil().readFile(PATH + "example_32.csv") eeg = eegData.getColumn("F3") nEeg = len(eeg) samplingRate = eegData.getSamplingRate() waves = self.util.getWaves(eeg, samplingRate) delta = self.util.getDeltaWaves(eeg, samplingRate) self.assertEqual(len(delta), nEeg) self.assertTrue(all([x in waves["delta"] for x in delta])) theta = self.util.getThetaWaves(eeg, samplingRate) self.assertEqual(len(theta), nEeg) self.assertTrue(all([x in waves["theta"] for x in theta])) alpha = self.util.getAlphaWaves(eeg, samplingRate) self.assertEqual(len(alpha), nEeg) self.assertTrue(all([x in waves["alpha"] for x in alpha])) beta = self.util.getBetaWaves(eeg, samplingRate) self.assertEqual(len(beta), nEeg) self.assertTrue(all([x in waves["alpha"] for x in alpha])) gamma = self.util.getGammaWaves(eeg, samplingRate) self.assertEqual(len(gamma), nEeg) self.assertTrue(all([x in waves["gamma"] for x in gamma]))
def __init__(self, person, eegData, signals, filePath, save=True, plot=True, logScale=False): RawSignalPlotter.__init__(self, person, eegData, signals, filePath, save, plot, logScale, name="delta") self.chain = SignalProcessor() self.eegUtil = EEGUtil()