Difference between revisions of "Visualization with BESA Plot in FieldTrip"
(→Creating the BESA Plot control file) |
(→Creating the BESA Plot control file) |
||
Line 50: | Line 50: | ||
</source> | </source> | ||
The result after running the script is shown in Figure 1. | The result after running the script is shown in Figure 1. | ||
− | [[File:DipoleFitResults.png| | + | [[File:DipoleFitResults.png|thumb|500px|Figure 1 Dipole fitting results visualized with BESA Plot]] |
Revision as of 13:03, 7 July 2016
BESA Plot is a free tool created by Patrick Berg (BESA GmbH) for visualization of MEEG data. Initially it was meant to be complementary visualization tool to BESA Research, however, it could be used in more general context. In this document we demonstrate the possibility of using BESA Plot as a visualization tool in the Matlab based open source package for MEEG data analysis FieldTrip.
Since BESA Plot can be started with command line arguments, it can be called directly from Matlab and the required input parameters (e.g. data file, settings and plotting modalities) can be committed as such arguments. There are four files necessary for starting BESA Plot from Matlab and visualizing the corresponding data: 1) a data file (e.g. test1.avr), 2) a file containing the channel labels and coordinates (e.g. test1.elp), 3) a control file containing the plotting commands for BESA Plot (e.g. test1.bpctrl) and 4) a dataset file containing general information about the data file (e.g. test1.avr.dataset). These files should be generated dynamically in Matlab in order to be able to plot the Matlab data in BESA Plot.
Generating the data file
First of all we need the data which are going to be saved as an avr-file. This is usually a Matlab structure generated in FieldTrip with the function ft_timelockanalysis. Its general form is something like this:
avg: [147x271 double] var: [147x271 double] time: [1x271 double] dof: [147x271 double] label: {147x1 cell} dimord: 'chan_time' grad: [1x1 struct] cfg: [1x1 struct]
In order to create a data file from that structure one needs the function besa_save2Avr which can be found in the FieldTrip installation in the folder external\besa or can be downloaded directly from BESA’s ftp-server. Just unpack the archive and add the path to the Matlab path (e.g. addpath(‘D:\Path\to\MATLAB2BESA’)). Use the function like this:
status = besa_save2Avr(cfg.datapath, DataFile, data_matrix, ... time_samples, channel_labels, data_scale_factor, time_scale_factor);
Generating the channel file (*.elp)
This file contains the channel type, the channel labels and the spherical coordinates of the channels. It can be created using the function besa_save2Elp again from the package MATLAB2BESA. Use the function like this:
status = besa_save2Elp(cfg.datapath, ElpFile, ... SphericalCoords, channel_labels, channel_type);
Creating the BESA Plot control file
This is the actual plotting script. It follows the syntax of a scripting language defined in BESA Plot. For more details about the scripting language please refer to the program help. For this file format there is no writer function, since it can contain different scripts for different visualization scenarios. One possible script for plotting two dipoles in a schematic head could look like this:
set color=black set size=16 set dipole number=1 xloc=0.645106 yloc=0.159181 zloc=0.288564 xori=0.147790 yori=-0.726931 zori=-0.670619 color=blue length=0.1 diameter=0.05 set dipole number=2 xloc=-0.645106 yloc=0.159181 zloc=0.288564 xori=-0.166429 yori=-0.567066 zori=-0.806683 color=blue length=0.1 diameter=0.05 head width=35 height=40 viewpoint=top brain=on x=20.0 y=75.0 head width=35 height=40 viewpoint=back brain=on x=20.0 y=30.0 head width=35 height=40 viewpoint=left brain=on x=77.0 y=77.0 set dataset=1 set mapuV=18 set mapcolor negative=blue positive=red electrode=none set mapsize=35 set maptype=amplitude set maplambda=1E-5 set mapviewpoint=top set maprange maximumuV=461 minimumuV=-419 zerouV=0.0 contours=on map latency=110.6 end=150.4 step=20 mean=on label=on x=77.0 y=30.0
The result after running the script is shown in Figure 1.