Skip to content

Sending_Events_and_Timing_Check

Jin Jeon edited this page Nov 1, 2018 · 2 revisions

Using pyns_auto.py, we can test PsychoPy events are sent properly and in timely manner. The file uses PyNetStation module to let PsychoPy communicate with NetStation. Core components of the module are summarized in PyNetStation Code Summary.

Sending Events

  1. Clone the repository if you haven't done so by:
git clone https://github.com/vucml/psychopynetstation.git
  1. Make sure PsychoPy computer is connected to NetStation computer, and that proper acquisition setup is loaded and turned 'on'.

  2. Navigate to basic folder and open pyns_auto.py in either PsychoPy or simply Python
    - Using Python, type:

python -i pyns_auto.py
  1. This will start sending total 5 events labeled 'auto' to NetStation with +1 second increments. Also, type beep() to send custom event labeled 'beep'



  2. Once 5 auto events are sent, Close recording in NetStation, and exit python or PsychoPy

  3. Check the resulted files in: A. PsychoPy computer: check that autolog.csv is created in the basic folder B. NetStation computer: check the recording file name

Exporting NetStation Events

We will now compare timing difference between events logged in PsychoPy and NetStation. Before, we need to export NetStation events to text file

  1. In NetStation top menu bar, go to Tools > Waveform Tools
    - Note, Waveform Tools is essential tool for exporting and cleaning data. It is also used in deriving ERP

  2. Click Add or drag the recording file to the Inputs box



  3. Click Create... and select Event Export

  4. Name the event type and change the settings as below. You can ignore the "Available event types". You can exit by clicking 'x'




  5. Click 'Run' and it will process your uploaded recording file to export just the events as text file

  6. Move the resulted NetStation event text file to your PsychoPy basic folder, and rename it to something like 'nslog'. From this on, this text file will be referred to as 'nslog'.

Comparing Timing Difference

Now that we have both log files from both PsychoPy and NetStation, we will check for timing difference to make sure that there is no significant delay in events being sent to NetStation.

  1. In terminal,
python -i auto_compare_log.py 
  1. In python,
auto_compare_log('nslog') # insert your renamed NetStation event name with quotation marks

This should print something like:

average delay between nslog and pylog: [6, 2, 0, 5]
average difference is 3.25ms

Here average difference is the average of the list of difference (6 + 2 + 0 + 5) / 4 ** What the function basically does is that it extracts out and cleans all the timestamps from each Psychopy log and NetStation log. Then in each of the log, the timestamps are subtracted. ie. timestamp2 - timestamp1, timestamp3 - timestamp 2, ..., and timestampN - timestamp(N-1) in order to find the relative timing difference. Then the two differences are compared to find the average relative difference.

** If you have average difference above 15-20ms, it is a bad sign that there is some delay between PsychoPy and NetStation