mne-tools/mne-python — pull request #382 by mluessi (2013-01-14 21:08:08+00:00)
Title: WIP: Realtime

This is a rework of #213. My idea is to have a real time epochs class `RtEpochs` that behaves similarly to `Epochs`, but the data is received continuously from an mne_rt_server via an `RtClient` instance which pushes the received raw buffers to the `RtEpochs` instance(s). You can e.g. do

import mne
from mne.realtime import RtClient, RtEpochs
client = RtClient('localhost')
rt_epochs = RtEpochs(client, 1, -0.2, 0.5, 5, reject=dict(eeg=80e-6, eog=150e-6))
rt_epochs.start()

while True:
evoked = rt_epochs.average()
mne.viz.plot_evoked(evoked)
pl.show()
time.sleep(0.5)

This code will receive 5 (good) epochs, compute an evoked response, and plot it. Then the next 5 epochs are received (5 because the `n_epochs` parameter in the constructor is 5). The idea is that it will be possible to pass an instance of `RtEpochs` to most functions that accept `Epochs` as input, e.g., `apply_inverse_epochs`, `spectral_connectivity` (for the latter, the `n_epochs` argument is useful, as only `n_epochs` will be used for the connectivity computation).

The code works but one problem is that `RtEpochs` is derived from `Epochs`, which has many methods which don't work when real time processing is used. Right now, those methods are disabled using an ugly hack. The proper solution would be create a new class `BaseEpochs` and derive both `Epochs` and `RtEpochs` from that class. Is anyone opposed to this solution?