Back to the main page.

Bug 2336 - read the individual FE mesh and the individual leadfields from BESA

Status ASSIGNED
Reported 2013-10-25 12:58:00 +0200
Modified 2014-01-17 08:49:51 +0100
Product: FieldTrip
Component: external_besa
Version: unspecified
Hardware: PC
Operating System: Mac OS
Importance: P3 normal
Assigned to: Robert Spangler
URL:
Tags:
Depends on:
Blocks:
See also:

Robert Oostenveld - 2013-10-25 12:58:30 +0200

excerpt from email: We would like to provide the possibility to integrate the FEM output files created by BESA MRI for Fieldtrip. Therefore, it will be necessary to implement several routines in Matlab which will serve as readers for the FEM output files and will also rearrange the data into structures defined by Fieldtrip. A good starting point might be the implementation of routines to read the individual FE mesh and the individual leadfield in order to test them in a simple forward model with a small number of sources.


Robert Oostenveld - 2013-10-25 13:19:39 +0200

it would be good to have a shared test script with some data. The test script could be located at fieldtrip/external/besa/test_bug2336.m, which is a naming that is consistent with the other test scripts (present in fieldtrip/test). However adding data to SVN is not such a great idea. Once you have some data, I suggest you share it with us over dropbox, ftp, or something similar and that we keep a local copy for reproducing what is in the script.


Robert Spangler - 2013-11-27 14:01:08 +0100

just checked in a test script with the suggested filename (fieldtrip/external/besa/test_bug2336.m). it provides the possibility to read several files generated by BESA MRI, including individual leadfields (*.lft file), the corresponding coordinates of the source space grid nodes (*.loc file), the corresponding electrode configuration (*.sfh file) and the surface of the four modelled layers (scalp, skull, csf, brain; each layer stored in a separate *.srf file). readers for all types of files mentioned above are now also available in the fieldtrip repo (added to readBESAlft.m and readBESAloc.m fieldtrip/extern/besa/). @Robert: how should i provide the test files that are currently used in the test script? Dropbox might be a good option!


Robert Oostenveld - 2013-12-09 09:26:36 +0100

(In reply to comment #2) Hi Robert, I suggest we continue work on this. Can you use one of the methods listed here http://fieldtrip.fcdonders.nl/faq/how_should_i_send_example_data_to_the_developers to send me teh data for the test script? I see that for the BESA leadfield the information is read in readBESAlft and readBESAloc. In the present FT/SPM implementation the positions and leadfields are stored in a collection of 4-D nifti files, i.e. one nifti file per electrode, three volumes per nifti file for the three orientations and space is represented in the native 3-D way. That allows us to use the SPM interpolation routines for dipole space. We discussed the possibility of using irregular source grid spacing, but decided against it as the interpolation becomes more difficult. With the BESA files we'll have to implement this "difficult" interpolation nevertheless.


Robert Oostenveld - 2013-12-16 14:28:34 +0100

Hi Robert, can you fix this: >> readBESAlft('nonexistentfile') Undefined function 'printf' for input arguments of type 'char'. Error in readBESAlft (line 36) printf('Error opening file.\n'); 36 printf('Error opening file.\n'); (it should be fprintf) and could you add the missing readBESAsfh fnuction? thanks, Robert


Robert Spangler - 2013-12-17 10:47:22 +0100

Added function readBESAsfh to read *.sfh files created by BESA Research/MRI


Robert Spangler - 2013-12-17 10:59:12 +0100

changed all printf to fprintf (also see bug #2336) for files: fieldtrip\external\besa\readBESAlft.m fieldtrip\external\besa\readBESAloc.m


Robert Oostenveld - 2013-12-17 12:05:44 +0100

thanks. I have further worked on the test script, ft_prepare_headmodel and ft_headmodel_infinite and will commit the finalized version soon.


Robert Oostenveld - 2013-12-17 12:47:10 +0100

I added support for reading electrode info from the *.sfh file. mac001> svn commit Sending fileio/ft_filetype.m Sending fileio/ft_read_sens.m Transmitting file data .. Committed revision 9037.


Robert Oostenveld - 2013-12-17 13:37:35 +0100

mac001> svn commit Deleting external/besa/test_bug2336.m Sending fileio/ft_read_sens.m Sending forward/ft_headmodel_interpolate.m Sending ft_prepare_headmodel.m Adding test/test_bug2336.m Transmitting file data .... Committed revision 9038. added support for method=besa, i.e. leadfield interpolation based on BESA FEM forward solution. Moved test script to fieldtrip/test. Do not return fiducials, only electrodes. It seems to be functional now, please see fieldtrip/test/test_bug2336 at the end of the script. Creating the nifti volumes is very slow and should be made more efficient. I should check whether the indexing of the x/y/z leadfield column is correct.


Robert Oostenveld - 2013-12-17 14:44:41 +0100

(In reply to Robert Oostenveld from comment #9) mac001> svn commit Sending forward/ft_headmodel_interpolate.m Transmitting file data . Committed revision 9041. Most time was spent in ind2sub, which is now avoided. This makes the writing of the nifti's considerably faster.


Robert Spangler - 2013-12-17 14:47:49 +0100

Added optional input parameter to function fieldtrip\external\besa\readBESAlft.m to specifiy particular channel for which leadfield information should be returned.


Robert Oostenveld - 2013-12-19 09:44:24 +0100

Hi Robert, could you resolve this? Probably you already have the function, but it is not in SVN. I do suggest to call it readBESAsrf for consistency. >> test_bug2336 Number of channels: 31 Number of nodes: 180445 Number of orientations: 3 Number of nodes: 180445 Number of neighbours/node: 6 Undefined function 'ft_read_bv_srf' for input arguments of type 'char'. Error in test_bug2336 (line 56) [pnt_scalp, tri_scalp, srf_scalp] = ft_read_bv_srf(strPath__ScalpSurface);


Robert Spangler - 2013-12-19 12:24:50 +0100

Hello Robert I just checked in the function to read *.srf files created by BESA Research/MRI: fieldtrip\external\besa\readBESAsrf.m Furthermore, I also wanted to adjust the test script fieldtrip\test\test_bug2336.m but I may not have the rights to make any changes in the file. Could you please commit the following changes to the test script? 1. There are changes in the section: % Read electrode config, surface points & fiducials, FIXME this function is missing % sfh = readBESAsfh(strPath__ElectrodeConfig); I would change it to: % Read electrode config & fiducials cfg_eeg = readBESAsfh(strPath__ElectrodeConfig, 'eeg'); cfg_fid = readBESAsfh(strPath__ElectrodeConfig, 'fiducial'); 2. And the second one: % Read scalp, skull, csf & brain surface [pnt_scalp, tri_scalp, srf_scalp] = ft_read_bv_srf(strPath__ScalpSurface); [pnt_skull, tri_skull, srf_skull] = ft_read_bv_srf(strPath__SkullSurface); [pnt_csf, tri_csf, srf_csf] = ft_read_bv_srf(strPath__CSFSurface); [pnt_brain, tri_brain, srf_brain] = ft_read_bv_srf(strPath__BrainSurface); Please change it to: % Read scalp, skull, csf & brain surface cfg_scalp = readBESAsrf(strPath__ScalpSurface); cfg_skull = readBESAsrf(strPath__SkullSurface); cfg_csf = readBESAsrf(strPath__CSFSurface); cfg_brain = readBESAsrf(strPath__BrainSurface); Thanks! Robert


Robert Oostenveld - 2014-01-17 08:47:18 +0100

(In reply to Robert Spangler from comment #13) Robert S has made some code changes yesterday, which I'll post here as well: ------------------------------------------------------------------------ r9105 | robspa | 2014-01-16 18:26:03 +0100 (Thu, 16 Jan 2014) | 1 line bugfix - Changed specification of path to data folder; uncommented function option in first line ------------------------------------------------------------------------ r9104 | robspa | 2014-01-16 18:16:28 +0100 (Thu, 16 Jan 2014) | 1 line bugfix - fixed a problem in reading electrode config & fiducials coordinates, as wel as reading scalp, skull, csf and brain surfaces. Added option to compute individual leadfield based on BESA MRI input on a specific dipole position. also see bugzilla entry #2336 (http://bugzilla.fcdonders.nl/show_bug.cgi?id=2336) ------------------------------------------------------------------------ r9103 | robspa | 2014-01-16 18:11:42 +0100 (Thu, 16 Jan 2014) | 1 line bugfix - fixed a problem in translation of coordinate system; subtract 127.5 (mm) from all axes.


Robert Oostenveld - 2014-01-17 08:49:51 +0100

@Robert S, read_bv_srf is still present in fieldtrip/fileio/private, so you can just use it in ft_read_headshape instead of readBESAsrf. We should consider (to be discussed in Nijmegen) whether to rename ft_read_headshape into ft_read_surface, which better describes what it does.