Episode 1: Paradigm Presenter

Start a g.tec Paradigm Presenter paradigm from a g.Pype window with the ParadigmPresenter widget, and bring its stimulus codes into the pipeline.

Paradigm Presenter is g.tec’s program for showing stimuli, pictures, sounds and text, on a fixed schedule. This episode starts a paradigm from a g.Pype window and brings its stimulus codes into the pipeline, where the next episodes cut the EEG around them.

Before you start
  • This runs on Windows only. The widget drives g.tec’s Paradigm Presenter, which is installed and licensed separately; its Python package, gtec_pp, comes with pip install "gpype[devices]" on Windows. On macOS and Linux, creating a ParadigmPresenter raises ParadigmPresenter is only supported on Windows.

A paradigm is an XML file

It lists tasks, a picture, a sound or a text and how long it stays, and the order to run them in. Any stimulus can carry a UdpMessage: the moment it appears, Paradigm Presenter sends that number over UDP to the address the paradigm names. Every paradigm in the examples’ paradigms folder sends to 127.0.0.1, port 1000.

11# Every paradigm in this folder sends its codes to 127.0.0.1, port 1000
12PARADIGMS = os.path.join(os.path.dirname(os.path.abspath(__file__)),
13                         "paradigms")
The widget receives the codes

ParadigmPresenter is a UDPReceiver itself, the receiver of Season 4, Episode 4, listening at its default port, which is the port the paradigms send to. So it joins the pipeline like any source, and no second receiver is needed. Each code arrives as its value, followed a moment later by a 0. A Router puts that channel beside the eight generated ones, and three markers watch it for the codes 1, 2 and 3.

20    source = gp.Generator(sampling_rate=250, channel_count=8,
21                          signal_frequency=10, signal_amplitude=10,
22                          noise_amplitude=10)
23
24    # The presenter receives its codes itself: port 1000 is the default
25    # on both ends
26    presenter = gp.ParadigmPresenter(PARADIGMS)
27
28    # The generator's 8 channels, then the codes on channel 8
29    router = gp.Router(input_channels=[gp.Router.ALL, gp.Router.ALL])
30
31    mk = gp.TimeSeriesScope.Markers
32    markers = [mk(color="r", label="task 1", channel=8, value=1),
33               mk(color="c", label="task 2", channel=8, value=2),
34               mk(color="y", label="task 3", channel=8, value=3)]
35    scope = gp.TimeSeriesScope(amplitude_limit=30, time_window=10,
36                               markers=markers, hidden_channels=[8])
37
38    p.connect(source, router["in1"])
39    p.connect(presenter, router["in2"])
40    p.connect(router, scope)
The widget starts and stops it

Give ParadigmPresenter a folder, and it lists every .xml file in it to choose from; give it one file, and it loads that; give it nothing, and it shows a Load Paradigm… button. Start and Stop run the paradigm, and the codes it sends come back to the same widget.

42    # The widget lists the folder's paradigms, and starts and stops the
43    # one you pick
44    app.add_widget(presenter)
45    app.add_widget(scope)
Result

Run the script, pick a paradigm from the list and press Start. Each stimulus’s code appears as a marker on the sample it arrived on. The next episodes use this setup for real experiments: one repeated tone (Episode 3), a rare and a frequent tone (Episode 4), and faces among checkerboards (Episode 5).

S5E1 example screenshot

Figure 35: The presenter’s controls, and the running paradigm’s codes marked on the signal.

Summary

In this episode, you learned how to:

  • start and stop a paradigm from a g.Pype window with ParadigmPresenter

  • know what a paradigm’s XML carries, and where it sends its codes

  • take those codes into the pipeline through the widget itself, and mark them beside the signal

Proceed to Episode 2, where the signal is cut into epochs around events and the epochs are averaged.

Nodes in this episode: Generator, Router, TimeSeriesScope, ParadigmPresenter

File s5e1_paradigm_presenter.py – View file on GitHub

 1"""Season 5, Episode 1: a paradigm's stimulus codes, received as they fire.
 2
 3Windows only: the widget drives g.tec's Paradigm Presenter, installed
 4and licensed separately; its Python package comes with gpype[devices].
 5"""
 6
 7import os
 8
 9import gpype as gp
10
11# Every paradigm in this folder sends its codes to 127.0.0.1, port 1000
12PARADIGMS = os.path.join(os.path.dirname(os.path.abspath(__file__)),
13                         "paradigms")
14
15if __name__ == "__main__":
16
17    app = gp.MainApp()
18    p = gp.Pipeline()
19
20    source = gp.Generator(sampling_rate=250, channel_count=8,
21                          signal_frequency=10, signal_amplitude=10,
22                          noise_amplitude=10)
23
24    # The presenter receives its codes itself: port 1000 is the default
25    # on both ends
26    presenter = gp.ParadigmPresenter(PARADIGMS)
27
28    # The generator's 8 channels, then the codes on channel 8
29    router = gp.Router(input_channels=[gp.Router.ALL, gp.Router.ALL])
30
31    mk = gp.TimeSeriesScope.Markers
32    markers = [mk(color="r", label="task 1", channel=8, value=1),
33               mk(color="c", label="task 2", channel=8, value=2),
34               mk(color="y", label="task 3", channel=8, value=3)]
35    scope = gp.TimeSeriesScope(amplitude_limit=30, time_window=10,
36                               markers=markers, hidden_channels=[8])
37
38    p.connect(source, router["in1"])
39    p.connect(presenter, router["in2"])
40    p.connect(router, scope)
41
42    # The widget lists the folder's paradigms, and starts and stops the
43    # one you pick
44    app.add_widget(presenter)
45    app.add_widget(scope)
46
47    p.start()
48    app.run()
49    p.stop()
50    p.close()