Explaining running_subprocess in the mne.utils library

MNE Version: 1.2
OS: Windows 10
I have been having issue understanding how running_subprocess is working in the mne_realtime examples. There is no API documentation on the mne website regarding this function and the function’s parameters are quite different from the subprocess functions in python. If there is anyone who has any information on what parameters can be passed, I would be grateful:

Here is the docstring: mne-python/misc.py at 6c3a159824c41ffac40e289da601fb57de3649ba · mne-tools/mne-python · GitHub

If I take this example from MNE-realtime: Compute real-time evoked responses with FieldTrip client — MNE-Realtime 0.3.dev0 documentation

running_subprocess is used here:

speedup = 10
command = ["neuromag2ft", "--file",
           "{}/MEG/sample/sample_audvis_raw.fif".format(data_path),
           "--speed", str(speedup)]
with running_subprocess(command, after='kill',
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE):
    with FieldTripClient(host='localhost', port=1972,
                         tmax=30, wait_max=5, info=info) as rt_client:

Let’s dissect it:

  • As a context manager, running_subprocess runs the command neuromag2ft. Based on the name, it looks like it’s a way to take a neuromag recording (FIFF) and to send it to a fieldtrip buffer (ft). The command is run with the arguments provided in the list command, overall:
neuromag2ft --file path/to/sample/dataset/MEG/sample/sample_audvis_raw.fif --speed 10
  • As a context manager, a FieldTrip client is created as rt_client.

I don’t know how the FieldTrip buffer system works, but it looks like the first context manager creates a server with simulated/fake data while the second context manager creates the client and connects to the server to receive data in real-time.

This is also explained at the beginning of the tutorial, with a link to the version of neuromag2ft used.

2 Likes