Online analysis with Python

Hi Ant,

I tried several combinations of python and mworks versions and could not manage to read datafiles neither online nor offilen.

Reading data files online (i.e. while they’re still being written) isn’t supported. However, you certainly should be able to read them offline. Can you tell me more about the errors you were encountering?

Regarding the “initialization of _mworks raised unreported exception” error, is it possible that you’re seeing
this issue?

I wanted to ask you in advance if you could give me a hint on how to set up the Python Bridge script and how to setup the mwel experiment itself to work with the bridge.

I’ve posted an updated Python bridge plotting demo on GitHub. It should be a good starting point for working with the Python bridge in the nightly build.

The Conduit class (in file conduit.py) hides some of the hairier details and sets things up so that any matplotlib windows you open remain responsive. You should be able to use it with multiple experiments without modification.

The experiment-specific Python file (python_bridge_plotting_demo.py) defines an event handler function that receives updated values for variables of interest, processes them in some way, and then draws one or more plots. It also invokes Conduit.main, passing it the custom function and the list of variable names to monitor. (Note that the function should not call pyplot.show, as that’s handled by Conduit.main.)

The only thing that the experiment file (python_bridge_plotting_demo.mwel) needs to do is tell the Python script when to start/stop collecting events. This is done via two variables (called start and stop in the example). Assigning a value to the first variable tells the script to begin collecting events. Assigning a value to the second variable tells the script to stop collection events and invoke the event handler function on the collected events. The example assigns start/stop at the beginning/end of each trial, respectively.

To use the example, first load the experiment, then load the experiment-specific Python file via the Python script bridge window. The first time you load the script, you’ll also have to select the Python executable to use (e.g. python3 in your local Anaconda installation).

Also, is it the bridge going to be kept in future versions of MWorks?

Yes.

Cheers,
Chris