def test_passthrough(): """ Pass-through pipeline test m: .--------. | | +- b -. | | | | --+ +==+== | | '- c -' p: -- a - m = d -- """ b = _FBlock() c = _GBlock() m = pipeline.Passthrough((b, c)) a = _FBlock() d = _ThreeIn() p = pipeline.Pipeline([a, m, d]) result = p.process(data) ares = _f(data) assert result == _threein(ares, _f(ares), _g(ares))
def test_parallel_clear(): # see issue #70 p = pipeline.Pipeline([ (_FBlock(), _GBlock()), _TwoIn() ]) out = p.process(data) p.clear()
def test_clear_pipeline(): init = 4 b = _Stateful(init) p = pipeline.Pipeline([b]) p.process(data) p.clear() assert b.data == init
def test_clear(): # clearing a stateful block. init = 4 b = _Stateful(init) p = pipeline.Pipeline([b]) p.process(data) assert b.data == _f(data) b.clear() assert b.data == init
def test_block_access(): # test access to blocks in a pipeline using `named_blocks`. a = _NamedBlock(name='a') b = _NamedBlock(name='b') p = pipeline.Pipeline([a, b]) assert p.named_blocks['a'] is a assert p.named_blocks['b'] is b assert p.named_blocks['a'] is not b assert p.named_blocks['b'] is not a
def test_series(): """ Simple series test: -- a - b -- """ a = _FBlock() b = _GBlock() p = pipeline.Pipeline([a, b]) result = p(data) assert result == _g(_f(data))
def test_composite(): """ Composite pipeline (pipeline within a pipeline): m: -- a - b -- p: .- m -. | | --+ += d -- | | '- c -' """ a = _FBlock() b = _GBlock() m = pipeline.Pipeline([a, b]) c = _FBlock() d = _TwoIn() p = pipeline.Pipeline([(m, c), d]) result = p.process(data) assert result == _twoin(_g(_f(data)), _f(data))
def test_channel_selector(): fe = pipeline.FeatureExtractor( [('0', _NthSampleFeature(0)), ('2', _NthSampleFeature(2))], channel_names=['channel_1', 'channel_2', 'channel_3']) cs = pipeline.ChannelSelector( channels=['channel_1', 'channel_3'], channel_indices=fe.channel_indices) pipe = pipeline.Pipeline([fe, cs]) data = np.array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]) truth = np.array([0, 10, 2, 12]) assert_array_equal(truth, pipe.process(data))
def test_feature_selector(): fe = pipeline.FeatureExtractor( [('N0', _NthSampleFeature(0)), ('N2', _NthSampleFeature(2))], n_channels=3) fs = pipeline.FeatureSelector( features=['N2'], feature_indices=fe.feature_indices) pipe = pipeline.Pipeline([fe, fs]) data = np.array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]) truth = np.array([2, 7, 12]) assert_array_equal(truth, pipe.process(data))
def test_callable_block(): # test block creation from function a = _FBlock() b = pipeline.Callable(_g) p = pipeline.Pipeline([a, b]) result = p.process(data) assert result == _g(_f(data)) # lambdas work too a = pipeline.Callable(lambda x: x + 2) assert a.process(3) == 5 # check that naming works -- use name of function, not the class a = pipeline.Callable(_g) assert a.name == '_g'
def test_hooks(): # test hooks for intermediate blocks. def hook1(out): assert out == _f(data) def hook2(out): assert out == _f(data) # first test just one hook a = _HookEnabledBlock(hooks=[hook1]) b = _GBlock() p = pipeline.Pipeline([a, b]) result = p.process(data) assert result == _g(_f(data)) # test multiple hooks a = _HookEnabledBlock(hooks=[hook1, hook2]) p = pipeline.Pipeline([a, b]) result = p.process(data) assert result == _g(_f(data))
def test_named_subpipeline(): # any block that wraps a sub-pipeline is accessible through # ``named_blocks``, but the sub-pipeline blocks are not a = _NamedBlock(name='sub_a') b = _NamedBlock(name='sub_b') c = _NamedBlock(name='c') passthrough = pipeline.Passthrough([a, b], name='passthrough') p = pipeline.Pipeline([passthrough, c]) names = list(p.named_blocks) assert 'passthrough' in names assert 'c' in names assert 'sub_a' not in names assert 'sub_b' in p.named_blocks['passthrough'].named_blocks
def test_parallel(): """ Simple parallel structure: .- a -. | | --+ +== | | '- b -' """ a = _FBlock() b = _GBlock() p = pipeline.Pipeline((a, b)) result = p.process(data) assert result == [_f(data), _g(data)]
def test_parallel_series(): """ Simple parallel to series structure: .- a -. | | --+ += c -- | | '- b -' """ a = _FBlock() b = _GBlock() c = _TwoIn() p = pipeline.Pipeline([(a, b), c]) result = p.process(data) assert result == _twoin(_f(data), _g(data))
self.finish() if key == util.key_q: sys.exit() else: super().key_press(key) # dev = NoiseGenerator(rate=2000, num_channels=1, read_size=200) dev = TrignoEMG(channel_range=(0, 0), samples_per_read=200, units='mV') exp = Experiment(daq=dev, subject='test') 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),
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), CursorFollowing(main_pipeline))
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))