Back to the main page.
Bug 719 - MEGrealign misplaces sensor
Status | CLOSED FIXED |
Reported | 2011-05-31 18:44:00 +0200 |
Modified | 2011-07-13 14:22:42 +0200 |
Product: | FieldTrip |
Component: | core |
Version: | unspecified |
Hardware: | PC |
Operating System: | Linux |
Importance: | P1 normal |
Assigned to: | Jan-Mathijs Schoffelen |
URL: | |
Tags: | |
Depends on: | |
Blocks: | |
See also: |
Jeff Stout - 2011-05-31 18:44:00 +0200
Created attachment 61 MEG sensors with misplaced channel A229 after using megrealign This error is twofold, but I think that they are independent. I am using fieldtrip 20110507 with a 248 channel magnetometer Magnes 3600. ISSUE1: I had to modify one line on the ft_megrealign command for the command to run. On line 245 of ft_megrealign, the code calls ft_prepare_sourcemodel with one input - tmpcfg. tmpcfg.vol = volold; [grid, tmpcfg] = ft_prepare_sourcemodel(tmpcfg); In line 132 of ft_prepare_sourcemodel, the command requires nargin to be greater than 1 in order to select basedonvol. Since the input has the volume as a part of the tempcfg file, nargin=1, so basedonvol is not set equal to 1, so it causes an error. if ~any([basedonauto basedongrid basedonpos basedonshape basedonmri basedoncortex]) && nargin>1 && ~isempty(cfg.vol) % fall back to default behaviour, which is to create a surface grid (e.g. used in MEGRELIGN) basedonvol = 1; end I changed line 245 of ft_megrealign to be [grid, tmpcfg] = ft_prepare_sourcemodel(tmpcfg,volold) and the code will run. ISSUE2: I have a preprocessed dataset with channels A6 and A246 removed. I am trying to use ft_megrealign to interpolate the channel information. After performing megrealign, channel A229 is located about 10 cm above the top of the sensor (see attached). In the dataset A229 has not been labelled as a bad channel, nor any of its neighboring channels. The location of A229 is significant in that it is the most inferior/anterior channel on the left side. temp = ft_read_sens(subjectdata.FA_dataset); temp.pnt = temp.pnt*100; temp.unit = 'cm'; cfg = []; cfg.inwardshift = 1; cfg.vol=vol; cfg.template{1}= temp; cfg.channel={'MEG'}; con.grad.pnt = con.grad.pnt*100; con.grad.unit = 'cm'; con = ft_megrealign(cfg, con) --- output --- ..... computing surface normals mean distance towards template gradiometers is 0.00 cm creating dipole grid based on inward-shifted brain surface from volume conductor model Warning: the normals of the surface triangulation are inward oriented > In fieldtrip-20110507/private/headsurface at 211 In ft_prepare_sourcemodel at 492 In ft_megrealign at 245 642 dipoles inside, 0 dipoles outside brain computing forward model for 642 dipoles pruning 122 from 246, i.e. removing the 122 smallest spatial components computing interpolation matrix #1 computing interpolation matrix #2 computing interpolation matrix #3 pruning 124 from 248, i.e. removing the 124 smallest spatial components realigning trial 1 original -> template RV 14.42 % original -> original RV 14.42 % original -> template -> original RV 14.44 % ....................
Jan-Mathijs Schoffelen - 2011-05-31 19:48:04 +0200
*** Bug 716 has been marked as a duplicate of this bug. ***
Jan-Mathijs Schoffelen - 2011-05-31 19:53:56 +0200
Dear Jeff, Thanks for the detective work. I would have a preference for changing the last && in line 132 into a ||, and adding the appropriate brackets. This can leave the higher level code (i.e. ft_megrealign) unchanged. Would you agree? Rather than having ... && nargin>1 && ~isempty(cfg.vol), make it ... && (nargin>1 || ~isempty(cfg.vol)) Now I think of it: in line 88 the vol (in case nargin>1) is already added to the cfg, so I guess that the conditional nargin>1 can disappear altogether. Even better.
Jan-Mathijs Schoffelen - 2011-05-31 20:19:25 +0200
The evil happens in ft_prepare_vol_sens, line 135. In short, this line assumes that the sens.tra is an 'unbalanced' one, i.e. each row only containing either a single 1 (and for the rest 0's), for a magnetometer channel, or 2 1's (for a gradiometer channel). When the sens.tra contains additional weights, e.g. with digital weights applied for the bti system, this line will produce bogus results.
Jan-Mathijs Schoffelen - 2011-05-31 20:42:37 +0200
I take back my previous statement. There's no evil going in the line I reported. This should be perfectly normal behavior.
Jan-Mathijs Schoffelen - 2011-05-31 21:25:03 +0200
I think the second problem is a plotting issue. Something goes wrong in ft_apply_montage (called by channelposition), when the montage is unbalanced in order to get the channel positions.
Jeff Stout - 2011-06-01 17:17:08 +0200
(In reply to comment #5) > I think the second problem is a plotting issue. Something goes wrong in > ft_apply_montage (called by channelposition), when the montage is unbalanced in > order to get the channel positions. Hi Jan-Mathijs, I agree with you that it is not a position error, but there is still something odd happening. During megplanar (shown at bottom), an extra channel appears in the dataset. Below is my test for locations on adjacent sensors (A229 and A230)in a pre-realign (con) and post-realign (con2) con.label(sel) ans = 'A230' 'A229' >> con2.label(sel) ans = 'A230' 'A229' >> con.grad.pnt(sel,:) ans = 0.0312 0.0984 -0.0382 *********These are in 'm' ********* 0.0522 0.0960 -0.0364 >> con2.grad.pnt(sel,:) ans = 3.1182 9.8428 -3.8175 **********These are in 'cm' *********** 5.2243 9.5982 -3.6447 The locations are equivalent except for the position scaling that I implemented and the adjacent channels stay adjacent. When I perform a megplanar calculation on the realigned dataset, an odd thing happens. con2 is a megrealigned dataset with appropriate number of channels. con2 = label: {248x1 cell} grad: [1x1 struct] trial: {1x112 cell} fsample: 678.1700 time: {1x112 cell} cfg: [1x1 struct] sampleinfo: [112x2 double] ---cfg.method='sincos' and cfg.neighbourdist=4; test=ft_megplanar(cfg,con2) the input is raw data with 248 channels and 112 trials undoing the Supine balancing minimum distance between gradiometers is 1.85 cm maximum distance between gradiometers is 29.74 cm average number of neighbours is 7.887097 processing trials processing trial 1 from 112 processing trial 2 from 112 .............. test = label: {497x1 cell} grad: [1x1 struct] trial: {1x112 cell} fsample: 678.1700 time: {1x112 cell} cfg: [1x1 struct] sampleinfo: [112x2 double] No errors are thrown, but an additional channel is produced. 248*2=496, test has 497 channels. The extra channel is A229. 'A229_dH' 'A229_dV' 'A229' Also, I have emailed you back responding to your email on the email discussion list, but it was sent back to my spam folder twice. Not sure if this has happened to others. Thanks for you help -Jeff Stout
Jan-Mathijs Schoffelen - 2011-06-02 10:25:36 +0200
-Just to clarify: when applying ft_megrealign to the pre-aligned set, does it work correctly? -@bounced e-mails: I did not get any. Be sure that your outgoing e-mail address is exactly the same as the one with which you are known by the list -Could you also check the following -> it should be possible to realign to a planar gradient sensor array in one step using ft_megrealign (rather than going first through megrealign and then through megplanar). I never tried it myself, but the idea would be to provide as a cfg.template gradiometer-array, a structure which has been created by the function megplanar_sincos (which is in fieldtrip/private).
Jeff Stout - 2011-06-02 17:27:18 +0200
(In reply to comment #7) I am not entirely sure that this is what you are asking: If I perform ft_megrealign on a dataset, it completes without error, but it does give a warning about the normals of the surface triangulation are inward shifted. If I perform megrealign on that realigned dataset, it will complete without error. The residual variance is very low for each trial, like .05%. I checked the locations of sensors for both realigned datasets and they are the same. I will try to realign the planar data later today. > -Just to clarify: when applying ft_megrealign to the pre-aligned set, does it > work correctly? > -@bounced e-mails: I did not get any. Be sure that your outgoing e-mail address > is exactly the same as the one with which you are known by the list > -Could you also check the following -> it should be possible to realign to a > planar gradient sensor array in one step using ft_megrealign (rather than > going first through megrealign and then through megplanar). I never tried it > myself, but the idea would be to provide as a cfg.template gradiometer-array, a > structure which has been created by the function megplanar_sincos (which is in > fieldtrip/private).