Пример #1
0
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'
Пример #2
0
def test_callable_block_with_args():
    # pass additional args/kwargs to the function
    def func(data, param, kwarg=None):
        return param, kwarg

    a = pipeline.Callable(func, func_args=(42,), func_kwargs={'kwarg': 10})
    assert a.process(3) == (42, 10)
Пример #3
0
            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))
Пример #4
0
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
Пример #5
0
    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))