Back to the main page.

Bug 3460 - Parcellated network analysis cannot be plotted

Reported 2018-10-22 14:50:00 +0200
Modified 2019-08-10 12:36:51 +0200
Product: FieldTrip
Component: plotting
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P5 normal
Assigned to:
Depends on:
See also:

Jens Klinzing - 2018-10-22 14:50:15 +0200

When following the network analysis tutorial ( the results cannot be plotted if an atlas other than atlas_MMP1.0_4k atlas is used. Find example code and further explanations below. % -------------------------------------- % load some data from % load hdm load standard_sourcemodel3d2cm load dataica cfg = []; cfg.grid = sourcemodel; cfg.headmodel = hdm; = {'MEG'}; lf = ft_prepare_leadfield(cfg, dataica); cfg = []; cfg.method = 'mtmfft'; cfg.output = 'fourier'; cfg.keeptrials = 'yes'; cfg.tapsmofrq = 1; cfg.foi = 10; freq = ft_freqanalysis(cfg, dataica); cfg = []; cfg.frequency = freq.freq; cfg.method = 'pcc'; cfg.grid = lf; cfg.headmodel = hdm; cfg.keeptrials = 'yes'; cfg.pcc.lambda = '10%'; cfg.pcc.projectnoise = 'yes'; cfg.pcc.fixedori = 'yes'; source = ft_sourceanalysis(cfg, freq); source = ft_sourcedescriptives([], source); % to get the neural-activity-index cfg = []; cfg.method ='coh'; cfg.complex = 'absimag'; source_conn = ft_connectivityanalysis(cfg, source); atlas = ft_read_atlas('/template/atlas/aal/ROI_MNI_V4.nii'); % also this interpolation step does not have to be done with the 4k atlas atlas = ft_convert_units(atlas,'cm'); cfg = []; cfg.interpmethod = 'nearest'; cfg.parameter = 'tissue'; atlas_int = ft_sourceinterpolate(cfg, atlas, sourcemodel); atlas_int.pos = sourcemodel.pos; cfg = []; cfg.parcellation = 'tissue'; cfg.parameter = 'cohspctrm'; parc_conn = ft_sourceparcellate(cfg, source_conn, atlas_int); cfg = []; cfg.method = 'degrees'; cfg.parameter = 'cohspctrm'; cfg.threshold = .1; network_parc = ft_networkanalysis(cfg, parc_conn); cfg = []; cfg.method = 'surface'; cfg.funparameter = 'degrees'; cfg.funcolormap = 'jet'; ft_sourceplot(cfg, network_parc); % Here, ft_sourceplots produces an error: % Subscript indices must either be real positive integers or logicals. % % Error in fixsegmentation (line 23) % indexlabel{indexval(j)} = sprintf('tissue %d', indexval(j)); % % Error in ft_datatype_parcellation (line 159) % parcellation = fixsegmentation(parcellation, fn(indexed), 'indexed'); % % Error in ft_checkdata (line 276) % data = ft_datatype_parcellation(data, 'parcellationstyle', parcellationstyle); % % Error in ft_selectdata (line 123) % varargin{i} = ft_checkdata(varargin{i}); % % Error in ft_sourceplot (line 325) % functional = ft_selectdata(tmpcfg, functional); % The problem is that ft_checkdata tries to convert the tissue % representation to the source point representation (in this case in the % field 'degrees') and for source points not belonging to a tissue this % results in a NaN. The 4k atlas used in the tutorial provides a 1-to-1 % mapping of tissues and source points so that does not happen. It does so % however for the brainnetome and the AAL atlas. % This can be prevented by manually calling ft_checkdata and replacing NaNs % by zeros: network_parc_corr = ft_checkdata(network_parc, 'datatype', {'source', 'volume'}, 'feedback', 'yes', 'hasunit', 'yes'); network_parc_corr.degrees(isnan(network_parc_corr.degrees)) = 0; ft_sourceplot(cfg, network_parc_corr); % now the plot works % -------------------------------------- Possible solutions would be to change the atlases so that they do not produce unassigned grid points (in the 4k atlas that is done using a L_? tissue). Alternatively (and less invasively), ft_checkdata could make sure no NaNs are produced during tissue - grid point conversion. Greetings, Jens

Jan-Mathijs Schoffelen - 2018-10-24 13:27:57 +0200

Thanks Jens, also for the in depth diagnostics Would it also work if in fixsegmentation line 13 is replaced by indexval = indexval(indexval~=0 & isfinite(indexval)); ?

Jens Klinzing - 2018-10-24 16:49:16 +0200

Created attachment 880 ft_sourceplot without (top) and with (bottom) NaNs

Jens Klinzing - 2018-10-24 16:50:11 +0200

Hey Jan-Mathijs, with that change ft_sourceplot will execute without error but since there are still NaNs in the functional data these datapoints will not be plotted at all leading to wholes in the surface plot. I uploaded plots with NaNs replaced by 0s (top) and with your fix (bottom). Best, Jens

Jens Klinzing - 2018-10-24 16:51:35 +0200


Jan-Mathijs Schoffelen - 2018-10-24 19:04:25 +0200

Ah, I see. I'd say that the holes are a feature, not a bug. What I don't understand, is why the cortex is not plotted in grey underneath. At least, that's what I would expect.

Jens Klinzing - 2018-10-28 22:56:28 +0100

(In reply to Jan-Mathijs Schoffelen from comment #5) Mmmh yeah that's what you'd expect and what usually happens when you have NaNs in your data. Not sure where the brain went. Did I forget something during the preparation of the source reconstruction? Is it because there is no volume normalization step (I did not do that because the brain positions are already in MNI space)?

Jan-Mathijs Schoffelen - 2018-10-29 13:05:03 +0100

Ich weiss es nicht. Kannst du ein bisschen Data hochladen?

Jens Klinzing - 2018-10-30 15:53:15 +0100

Mmh, the code example should actually be self-contained. I tried to interpolate network_parc to the standard mri (single_subj_T1_1mm.nii). That successfully adds anatomy to the structure but does not change the surface plot (slice plot is possible but functional data looks weird). That's the additional code (using fixsegmentation with your proposed fix): load('single_subj_T1_1mm.nii') cfg_int = []; cfg_int.downsample = 1; cfg_int.parameter = 'degrees'; network_parc_int = ft_sourceinterpolate(cfg_int, network_parc, mri); cfg = []; cfg.method = 'surface'; cfg.funparameter = 'degrees'; cfg.funcolormap = 'jet'; ft_sourceplot(cfg, network_parc_int); % works but still has holes cfg.method = 'slice'; ft_sourceplot(cfg, network_parc_int); % works and has anatomy but functional data looks awkward -------------------------- The same problems persist when I use my own data (subject-specific mni-aligned grids), s. new attachment. I parcellated that data using an atlas that I interpolated into the used standard 10 mm sourcemodel. I plotted it using above code after doing the networkanalysis like this: cfg = []; cfg.method = 'degrees'; cfg.parameter = 'powcorrspctrm'; cfg.threshold = .05; network_parc = ft_networkanalysis(cfg, data_parc); % Sieht nicht gut aus :/

Jens Klinzing - 2018-10-30 15:54:56 +0100

Created attachment 881 Own parcellated connectivity data

Jan-Mathijs Schoffelen - 2018-10-31 16:03:41 +0100

I have now updated the plotting and on-the-fly interpolation code such that the gray background appears again at the locations in which the data are NaN. This still leads to ugly plot, but as I mentioned before, I think that this should be a feature. Alternatively, we might consider adding an option to ft_sourceinterpolate's cfg.interpmethod to be 'nearsest_finite' or so. This might lead to unexpected effects as well, so I'd rather not do that.

Jens Klinzing - 2018-11-05 10:52:47 +0100

OK, thanks, sounds like a reasonable solution. Maybe throw a warning so that users know they got NaNs in their inside-labeled data?

Jan-Mathijs Schoffelen - 2018-11-05 13:02:51 +0100

Fine with me: can you make a suggestion through a PR on github?

Jens Klinzing - 2018-11-06 10:54:45 +0100

Mmh, like this? #869

Jan-Mathijs Schoffelen - 2018-11-06 11:50:24 +0100

Ja sicher!

Robert Oostenveld - 2019-08-10 12:36:51 +0200

This closes a whole series of bugs that have been resolved (either FIXED/WONTFIX/INVALID) for quite some time. If you disagree, please file a new issue on