Dear Jan-Mathijs,<div><br></div><div>oh, sorry! Thanks for the hint. Now it works fine ;-).</div><div><br></div><div>Best,</div><div><br></div><div>Andreas<br><br>Am Mittwoch, 15. Juni 2016 schrieb Schoffelen, J.M. (Jan Mathijs) :<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">
Are you sure that you use the pos-field from the template, i.e. from the standard_sourcemodel3d5mm?<br>
<div>
<div>
<div style="word-wrap:break-word">
<div><br>
</div>
<div>Best,</div>
<div>Jan-Mathijs</div>
<div><br>
<div>
<blockquote type="cite">
<div>On 15 Jun 2016, at 14:31, Andreas Sauer <<a href="javascript:_e(%7B%7D,'cvml','sauer.mpih@googlemail.com');" target="_blank">sauer.mpih@googlemail.com</a>> wrote:</div>
<br>
<div>
<div dir="ltr">Dear Jan,
<div><br>
</div>
<div>thank you for your email and the example code!</div>
<div><br>
</div>
<div>I tried both ways to convert the coord systems, but unfortunately it still doesn't work. </div>
<div><br>
</div>
<div>Since I used the tutorial procedure to create my sourcemodel (<a href="http://www.fieldtriptoolbox.org/tutorial/sourcemodel#subject-specific_grids_that_are_equivalent_across_subjects_in_normalized_space" style="font-size:13px" target="_blank">http://www.fieldtriptoolbox.org/tutorial/sourcemodel#subject-specific_grids_that_are_equivalent_across_subjects_in_normalized_space</a>)
 I tried first with the easy way of only replacing the .pos field. But the plots don't change, the sources are still rotated by 90 degrees. Actually, the .pos fields are already the same before replacing it (see pic). Is there some error in my code? </div>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><i><br>
</i></div>
<div><i>% Step1: Load mri file</i></div>
<div>
<div><i>mri = ft_read_mri('/data/home1/asauer/Projects/RPScZ/Analysis/Beamforming/MRI/HSM12_V2.mri');</i></div>
</div>
<div>
<div><i><br>
</i></div>
</div>
<div>
<div><i>% Step 2: Segment the template brain and construct a volume conduction</i></div>
</div>
<div>
<div><i>% model (i.e. head model): this is needed for the inside/outside detection of voxels</i></div>
</div>
<div>
<div><i>cfg = [];</i></div>
</div>
<div>
<div><i>cfg.output = 'brain';</i></div>
</div>
<div>
<div><i>segmentedmri = ft_volumesegment(cfg,anatomy);</i></div>
</div>
<div>
<div><i><br>
</i></div>
</div>
<div>
<div><i>cfg = [];</i></div>
</div>
<div>
<div><i>cfg.method = 'singleshell';</i></div>
</div>
<div>
<div><i>vol = ft_prepare_headmodel(cfg,segmentedmri);</i></div>
</div>
<div>
<div><i>vol = ft_convert_units(vol,'m');</i></div>
</div>
<div>
<div><i>figure; ft_plot_sens(sens,'style','*b'); hold on; ft_plot_vol(vol)</i></div>
</div>
<div>
<div><i><br>
</i></div>
</div>
<div>
<div><i>% Step 3: Load sourcemodel </i></div>
</div>
<div>
<div><i>load(fullfile(ft_path,'template/sourcemodel/standard_sourcemodel3d5mm'));</i></div>
</div>
<div>
<div><i>template_grid = sourcemodel;</i></div>
</div>
<div>
<div><i>clear sourcemodel</i></div>
</div>
<div>
<div><i><br>
</i></div>
</div>
<div>
<div><i>% Step 4: Make sourcemodel</i></div>
</div>
<div>
<div><i>cfg = [];</i></div>
</div>
<div>
<div><i>cfg.grid.warpmni = 'yes';</i></div>
</div>
<div>
<div><i>cfg.grid.template = template_grid;</i></div>
</div>
<div>
<div><i>cfg.grid.nonlinear = 'yes';</i></div>
</div>
<div>
<div><i>cfg.mri = mri;</i></div>
</div>
<div>
<div><i>cfg.grid.unit = 'm';</i></div>
</div>
<div>
<div><i>grid = ft_prepare_sourcemodel(cfg);</i></div>
</div>
<div>
<div><i>figure; hold on;</i></div>
</div>
<div>
<div><i>ft_plot_vol(vol,'facecolor','cortex','edgecolor','none'); alpha 0.5; camlight;</i></div>
</div>
<div>
<div><i>ft_plot_mesh(grid.pos(grid.inside,:));</i></div>
</div>
</blockquote>
<div><br>
</div>
<div>The only thing that is different from the tutorial is the unit conversion... <br>
</div>
<div><br>
</div>
<div>After that I tried the transformation. All worked well until the source interpolation. ft_sourceinterpolation throws this error:</div>
<div><br>
</div>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>
<div><i>Attempted to access sel(1); index out of bounds because numel(sel)=0.</i></div>
</div>
<div>
<div><i><br>
</i></div>
</div>
<div>
<div><i>Error in ft_sourceinterpolate>my_interpn (line 508)</i></div>
</div>
<div>
<div><i>  ft_progress(sel(1)/num, 'interpolating %.1f%%\n', 100*sel(1)/num);</i></div>
</div>
<div>
<div><i><br>
</i></div>
</div>
<div>
<div><i>Error in ft_sourceinterpolate (line 393)</i></div>
</div>
<div>
<div><i>    interp.inside( sel) = my_interpn(double(functional.inside), ax(sel), ay(sel), az(sel), 'nearest', cfg.feedback);</i></div>
</div>
</blockquote>
<div><br>
</div>
<div>which, to be honest, I don't really understand. Sorry...</div>
<div><br>
</div>
<div>Best wishes,</div>
<div><br>
</div>
<div>Andreas</div>
<div><br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">2016-06-14 9:41 GMT+02:00 Schoffelen, J.M. (Jan Mathijs)
<span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','jan.schoffelen@donders.ru.nl');" target="_blank">jan.schoffelen@donders.ru.nl</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="word-wrap:break-word">Dear Andreas,
<div>
<div><span><br>
<blockquote type="cite">
<div>
<div dir="ltr">
<div style="font-family:Helvetica;font-size:12px">after having calculated the sources of a MMN paradigm (4D-system), I’d like to plot the results on one of the anatomy template files in the fieldtrip directory (single_subj_T1_1mm.nii) or alternatively
 on a MNI T1 template file (mni_icbm152_t1_tal_nlin_sym_09a.nii). Unfortunately, this is not working well… As you can see on the attached picture, the functional data is rotated by 90 degrees. </div>
<div style="font-family:Helvetica;font-size:12px"><br>
</div>
<div style="font-family:Helvetica;font-size:12px">I guess that something gets mixed because of the different coordsystems of functional and anatomical data. The functional data is 4D, which means ALS orientation. The anatomical is MNI, so RAS orientation.
 The plotting works fine, if I use a mri file which was converted in field trip (V2.mri) and therefore is also in ALS orientation. However, the anatomy doesn’t look very pretty… </div>
</div>
</div>
</blockquote>
<blockquote type="cite">
<div>
<div dir="ltr">
<div style="font-family:Helvetica;font-size:12px"><br>
</div>
<div style="font-family:Helvetica;font-size:12px">Is there any way that I can transform the functional data to RAS orientation or the anatomical data to ALS orientation, respectively?</div>
</div>
</div>
</blockquote>
<blockquote type="cite">
<div>
<div dir="ltr">
<div style="font-family:Helvetica;font-size:12px"><br>
</div>
<div style="font-family:Helvetica;font-size:12px">I tried with ft_volumerealign. However, since the template file has no fiducials, it is hard to really precisely do this. </div>
</div>
</div>
</blockquote>
<div><br>
</div>
</span>
<div>Fair point. I would however do it the other way around, using the V2 to get the transformation from voxel space to MNI-RAS, and then use the inverse of the transformation on the functional data: in this case you could use ft_volumenormalise, with
 cfg.nonlinear = ‘no’. Alternatively, if you are using this procedure: <a href="http://www.fieldtriptoolbox.org/tutorial/sourcemodel#subject-specific_grids_that_are_equivalent_across_subjects_in_normalized_space" target="_blank">
http://www.fieldtriptoolbox.org/tutorial/sourcemodel#subject-specific_grids_that_are_equivalent_across_subjects_in_normalized_space</a>, you could directly replace the source.pos of your functional data with the template.pos and then do the interpolation.</div>
<div><br>
</div>
<div>To summarize: </div>
<div><br>
</div>
<div>either:</div>
<div><br>
</div>
<div>mri = ft_read_mri(‘V2.mri’);</div>
<div>mri.coordsys = ‘bti’;</div>
<div><br>
</div>
<div>cfg = [];</div>
<div>cfg.nonlinear=’no’;</div>
<div>mrin = ft_volumenormalise(cfg, mri);</div>
<div><br>
</div>
<div>transform_vox2bti = mri.transform;</div>
<div>transform_vox2spm = mrin.transform;</div>
<div>transform_bti2spm = transform_vox2spm/transform_vox2bti</div>
<div>source = ft_transform_geometry(transform_bti2spm, source);</div>
<div><br>
</div>
<div>source_int = ft_sourceinterpolate(somecfg, source, niceanatomical);</div>
<div><br>
</div>
<div>or:</div>
<div><br>
</div>
<div>source.pos = templat.pos;</div>
<div>source_int = ft_sourceinterpolate(somecfg, source, niceanatomical);</div>
<div><br>
</div>
<div>Best,</div>
<div>JM</div>
<div><br>
</div>
<div><br>
</div>
<br>
<blockquote type="cite">
<div><span>
<div dir="ltr">
<div style="font-family:Helvetica;font-size:12px">Any input on how to plot the sources on one of these nice anatomical files is highly appreciated!</div>
<div style="font-family:Helvetica;font-size:12px"><br>
</div>
<div style="font-family:Helvetica;font-size:12px">Thanks and best regards,</div>
<div style="font-family:Helvetica;font-size:12px"><br>
</div>
<div style="font-family:Helvetica;font-size:12px">Andreas</div>
<div style="font-family:Helvetica;font-size:12px"><br>
</div>
<div><br>
</div>
-- <br>
<div data-smartmail="gmail_signature">
<div></div>
<div>Dipl.-Psych. Andreas Sauer</div>
<div>Max Planck Institute for Brain Research</div>
<div>Deutschordenstraße 46</div>
<div>60528 Frankfurt am Main</div>
<div>Germany</div>
<div><br>
</div>
<div>T: <a href="tel:%2B49%2069%2096769%20278" value="+496996769278" target="_blank">
+49 69 96769 278</a></div>
<div>F: <a href="tel:%2B49%2069%2096769%20327" value="+496996769327" target="_blank">
+49 69 96769 327</a></div>
<div>Email: <a href="javascript:_e(%7B%7D,'cvml','sauer.mpih@gmail.com');" target="_blank">
sauer.mpih@gmail.com</a></div>
<div><a href="http://www.brain.mpg.de/" target="_blank">www.brain.mpg.de</a></div>
</div>
</div>
</span><span><Rotated_Source.png></span>_______________________________________________<br>
fieldtrip mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','fieldtrip@donders.ru.nl');" target="_blank">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></div>
</blockquote>
</div>
<br>
</div>
</div>
<br>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','fieldtrip@donders.ru.nl');" target="_blank">fieldtrip@donders.ru.nl</a><br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div data-smartmail="gmail_signature">
<div></div>
<div>Dipl.-Psych. Andreas Sauer</div>
<div>Max Planck Institute for Brain Research</div>
<div>Deutschordenstraße 46</div>
<div>60528 Frankfurt am Main</div>
<div>Germany</div>
<div><br>
</div>
<div>T: +49 69 96769 278</div>
<div>F: +49 69 96769 327</div>
<div>Email: <a href="javascript:_e(%7B%7D,'cvml','sauer.mpih@gmail.com');" target="_blank">
sauer.mpih@gmail.com</a></div>
<div><a href="http://www.brain.mpg.de/" target="_blank">www.brain.mpg.de</a></div>
</div>
</div>
</div>
<span><pos_fields.png></span>_______________________________________________<br>
fieldtrip mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','fieldtrip@donders.ru.nl');" target="_blank">fieldtrip@donders.ru.nl</a><br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
<br>
</div>

</blockquote></div><br><br>-- <br><div></div><div>Dipl.-Psych. Andreas Sauer</div><div>Max Planck Institute for Brain Research</div><div>Deutschordenstraße 46</div><div>60528 Frankfurt am Main</div><div>Germany</div><div><br></div><div>T: +49 69 96769 278</div><div>F: +49 69 96769 327</div><div>Email: <a href="mailto:sauer.mpih@gmail.com" target="_blank">sauer.mpih@gmail.com</a></div><div><a href="http://www.brain.mpg.de" target="_blank">www.brain.mpg.de</a></div><br>