{"id":242,"date":"2015-04-01T10:30:56","date_gmt":"2015-04-01T09:30:56","guid":{"rendered":"http:\/\/blogs.kent.ac.uk\/psychotech\/?p=242"},"modified":"2020-05-29T11:54:17","modified_gmt":"2020-05-29T10:54:17","slug":"fixing-eeg-marker-data-for-brainvision-recorder","status":"publish","type":"post","link":"https:\/\/blogs.kent.ac.uk\/hsstech\/2015\/04\/01\/fixing-eeg-marker-data-for-brainvision-recorder\/","title":{"rendered":"Fixing EEG marker data for Brainvision Recorder"},"content":{"rendered":"<p>A research student recently had an issue with their EEG data from a recently completed study. During the early stages, the parallel cable connection had been disturbed between the EEG PC and the Stimulus PC, which had resulted in triggers being sent at key points of the experiment, but with completely different values than originally specified.<\/p>\n<p>Markers are indications within the Brainvision Recorder software of when key events occur that you want to \u201cmark\u201d for later analysis. In the case of this experiment, when particular responses or stimuli were presented onto the screen, particular marker numbers would be fired down the parallel port and embedded into the EEG data.<\/p>\n<p>Luckily the issue was detected early on and fixed for the majority of participants, but this still left around 6 participant data files with incorrect markers.<\/p>\n<p>For most cases, Brainvision Analyser offers the opportunity to replace all data markers with another value. This is all well and good if the marker sent is unique to the event. In this particular case, when the parallel connection had corrupted &#8211; the same event marker value was put in. Luckily the experiment also records its own participant data file, which has details of what stimuli were shown and when &#8211; so by hand, you could go through both sets of data simultaneously and work out what the code was. To do this though could take you probably an entire day per participant file, and probably leave you seeing marker numbers and mumbling expletives about parallel cables in your sleep.<\/p>\n<h2>Avoiding unnecessary pain<\/h2>\n<p>Thankfully, for analysis and replacement of this scale, you can automate the process using a programming language like Python &#8211; which in this case is exactly what was done.<\/p>\n<p>When talking through with the researcher, we obtained what conditions from the stimuli data file would indicate which marker flag to be expected. Next we established how the marker data was stored &#8211; which is luckily in a separated data file with a \u201c.vmrk\u201d extension. The marker data is just a flat list in sequence, so the other key detail is to correlate how many marker events will occur within a single trial loop (3 in this case). So as we read in a single trial and check its conditions, we apply the conditions on only those amount of markers at one time per trial.<\/p>\n<p>PsychoPy experiments output a CSV data file, and the .vmrk file is also conveniently a form of CSV. Python can easily read in CSV data and turn into an array with a few short commands, after which we could simply loop through the data, apply the conditional checks as we go to the marker array created. Once we have finished processing all our trials &#8211; we just save the contents of the marker array, to create our replacement .vmrk file.<\/p>\n<p>Replacing this within the Brainvision data directory, we just need to remove any history files for the analyser to pick up the changed marker data.<\/p>\n<p>The script was less than an afternoon\u2019s work, and very simple in its implementation to \u201cget the job done\u201d. Most of the simplicity was thanks to the power of Python and how simple it can be to create your own scripts to do data processing or fixing for you. This particular script runs over command line, and takes two arguments &#8211; firstly a PsychoPy data CSV file, followed by the corresponding .VMRK file. Within a matter of seconds, the changes are made and the new file outputted into an output directory with the same file name (pre-existing files are overwritten).<\/p>\n<p>E.g.<\/p>\n<p><strong>&gt; python convert.py input\/psychopydata.csv input\/participant01.vmrk<\/strong><\/p>\n<p>The script used has been attached below in case you want to take a look at it and see how it was done. Comments have been left throughout to indicate what each part is doing &#8211; so hopefully if you come to do something similar, you can adapt or re-use parts for your own scripts.<\/p>\n<p><a href=\"https:\/\/www.kent.ac.uk\/school-of-psychology\/downloads\/technical\/marker-script.zip\">Download example script<\/a><\/p>\n<p>More details on data processing from John can also be found here:<\/p>\n<p><a href=\"http:\/\/blogs.kent.ac.uk\/psychotech\/2013\/08\/01\/data-programming-support-for-working-with-large-data-files\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/blogs.kent.ac.uk\/psychotech\/2013\/08\/01\/data-programming-support-for-working-with-large-data-files\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A research student recently had an issue with their EEG data from a recently completed study. During the early stages, the parallel cable connection had &hellip; <a href=\"https:\/\/blogs.kent.ac.uk\/hsstech\/2015\/04\/01\/fixing-eeg-marker-data-for-brainvision-recorder\/\">Read&nbsp;more<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16561,56647],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.kent.ac.uk\/hsstech\/wp-json\/wp\/v2\/posts\/242"}],"collection":[{"href":"https:\/\/blogs.kent.ac.uk\/hsstech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.kent.ac.uk\/hsstech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/hsstech\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/hsstech\/wp-json\/wp\/v2\/comments?post=242"}],"version-history":[{"count":4,"href":"https:\/\/blogs.kent.ac.uk\/hsstech\/wp-json\/wp\/v2\/posts\/242\/revisions"}],"predecessor-version":[{"id":522,"href":"https:\/\/blogs.kent.ac.uk\/hsstech\/wp-json\/wp\/v2\/posts\/242\/revisions\/522"}],"wp:attachment":[{"href":"https:\/\/blogs.kent.ac.uk\/hsstech\/wp-json\/wp\/v2\/media?parent=242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/hsstech\/wp-json\/wp\/v2\/categories?post=242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/hsstech\/wp-json\/wp\/v2\/tags?post=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}