<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hello<div>in view of your code: first check if</div><div>elec2       = ft_read_sens('standard_1020.elc’);</div><div>corresponds to the channel structure of your functional data (averages).</div><div>Best to Hamburg</div><div>Leo</div><div><br></div><div>—</div><div><br></div><div><br></div><div>Dr. med. Leopold Zizlsperger<br>Klinik für Neurologie<br>Uniklinik RWTH Aachen<br>Pauwelsstrasse 30<br>52074 Aachen<br>Tel: +49 241 80 35465<br><a href="mailto:lzizlsperger@ukaachen.de">lzizlsperger@ukaachen.de</a><br><br><br><img height="53" width="186" apple-inline="yes" id="0032703E-CF7C-48D4-A734-887B42936A46" apple-width="yes" apple-height="yes" src="cid:92708944-0CEA-435B-A687-9E96EE5FFDC4@eduroam.rwth-aachen.de"><br><br><br>Leopold Zizlsperger, MD<br>Department of Neurology<br>RWTH Aachen University<br>Pauwelsstrasse 30<br>52074 Aachen, Germany<br>Tel: +49 241 80 35465<br>lzizlsperger@ukaachen.de<br>
<br>
<br><div><div>On 22 Feb 2014, at 15:38, Chaitanya Srinivas <chaitanya.pro@gmail.com> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div>Hi Thomas, <br><br> When I was working with actual data, once I got this error. At that time, it was the problem of having different number of electrodes for the forward solution (lead-field) i have created and for each subject recording electrodes. Each subject has different set of recording electrodes which gave this problem. I think we have to check the difference in electrodes or number of sensors.<br>
</div><div><br> <br></div></div><div class="gmail_extra"><br clear="all"><div><div dir="ltr"><font face="arial, sans-serif"><b><div style="color:rgb(0,0,153)"><font color="#000099">===============================================</font></div>
</b><br><b><span><image.png></span><br><br></b></font><font face="arial, sans-serif"><b>Best Regards</b></font><font face="arial, sans-serif"><div><b>Chaitanya Srinivas Lanka <br>
<br><span style="color:rgb(153,153,153)">Wiss. Mitarbeiter                                       </span></b><span style="color:rgb(153,153,153)"><b><font face="arial, sans-serif">PhD Student</font><font face="arial, sans-serif"><b><br>
</b></font><span><font><span>Functional and Restorative Neurosurgery </span></font></span><span><font><span><font face="arial, sans-serif">Neural Information Processing</font></span></font></span><span><font><span><br>Neurosurgical University Hospital</span></font></span></b><b><span><font><font face="arial, sans-serif"><b>             </b></font></font></span><span><font><font face="arial, sans-serif">Graduate Training Center for Neuroscience</font></font></span><span><font>  <br>
<span>Eberhard Karls University                          </span></font></span><span><font><font face="arial, sans-serif">Eberhard Karls University</font></font></span><span><font><font face="arial, sans-serif"><b> </b></font><span><br>
</span></font></span></b></span><font face="arial, sans-serif"><span style="color:rgb(153,153,153)"><b><span><font><span>Otfried-Mueller-Str.45</span>                                </font></span>Österbergstr. 3</b></span><b><span style="color:rgb(153,153,153)"><font><span>  <br>
D-72076 Tuebingen</span></font></span>                                    </b><font face="arial, sans-serif"><b><span style="color:rgb(153,153,153)"><font><span>D-72074 Tuebingen</span></font></span></b></font></font><b><br>
</b></div><div><b><font color="#006600">Mobile Phone Number : </font><a value="+4917679038395">+49-176-79035731<br></a></b><a value="+4917679038395"><font face="arial, sans-serif"><b><font color="#000099">===============================================</font></b></font><br>
</a></div>
</font></div></div>
<br><br><div class="gmail_quote">On Sat, Feb 22, 2014 at 2:32 PM, Thomas Sauvigny <span dir="ltr"><<a href="mailto:tsauvigny@gmail.com" target="_blank">tsauvigny@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Dear fellow fiedtrippers,<div><br></div><div>I would like to do a source reconstruction of EEG data using The FielTrip example MRI dataset via minimum-norm estimate. I stick close to the MNE tutorial (<a href="http://fieldtrip.fcdonders.nl/tutorial/minimumnormestimate" target="_blank">http://fieldtrip.fcdonders.nl/tutorial/minimumnormestimate</a>) and use a few steps from the EEG headmodel tutorial as well (<a href="http://fieldtrip.fcdonders.nl/tutorial/headmodel_eeg" target="_blank">http://fieldtrip.fcdonders.nl/tutorial/headmodel_eeg</a>). Unfortunately, I am struggling to combine the information from both tutorials in some crucial step prior to ft_sourceanalysis.</div>
<div>My first approach has been to basically run through the MNE tutorial using the Fieltrip MRI dataset. As I could not save both the original anatomy and the masked anatomy in a freesurfer compatible format while using </div>
<div><br></div><div><div><i>cfg           = [];</i></div><div><i>cfg.output    = {'brain','skull','scalp'};</i></div><div><i>segmentedmri  = ft_volumesegment(cfg, mri);</i></div></div><div><br></div>
<div>I instead proceeded as mentioned below and aligned the electrodes to the scalp in a second step (according to the headmodel tutorial). But when I want to combine the headmodel (vol) and the electrodes (elec_aligned2) into the leadfield, that does not work:</div>
<div><br></div><div><div><i>using headmodel specified in the configuration</i></div><div><i>using electrodes specified in the configuration</i></div><div><i>Error using ft_prepare_vol_sens (line 534)</i></div><div><i>unsupported volume conductor model for EEG</i></div>
<div><i><br></i></div><div><i>Error in prepare_headmodel (line 94)</i></div><div><i>[vol, sens] = ft_prepare_vol_sens(vol, sens, 'channel', cfg.channel, 'order',</i></div><div><i>cfg.order);</i></div><div>
<i><br></i></div><div><i>Error in ft_prepare_leadfield (line 124)</i></div><div><i>[vol, sens, cfg] = prepare_headmodel(cfg, data);</i></div></div><div><br></div><div><br></div><div>When I instead use the volume conduction model built in the headmodel tutorial (vol2) and the sourcespace from the MNE tutorial I get:</div>
<div><br></div><div><i>Error using  * <br>Inner matrix dimensions must agree.<br><br>Error in minimumnormestimate (line 179)<br>      A       = P*A; % prewhitened leadfields<br><br>Error in ft_sourceanalysis (line 869)<br>
        dip(i) = minimumnormestimate(grid, sens, vol, squeeze_avg, optarg{:},<br>        'noisecov', squeeze(Cy(i,:,:)));</i></div><div><br></div><div>In older posts in the mailing list there appeared to be problems with the scaling of the different components and I adapted the units, but that did not solve the problems.</div>
<div>I would be very thankful for any help.</div><div><br></div><div><br></div><div><br></div><div>cheers</div><div>Thomas</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>
<br></div><div><br></div><div>My script:</div><div><br></div><div><div>clear all;</div><div>mri = ft_read_mri('Subject01.mri');</div><div>save mri mri;</div><div>disp(mri)</div><div><br></div><div>cfg            = [];</div>
<div>cfg.resolution = 1;</div><div>cfg.dim        = [256 256 256];</div><div>mrirs          = ft_volumereslice(cfg, mri);</div><div>save mrirs mrirs;</div><div><br></div><div>% segmentation of the mri</div><div>% load mrirs;</div>
<div>cfg           = [];</div><div>cfg.coordsys  = 'ctf';</div><div>cfg.output    = {'skullstrip' 'brain'};</div><div>seg           = ft_volumesegment(cfg, mrirs);</div><div>save seg seg;</div><div>
<br></div><div>disp(seg(1))</div><div><br></div><div>%%% Thus, you need to identify the anterior commissure, the posterior commissure, and an interhemispheric point (which defines the XZ-plane). You can navigate across the slices with the arrows. </div>
<div>%%% By pressing the 'a', 'p', and 'z' at the right locations, the voxel</div><div>%%% coordinates of these landmarks are stored:</div><div>% load mrirs;</div><div>cfg        = [];</div><div>cfg.method = 'interactive';</div>
<div>mri_tal    = ft_volumerealign(cfg, mrirs);</div><div>save mri_tal mri_tal</div><div><br></div><div>clear all;</div><div>load mri_tal;</div><div>load seg;</div><div>% ensure that the skull-stripped anatomy is expressed in the same coordinate system as the anatomy</div>
<div>seg.transform = mri_tal.transform;</div><div>% save both the original anatomy, and the masked anatomy in a freesurfer compatible format</div><div>cfg             = [];</div><div>cfg.filename    = 'Subject01';</div>
<div>cfg.filetype = 'mgz';</div><div>cfg.parameter   = 'anatomy';</div><div>ft_volumewrite(cfg, mri_tal);</div><div>cfg.filename    = 'Subject01masked';</div><div>ft_volumewrite(cfg, seg);</div><div>
<br></div><div>%%%%% MAC Terminal Input %%%%%%%%%%%%%%%%</div><div>tcsh</div><div>chsh -s /bin/tcsh</div><div>setenv FREESURFER_HOME /Applications/freesurfer</div><div>source $FREESURFER_HOME/SetUpFreeSurfer.csh</div><div>
<br></div><div>setenv SUBJECTS_DIR /Applications/freesurfer/subjects</div><div>setenv SUBJECT /Subject01</div><div>%%% .mgz files to mri folder</div><div>cd $SUBJECTS_DIR/Subject01/mri/</div><div>mri_convert -c -oc 0 0 0 Subject01masked.mgz orig.mgz</div>
<div>mri_convert -c -oc 0 0 0 Subject01.mgz orig-nomask.mgz</div><div><br></div><div>recon-all -talairach -subjid Subject01</div><div>recon-all -nuintensitycor -subjid Subject01</div><div>recon-all -normalization -subjid Subject01</div>
<div>cp T1.mgz brainmask.mgz</div><div>recon-all -gcareg -subjid Subject01</div><div>recon-all -canorm -subjid Subject01</div><div>recon-all -careg -subjid Subject01</div><div>recon-all -calabel -subjid Subject01</div><div>
recon-all -normalization2 -subjid Subject01</div><div>recon-all -segmentation -subjid Subject01</div><div>recon-all -fill -subjid Subject01</div><div><br></div><div><br></div><div>%%% This ends the part of the Freesurfer pipeline concerned with volumetric processing. At this stage you should have a file filled.mgz containing the segmentation of the cortical white matter (cerebellum is not included!). </div>
<div>%%% You can check how this looks using FieldTrip, by doing the following:</div><div>% % go to the Subject01/mri directory</div><div>mri = ft_read_mri('filled.mgz');</div><div>cfg = [];</div><div>cfg.interactive = 'yes';</div>
<div>figure;ft_sourceplot(cfg, mri);</div><div><br></div><div>%%% back in Terminal:</div><div>cd $SUBJECTS_DIR/Subject01/mri/</div><div>recon-all -tessellate -subjid Subject01</div><div>recon-all -smooth1 -subjid Subject01</div>
<div>recon-all -inflate1 -subjid Subject01</div><div>recon-all -qsphere -subjid Subject01</div><div>recon-all -fix -subjid Subject01</div><div>cp brain.mgz brain.finalsurfs.mgz</div><div>recon-all -finalsurfs -subjid Subject01</div>
<div>recon-all -smooth2 -subjid Subject01</div><div>recon-all -inflate2 -subjid Subject01</div><div>recon-all -sphere -subjid Subject01</div><div>recon-all -surfreg -subjid Subject01</div><div><br></div><div>%%% MNE download and installation %%%%%%%%%%%%%%</div>
<div>setenv MNE_ROOT /Applications/MNE-2.7.4-3378-MacOSX-x86_64</div><div>setenv MATLAB_ROOT /Applications/MATLAB_R2013b.app</div><div>source $MNE_ROOT/bin/mne_setup</div><div><br></div><div>%  <a href="http://martinos.org/mne/stable/manual/list.html" target="_blank">http://martinos.org/mne/stable/manual/list.html</a></div>
<div>cd $MNE_ROOT/bin</div><div>./mne_setup_sh</div><div><br></div><div>setenv SUBJECTS_DIR /Applications/freesurfer/subjects</div><div>setenv SUBJECT /Subject01</div><div><br></div><div>./mne_setup_source_space --ico -6 --overwrite</div>
<div><br></div><div>%%%% back in Matlab: /Applications/freesurfer/subjects/Subject01/bem</div><div>bnd = ft_read_headshape('Subject01-oct-6-src.fif', 'format', 'mne_source');</div><div>figure;ft_plot_mesh(bnd);</div>
<div><br></div><div>%%% Current Folder : /Applications/freesurfer/subjects/Subject01/Subject01/mri</div><div>mri_nom = ft_read_mri('orig-nomask.mgz');</div><div><br></div><div>cfg = [];</div><div>cfg.method = 'interactive';</div>
<div>mri_nom_ctf = ft_volumerealign(cfg, mri_nom);</div><div><br></div><div>%%% fiducials chosen, fiducials l,r,n</div><div><br></div><div>mri_nom_ctf = ft_convert_units(mri_nom_ctf, 'cm');</div><div>T   = mri_nom_ctf.transform*inv(mri_nom_ctf.transformorig);</div>
<div>%%% Current Folder : /Applications/freesurfer/subjects/Subject01/Subject01/bem</div><div>bnd  = ft_read_headshape('Subject01-oct-6-src.fif', 'format', 'mne_source');</div><div>sourcespace = ft_convert_units(bnd, 'cm');</div>
<div>sourcespace = ft_transform_geometry(T, sourcespace);</div><div>save sourcespace sourcespace;</div><div>save T T; %we will need the transformation matrix in the next step</div><div><br></div><div>%%% Current Folder auf: /Applications/freesurfer/subjects/Subject01/Subject01/mri</div>
<div>mri_nom = ft_read_mri('orig-nomask.mgz');</div><div><br></div><div>cfg           = [];</div><div>cfg.coordsys  = 'spm'; </div><div>cfg.output    = {'brain'};</div><div>seg           = ft_volumesegment(cfg, mri_nom);</div>
<div>seg           = ft_convert_units(seg,'cm');</div><div><br></div><div>cfg           = [];</div><div>cfg.method    = 'singleshell';</div><div>vol           = ft_prepare_headmodel(cfg,seg);</div><div>vol.bnd       = ft_transform_geometry(T, vol.bnd);</div>
<div>save vol vol;</div><div><br></div><div>% load vol                                       % volume conduction model</div><div>figure;hold on;</div><div>ft_plot_vol(vol, 'facecolor', 'none');alpha 0.5;</div>
<div>ft_plot_mesh(sourcespace, 'edgecolor', 'none'); camlight </div><div><br></div><div><br></div><div><br></div><div>%%% so far, so good. >>> then I create the elec file:</div><div>clear all;</div>
<div>mri2 = ft_read_mri('Subject01.mri');</div><div>disp(mri2)</div><div>save mri2 mri2;</div><div><br></div><div>cfg           = [];</div><div>cfg.output    = {'brain','skull','scalp'};</div>
<div>segmentedmri2  = ft_volumesegment(cfg, mri2);</div><div>save segmentedmri2 segmentedmri2</div><div>disp(segmentedmri2)</div><div><br></div><div>cfg=[];</div><div>cfg.tissue={'brain','skull','scalp'};</div>
<div>cfg.numvertices = [3000 2000 1000];</div><div>bnd2=ft_prepare_mesh(cfg,segmentedmri2);</div><div><br></div><div>save bnd2 bnd2</div><div><br></div><div>disp(bnd2(1))</div><div><br></div><div>cfg        = [];</div><div>
cfg.method ='dipoli';</div><div>vol2        = ft_prepare_headmodel(cfg, segmentedmri2);</div><div><br></div><div>save vol2 vol2</div><div><br></div><div>disp(vol2)</div><div><br></div><div>vol2 = ft_convert_units(vol2, 'cm');</div>
<div><br></div><div><br></div><div>figure;</div><div>ft_plot_mesh(vol2.bnd(1),'facecolor','none'); %scalp</div><div>figure;</div><div>ft_plot_mesh(vol2.bnd(2),'facecolor','none'); %skull</div>
<div>figure;</div><div>ft_plot_mesh(vol2.bnd(3),'facecolor','none'); %brain</div><div><br></div><div>ft_plot_mesh(vol2.bnd(1), 'facecolor',[0.2 0.2 0.2], 'facealpha', 0.3, 'edgecolor', [1 1 1], 'edgealpha', 0.05);</div>
<div>hold on;</div><div>ft_plot_mesh(vol2.bnd(2),'edgecolor','none','facealpha',0.4);</div><div>hold on;</div><div>ft_plot_mesh(vol2.bnd(3),'edgecolor','none','facecolor',[0.4 0.6 0.4]);</div>
<div><br></div><div>elec2       = ft_read_sens('standard_1020.elc');   % may you need to define the path to the file</div><div><br></div><div>disp(elec2)</div><div><br></div><div>elec2 = ft_convert_units(elec2, 'cm');</div>
<div><br></div><div>% load volume conduction model</div><div>load vol2;                              </div><div>figure;</div><div>% head surface (scalp)</div><div>ft_plot_mesh(vol2.bnd(1), 'edgecolor','none','facealpha',0.8,'facecolor',[0.6 0.6 0.8]); </div>
<div>hold on;</div><div>% electrodes</div><div>ft_plot_sens(elec2,'style', 'sk');    </div><div><br></div><div><br></div><div>mri2 = ft_convert_units(mri2, 'cm');</div><div><br></div><div>nas=mri2.hdr.fiducial.mri.nas;</div>
<div>lpa=mri2.hdr.fiducial.mri.lpa;</div><div>rpa=mri2.hdr.fiducial.mri.rpa;</div><div> </div><div>transm=mri2.transform;</div><div> </div><div>nas=warp_apply(transm,nas, 'homogenous');</div><div>lpa=warp_apply(transm,lpa, 'homogenous');</div>
<div>rpa=warp_apply(transm,rpa, 'homogenous');</div><div><br></div><div>fid.chanpos       = [nas; lpa; rpa];       % ctf-coordinates of fiducials</div><div>fid.label         = {'Nz','LPA','RPA'};    % same labels as in elec </div>
<div>fid.unit          = 'cm';                  % same units as mri</div><div> </div><div>% alignment</div><div>cfg               = [];</div><div>cfg.method        = 'fiducial';            </div><div>cfg.template      = fid;                   % see above</div>
<div>cfg.elec          = elec2;</div><div>cfg.fiducial      = {'Nz', 'LPA', 'RPA'};  % labels of fiducials in fid and in elec</div><div>elec_aligned2      = ft_electroderealign(cfg);</div><div><br>
</div><div>save elec_aligned2 elec_aligned2;</div><div>% elec_aligned2 = ft_convert_units(elec_aligned2, 'cm');</div><div>figure;</div><div>ft_plot_sens(elec_aligned2,'style','sk');</div><div>hold on;</div>
<div>ft_plot_mesh(vol2.bnd(1),'facealpha', 0.85, 'edgecolor', 'none', 'facecolor', [0.65 0.65 0.65]); %scalp</div><div><br></div><div>cfg           = [];</div><div>cfg.method    = 'interactive';</div>
<div>cfg.elec      = elec_aligned2;</div><div>cfg.headshape = vol2.bnd(1);</div><div>elec_aligned2  = ft_electroderealign(cfg);</div><div><br></div><div><b><u style="font-size:14px"><br></u></b></div><div><b><u style="font-size:14px">%%%%% and here I am struggling: I can not get any of the above files to</u></b></div>
<div><b><u style="font-size:14px">%%%%% work together: vol or vol2, elec_aligned2, sourcespace etc.</u></b></div><div><br></div><div>vol = ft_convert_units(vol, 'cm');</div><div>elec_aligned2 = ft_convert_units(elec_aligned2, 'cm');</div>
<div>cfg = [];</div><div>cfg.elec      = elec_aligned2;                     % sensor positions</div><div>cfg.channel       = 'all';                   % the used channels</div><div>cfg.grid.pos = sourcespace.pnt;              % source points</div>
<div>cfg.grid.inside = 1:size(sourcespace.pnt,1); % all source points are inside of the brain</div><div>cfg.vol = vol;</div><div>cfg.normalize       = 'yes';% volume conduction model</div><div>leadfield = ft_prepare_leadfield(cfg);</div>
<div><br></div><div>save leadfield leadfield;      </div><div><br></div><div>clear all;</div><div>load('GA1.mat')</div><div>load('GA2.mat')</div><div>load leadfield;</div><div>load vol2;</div><div>load elec_aligned2;</div>
<div><br></div><div><br></div><div>cfg        = [];</div><div>cfg.method = 'mne';</div><div>cfg.elec = elec_aligned2;</div><div>cfg.grid   = leadfield;</div><div>cfg.vol    = vol;</div><div>cfg.mne.prewhiten = 'yes';</div>
<div>cfg.mne.lambda    = 3;</div><div>cfg.mne.scalesourcecov = 'yes';</div><div>cfg.mne.normalize = 'yes';</div><div>sourceCERT0  = ft_sourceanalysis(cfg, GA1);</div><div>sourceCERT3 = ft_sourceanalysis(cfg, GA2);</div>
</div></div><br>_______________________________________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl">fieldtrip@donders.ru.nl</a><br>
<a href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br></blockquote></div><br></div>
_______________________________________________<br>fieldtrip mailing list<br>fieldtrip@donders.ru.nl<br>http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</blockquote></div><br></div></body></html>