Back to the main page.

Bug 2839 - allow spm12 as full alternative to spm8

Status CLOSED FIXED
Reported 2015-02-12 09:50:00 +0100
Modified 2017-11-20 20:14:32 +0100
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Mac OS
Importance: P5 minor
Assigned to: Jan-Mathijs Schoffelen
URL:
Tags:
Depends on:
Blocks: 2837
See also:

Robert Oostenveld - 2015-02-12 09:50:13 +0100

I came across a piece of code like this if ~ft_hastoolbox('spm') ft_hastoolbox('spm8', 1); end which checks any SPM, and if not found adds spm8. I changed it into ft_hastoolbox('spm8up', 1); which checks for SPM8 or later, and adds spm8 the path if not present I expect that in many (if not all) cases spm12 will work where we are now requiring spm8. So perhaps all occurrences of hastoolbox(spm8) need to be updated in spm8up.


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

we should also deprecate spm2, and remove it from fieldtrip/external/spm2. However, we should maintain support for mnc (=minc) files...


Arjen Stolk - 2016-03-15 04:22:33 +0100

The ecog pipeline would benefit from this integration. See: http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=2837


Jan-Mathijs Schoffelen - 2017-03-16 16:04:33 +0100

I continued working in this direction, and have updated ft_volumesegment to now also be able to use spm12, both old-style (a la spm8), and new-style (with 6 tissue types). It's as of yet in a separate branch of mine: github.com/schoffelen/fieldtrip/volumesegment


Jan-Mathijs Schoffelen - 2017-03-27 09:32:28 +0200

I pulled the branch into the master branch with PR 376. As far as I can see, spm12 is now a full alternative to spm8, since both ft_volumesegment and ft_volumenormalise are fully functional with spm12 as spmversion, with added new-style segmentation functionality for ft_volumesegment.


Jan-Mathijs Schoffelen - 2017-11-07 21:29:56 +0100

Hi Guillaume, I was wondering whether I could pick your brain for a minute. Briefly, it's about my attempt to implement the 'new-style' spatial normalisation into FieldTrip. (before, we could only use spm12 in combination with the OldNorm functionality). In short, I wrote some FieldTrip glue around some spm functions, which I put in fieldtrip/external/spm12. So far so good, and it all works fine on Linux and Mac. The thing Jens (in CC) runs into, is that on his Windows 7 platform (matlab 2015b) he gets a rather obscure error, but this happens only once. This seems to occur upon the first call to spm (where at some point spm_select('init') is called, which seems to require the presence of a delicate subset of functions from matlabbatch). In short, we tracked it down to me not having copied in a necessary subset of files from spm12/matlabbatch, in particular some of the @cfg_xxx class directories. My first thought now was to minimally add the necessary functions, but this proved to be a tedious process, so I thought to just include all these @cfg_xxx class directories in our external/spm12, which on the other hand seems to be quite a bit of an overkill. Do you see an elegant alternative solution to this?


Guillaume - 2017-11-08 17:11:46 +0100

Hello, sorry about this - unfortunately SPM is not as modular as FieldTrip. I'm surprised about the error being platform-specific: do you have a more detailed error message? The only difference I can think of is that, on Windows, drive letters are detected but I doubt this is causing any trouble here. I cannot think of a simple and elegant way to resolve this. Copying the whole matlabbatch folder is the safe way or it seems that you could only copy folders @cfg_entry, private, @cfg_item, @cfg_branch, @cfg_intree, @cfg_leaf (as well as files cfg_getfile.m and cfg_get_defaults.m). That said, I assume the problem is with spm_select('regfilter') which is not necessary if you don't use the batch system and spm_select() calls so maybe we could do something from our side if the whole matlabbatch is not found and make this call a no-op. Could you point out to me your piece of code calling SPM12 functionalities? Also, could you add Volkmar Glauche to this report as he developed matlabbatch and might have further suggestions. </p>

Jan-Mathijs Schoffelen - 2017-11-09 09:27:58 +0100

Thanks for getting back to us about this. A detailed error stack is pasted below I think it is Windows specific, because in spm_platform: spm_select('ListDrives') is only called when PLATFORM.filesys = 'win' This latter call indeed (recursively, through spm_select('init') ends up in spm_select('regfilter'), which depends on functionality in matlabbatch. I guess that the general idea is to always ensure that the matlabbatch is 'initialized' upon starting SPM in a regular fashion, and perhaps it is not worth the hassle to come up with a workaround from your end for our exceptional use case. By now I have solved it by adding the necessary matlabbatch related code to fieldtrip/external/spm12, and would be happy to leave it at that. Unless you'd prefer to solve it in a different way. Thanks again for thinking along! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ERROR STACK Undefined function or variable 'cfg_intree'. Error in cfg_branch (line 92) item = class(struct([]), myclass, gitem, cfg_intree); Error in cfg_getfile>reg_filter (line 1185) dprms = {cfg_branch}; Error in cfg_getfile (line 177) t = reg_filter(varargin{2:end}); Error in spm_select (line 115) cfg_getfile('regfilter', 'mesh', {'.gii$'}); Error in spm_select (line 110) spm_select('regfilter'); Error in spm_select (line 97) spm_select('init'); Error in spm_platform>init_platform (line 233) driveLett = spm_select('ListDrives'); Error in spm_platform (line 62) if isempty(PLATFORM), PLATFORM = init_platform; end Error in spm_smoothto8bit>smoothto8bit (line 46) VO.dt = [spm_type('uint8') spm_platform('bigend')]; Error in spm_smoothto8bit (line 16) VO = smoothto8bit(V,fwhm); Error in spm_normalise (line 157) VF1 = spm_smoothto8bit(VF,flags.smosrc); Error in align_ctf2acpc (line 174) params = spm_normalise(V2,V1,[],[],[],flags);


Guillaume - 2017-11-09 12:40:22 +0100

Thanks, it now completely makes sense. The 'drives' option in spm_platform() has been deprecated for 5 years (it was returning a warning) so I've now removed it from our development version. This should solve the platform-specific issue in your case and remove the need to copy most of matlabbatch. It might be safer to fix it your way though as it could happen that some of the SPM functions you use call spm_select() internally one day or another.


Jan-Mathijs Schoffelen - 2017-11-09 12:46:51 +0100

Thanks Guillaume!