Back to the main page.

Bug 3319 - Mesh tissues were ordered according to input, now alphabetical

Reported 2017-06-27 13:51:00 +0200
Modified 2018-03-02 15:04:54 +0100
Product: FieldTrip
Component: forward
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P5 normal
Assigned to: Jan-Mathijs Schoffelen
Depends on:
See also:

Jens Klinzing - 2017-06-27 13:51:08 +0200

One of the recent changes (I wasn't able to quite figure out which one) changed the order of tissue types in mesh.tissuelabel. The order used to follow the order in which the tissues were specified for segmentation (cfg.output and the order of fields in the resulting structure), now its alphabetical. This silently breaks the FEM headmodel tutorial (it seems now wrong conductivities are assigned to the tissues when calling ft_prepare_headmodel): --- mri = ft_read_mri('Subject01.mri'); cfg = []; cfg.dim = mri.dim; mri = ft_volumereslice(cfg,mri); cfg = []; cfg.output = {'gray','white','csf','skull','scalp'}; segmentedmri = ft_volumesegment(cfg, mri); cfg = []; cfg.shift = 0.3; cfg.method = 'hexahedral'; mesh = ft_prepare_mesh(cfg,segmentedmri); mesh.tissuelabel % this is now in alphabetical order --- I think we should either change the order or the tutorial. This here would be robust against any order changes in the mesh (but I'm sure there is a more elegant way to do this): conductivities{1} = {'gray'; 'white'; 'csf'; 'skull'; 'scalp'}; conductivities{2} = {0.33; 0.14; 1.79; 0.01; 0.43}; for t = 1:numel(mesh.tissuelabel) idx(t) = find(cellfun(@(x) strcmp(mesh.tissuelabel{t}, x), conductivities{1})); end % Create the actual head model cfg = []; cfg.method = 'simbio'; cfg.conductivity = [conductivities{2}{idx}]; % order follows mesh.tissuelabel vol = ft_prepare_headmodel(cfg, mesh);

Robert Oostenveld - 2017-06-27 15:19:01 +0200

I consider it a bug that the labels are automatically alphabetical (imagine that happening on channel labels: everyone would complain). The user should be able to rely on the order he specifies things in his script, and the user is expected (and required) to be consistent in his own script.

Jan-Mathijs Schoffelen - 2018-02-15 11:19:37 +0100

alphabetical order was caused by ft_datatype_segmentation, where with a setdiff operation the inside field was removed from the list of fieldnames of the segmentedmri. An alternative way of getting rid of the inside preserves the order and has now been implemented and pushed to the git-repo.

Jan-Mathijs Schoffelen - 2018-03-02 15:04:54 +0100