def test_windower_short(): # make sure an exception is raised if the window length is too short data = rand_data_2d windower = pipeline.Windower(data.shape[1]-1) with pytest.raises(ValueError): windower.process(data)
def test_windower_1d(): # make sure a 1D array raises an error data = np.array([1, 2, 3, 4]) windower = pipeline.Windower(10) with pytest.raises(ValueError): windower.process(data)
def test_windower_overlap(): # make sure window overlap works correctly data = rand_data_2d windower = pipeline.Windower(13) for samp in _window_generator(data, 10): win = windower.process(samp) assert_array_equal(win, data[:, -13:])
def test_windower_no_overlap(): # make sure windower handles data the same length as the window data = rand_data_2d windower = pipeline.Windower(10) for samp in _window_generator(data, 10): win = windower.process(samp) assert_array_equal(win, data[:, -10:])
def test_windower_clear(): # make sure clearing the windower allows for changing number of channels data = rand_data_2d windower = pipeline.Windower(data.shape[1]+1) windower.process(data) with pytest.raises(ValueError): windower.process(rand_data_2d1) windower.clear() windower.process(rand_data_2d1)
def key_press(self, key): if key == util.key_escape: self.finish() else: super().key_press(key) if __name__ == '__main__': # from pytrigno import TrignoEMG # dev = TrignoEMG((0, 3), 200, host='192.168.1.114', units='normalized') from axopy.daq import NoiseGenerator dev = NoiseGenerator(rate=2000, num_channels=4, read_size=200) b, a = butter(4, (10 / 2000. / 2., 450 / 2000. / 2.), 'bandpass') preproc_pipeline = pipeline.Pipeline([ pipeline.Windower(400), pipeline.Centerer(), pipeline.Filter(b, a=a, overlap=200), ]) main_pipeline = pipeline.Pipeline([ preproc_pipeline, pipeline.Callable(mean_absolute_value, func_kwargs={ 'weights': 'mav', 'axis': -1, 'keepdims': False }), RLSMapping(4, 2, 0.99) ]) Experiment(daq=dev, subject='test').run(Oscilloscope(preproc_pipeline),
config = exp.configure(numbands=int) # TODO: figure out how to do this recursively b, a = butter(1, .1, fs=2000, btype='lowpass') lowpassfilter = pipeline.Pipeline([pipeline.Filter(b, a=a, overlap=200)]) b, a = butter(4, (40, 60), fs=2000, btype='bandpass') lowfilter = pipeline.Pipeline([pipeline.Filter(b, a=a, overlap=200)]) b, a = butter(4, (80, 100), fs=2000, btype='bandpass') highfilter = pipeline.Pipeline([pipeline.Filter(b, a=a, overlap=200)]) b, a = butter(4, (120, 140), fs=2000, btype='bandpass') midfilter = pipeline.Pipeline([pipeline.Filter(b, a=a, overlap=200)]) main_pipeline = pipeline.Pipeline([ pipeline.Windower(1000), pipeline.Passthrough([(lowfilter, highfilter, midfilter), FFT(), pipeline.Callable(integrated_emg), exponentialsmoothing()]) ]) exp.screen.showFullScreen() while True: exp.run( # Oscilloscope(pipeline.Windower(2000)), # Exertion(main_pipeline) PartialPowers(main_pipeline)) break
def finish(self): self.daqstream.stop() self.finished.emit() def key_press(self, key): if key == util.key_escape: self.finish() else: super().key_press(key) if __name__ == '__main__': from axopy.daq import NoiseGenerator dev = NoiseGenerator(rate=1000, num_channels=4, read_size=100) b, a = butter(4, (10 / 2000. / 2., 450 / 2000. / 2.), 'bandpass') pipeline = pipeline.Pipeline([ pipeline.Windower(200), # 200 ms windows pipeline.Filter(b, a=a, overlap=100), # pipeline.Callable(mean_absolute_value, func_kwargs={ 'axis': 1, 'keepdims': False }), Scaler(factor=5.), FeatureAverage() ]) exp = Experiment(daq=dev, subject='test') exp.run(ValuePrint(pipeline))