Back to the main page.

Bug 2843 - ft_sourceinterpolate fails on avg.pow of mne output

Reported 2015-02-13 18:08:00 +0100
Modified 2015-02-23 14:56:20 +0100
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P5 normal
Assigned to: Jan-Mathijs Schoffelen
Depends on:
See also:

Johanna - 2015-02-13 18:08:19 +0100

I'm filing this as I know there were some recent changes to source analysis code. I ran MNE on ERP timelock data with a full-brain grid (not surface). I want to interpolate onto MRI to sourceplot. But ft_sourceinterpolate fails, and I coudln't figure out why. I'm using the most recent SVN version. mrinormlin = anatomy: [201x213x251 double] transform: [4x4 double] dim: [201 213 251] params: [1x1 struct] initial: [4x4 double] coordsys: 'spm' cfg: [1x1 struct] unit: 'mm' >> erp_mne ans = time: [1x3784 double] dim: [20 25 22] inside: [11000x1 logical] pos: [11000x3 double] method: 'average' avg: [1x1 struct] cfg: [1x1 struct] cfg = []; cfg.parameter = 'avg.pow'; erp_source = ft_sourceinterpolate(cfg, erp_mne , mrinormlin); Warning: use cfg.parameter='pow' instead of cfg.parameter='avg.pow' > In ft_checkconfig at 139 In ft_sourceinterpolate at 119 the input is volume data with dimensions [201 213 251] the input is source data with 11000 brainordinates on a [20 25 22] grid selecting subvolume of 47.4% interpolating interpolating 100.0% reslicing and interpolating pow interpolating Error using interpn (line 151) Wrong number of input arguments. Error in ft_sourceinterpolate>my_interpn (line 511) av(sel) = interpn(fv, ax(sel), ay(sel), az(sel), interpmethod); Error in ft_sourceinterpolate (line 422) av( sel) = my_interpn(fv, ax(sel), ay(sel), az(sel), cfg.interpmethod,;

Jan-Mathijs Schoffelen - 2015-02-13 18:16:11 +0100

The error is rather uninformative, I agree, but it is intended that source-level data with 'time' in the dimord cannot be interpolated (to protect your RAM). You can use ft_sourceplot, though, on the original source data (which allows you to visualize the stuff without the anatomy on the background). All well?

Robert Oostenveld - 2015-02-13 19:40:37 +0100

The error Error in ft_sourceinterpolate>my_interpn (line 511) av(sel) = interpn(fv, ax(sel), ay(sel), az(sel), interpmethod); suggests that it fails on interpolating a 3-D volume, not 4D including time. The only reason I can see for this is that the number of dimensions of argument fv does not match the 3 ax/ay/az arguments. This is also suggested by the following >> fv = randn(10,10); >> interpn(fv, 1:2:10, 1:2:10, 1:2:20, 'linear') Error using interpn (line 152) Wrong number of input arguments. I agree with JM that there is a reason why this might not have to work, but I would rather have code crash your computer as it goes out of RAM, than have it give a MATLAB error. And ideally there would be "this will crash your computer, are you sure you want to proceed (y/n)?" Could you share your data (e.g. by personal mail to a dropbox link or so)?

Jan-Mathijs Schoffelen - 2015-02-14 08:29:08 +0100

NOTE: last FT-meeting it was discussed that it would make sense to split the functionality of the visualization functions of source data (ft_sourceplot + ft_sourcemovie) along the lines of having either scalar functional data defined on 2D or 3D brain ordinates (this would be a case for ft_sourceplot), or having time(-freq) data, requiring functionality to browse through the data (this would be a case for ft_sourcemovie). I just started working on ft_sourcemovie to streamline it (for a slightly different purpose), and broke my local copy along the way. Once this one is in place, this intended functionality can be implemented.

Johanna - 2015-02-16 10:44:19 +0100

Hi JM and Robert, Yes, using ft_sourceplot on just the erp_mne works without interpolating to the MRI. I've got 32GB of RAM on my local machine, so I'd rather see it try to do a high-memory computation if it can! :-) More info on my data: >> erp_mne.avg mom: {1x11000 cell} pow: [11000x3784 double] inside: [11000x1 logical] pos: [11000x3 double] and at line 511 of ft_sourceinterpolate, the data is: K>> whos Name Size Bytes Class Attributes av 5094496x1 40755968 double ax 5094496x1 40755968 double ay 5094496x1 40755968 double az 5094496x1 40755968 double blocksize 1x1 8 double feedback 1x4 8 char fv 20x25x22 88000 double interpmethod 1x7 14 char lastblock 1x1 8 double num 1x1 8 double sel 1x254724 2037792 double (with interpmethod as 'nearest'.) I will also send the data via dropbox. Cheers, Johanna

Johanna - 2015-02-16 11:04:38 +0100

(In reply to Johanna from comment #4) correction, interpmethod is 'linear' at the point where it crashes. Earlier in the code (where it succeeds) it is 'nearest'.

Robert Oostenveld - 2015-02-16 11:09:13 +0100

(In reply to Johanna from comment #4) I received the data and copied it to /home/common/matlab/fieldtrip/data/test/bug2843.mat

Jan-Mathijs Schoffelen - 2015-02-23 12:01:17 +0100

I will properly create a testscript, but what I see is that in this scenario ft_checkdata (l 165 in ft_sourceinterpolate) fails to convert the functional data into the expected dimensions (i.e. reshaping the 11000 positions into 3D). I'll look into it, but suspect that this works fine if the the data is scalar (one value per position).

Jan-Mathijs Schoffelen - 2015-02-23 12:09:13 +0100

cfg=[]; cfg.elec=elec; cfg.vol=voldipolimm; cfg.grid=lf; cfg.method='mne'; cfg.mne.lambda=2; cfg.mne.prewhiten='yes'; cfg.mne.scalesourcecov='yes'; s=ft_sourceanalysis(cfg,tlock_erp); v=ft_checkdata(s,'datatype','volume'); % this gives a pow field of 11000*3784 s2=s; s2.avg.pow=s2.avg.pow(:,1); v2=ft_checkdata(s2,'datatype','volume'); % this gives a pow field of 20x25x22

Jan-Mathijs Schoffelen - 2015-02-23 12:12:11 +0100

ft_checkdata: line 734 calls parameterselection, which fails to recognize 'pow' as a to-be-reshaped data field.

Robert Oostenveld - 2015-02-23 14:35:41 +0100

(In reply to Jan-Mathijs Schoffelen from comment #9) parameterselection should become deprecated at a certain point... Might it be that parameterselection is missing it because internally the avg structure is not used any more?

Jan-Mathijs Schoffelen - 2015-02-23 14:56:20 +0100

I agree about the deprecation of parameterselection. In this specific instance, I think it would suffice to check for the fields that have a pos in the dimord and reshape those. NOTE, the following functions (in fieldtrip/utilities) call parameterselection: ft_checkdata ft_selectdata_old (hehehe) ft_source2full ft_source2sparse in fieldtrip-main the functions are: ft_sliceinterp (the dinosaur) ft_sourceinterpolate ft_sourceplot ft_volumedownsample ft_volumenormalise ft_volumerealign ft_volumewrite