Dear Don and Andrej,
This is quite simple. I added '4d' type where Don suggested and the
fix will propagate to SPM8 release within a few days.
@ Andrej, put the attached function in spm8/external/fileio/private
and see if it resolves your problem with fiducials. The issue of
additional channels is still not clear. If you only select 'MEG'
channels when you convert, do you get the right number. I tend to
agree with Don that those extra channels must really be there.
Otherwise SPM would probably crash and not finish the conversion.
@Don, if there any other fixes like this, it'd be very helpful.
Vladimir
On Wed, Jan 28, 2009 at 6:25 PM, Rojas Don <[log in to unmask]> wrote:
> To all:
>
> Sorry about an error in my last message. The headshape does have the
> fiducials. Rather, there is a small error in the spm read_headshape.m
> function that prevents the relevant code block from executing when the file
> being read is a native 4D file. Change line 88 to read:
>
> case {'4d_xyz', '4d_m4d', '4d_hs', '4d'}
>
> I added the case '4d', since that is what is the case with our data when I
> set a breakpoint in the file and read the fileformat variable. I think the
> first two cases are for files converted using pdf2set. The third case I'm
> not sure of and maybe it doesn't need to be there.
>
> Best,
>
> Don
>
> On 1/28/09 10:29 AM, "Vladimir Litvak" <[log in to unmask]> wrote:
>
>> Dear Don,
>>
>> If you have code for reading fiducials from a config file, send it to
>> me and I'll integrate it in read_headshape. We'd be very interested in
>> solving the other issues you have with SPM8 converters, possibly using
>> parts of your code, because then other users will also benefit from
>> your experience.
>>
>> Best,
>>
>> Vladimir
>>
>> On Wed, Jan 28, 2009 at 5:09 PM, Rojas Don <[log in to unmask]> wrote:
>>> Dear Andrej,
>>>
>>> I think the issue you mention with respect to the fiducials is a general
>>> problem with the conversion process, as it also affects our site, which has
>>> a 248-channel 4D system. In looking at the SPM code for reading the native
>>> 4D data, In looking at the function, it seems to me that it assumes the
>>> fiducials will be in the headshape file. In the 4D format, they are in the
>>> config file, however. You can always manually input them into the resulting
>>> D structure (in the .mat file output from spm_eeg_convert.m.
>>>
>>> As to the number of channels you have, the SPM routines automatically import
>>> all channels in the dataset. Are you absolutely certain that only the MEG
>>> and reference channels are in your datasets (also, by default, there may be
>>> a Trigger channel, Response Channel and a UACurrent Channel for the coils on
>>> head)? You can confirm this by looking at one of your datasets or at the
>>> template file you used for acquisition. On your system, there are a number
>>> of external inputs available (e.g., for EEG) that might be turned on (96 of
>>> them on our system). When we import using the spm_eeg_convert function, we
>>> get the correct number of channels on our system. Have you tried selecting
>>> MEG only during the import? There are numerous other problems for us, but
>>> that one is correct. The file format for the 148 and 248 channel systems is
>>> the same, so that shouldn't be an issue.
>>>
>>> Feel free to contact me off-list if you like. We've analyzed a lot of 4D
>>> datasets using spm5 and now spm8. Generally we've been using our own
>>> converters because of the difficulties we've had using the spm conversion
>>> routines.
>>>
>>> Best,
>>>
>>> Don
>>>
>>>
>>> On 1/28/09 4:14 AM, "Vladimir Litvak" <[log in to unmask]> wrote:
>>>
>>>> Dear Andrej,
>>>>
>>>> The message is actually quite informative about the problem. SPM uses
>>>> routines for reading BTi data developed by Jan-Mathijs Schoffelen from
>>>> Glasgow. As said in the message there might be problem having to do
>>>> with the fact that your BTi sytem is different from his. It looks like
>>>> the conversion proceeds to the end but as you say the results are
>>>> incorrect. SPMs messages except for Jan-Mathijs's warnings are normal
>>>> and do not indicate a problem. I suggest that you get in touch with
>>>> Jan-Mathijs ([log in to unmask]) and ask for his help in
>>>> resolving the problem. Also if there are other BTi users on the list
>>>> who can help with resolving this problem I suggest that they contact
>>>> Jan-Mathijs with their suggestions.
>>>>
>>>> Best,
>>>>
>>>> Vladimir
>>>>
>>>> On Wed, Jan 28, 2009 at 10:49 AM, Andrej Stancak
>>>> <[log in to unmask]> wrote:
>>>>> Dear SPM experts,
>>>>>
>>>>> I have tried to load our 4D MEG data set, that has 148 MEG sensors and 17
>>>>> non-MEG signals (=165), into SPM8b. After calling Convert from the GUI, I
>>>>> get a lengthy message (below) but what is worse, the number of channels
>>>>> read
>>>>> is wrong - it is 290 instead of the correct number 165. Also fiducials are
>>>>> not read (however, they are available in the header), and other information
>>>>> seems to be missing as well. I would be grateful for adjusting the reading
>>>>> of MEG data for 4D-148 sensors machine, if possible.
>>>>>
>>>>> Best regards
>>>>> Andrej Stancak
>>>>>
>>>>>
>>>>> Here is the message I get by calling Convert in SPM8b:
>>>>>
>>>>> Warning: reading in weight table: no warranty that this is correct. it
>>>>> seems
>>>>> to work for the
>>>>> Glasgow 248-magnetometer system. if you have some code yourself, and/or
>>>>> would like to test it
>>>>> on your own data, please contact Jan-Mathijs
>>>>>> In fileio\private\read_4d_hdr at 252
>>>>> In fileio\private\read_header at 474
>>>>> In fileio_read_header at 11
>>>>> In spm_eeg_convert at 73
>>>>> In spm_eeg_convert_ui at 81
>>>>> Warning: reading in weight table: no warranty that this is correct. it
>>>>> seems
>>>>> to work for the
>>>>> Glasgow 248-magnetometer system. if you have some code yourself, and/or
>>>>> would like to test it
>>>>> on your own data, please contact Jan-Mathijs
>>>>>> In fileio\private\read_4d_hdr at 252
>>>>> In fileio\private\read_header at 474
>>>>> In fileio\private\read_event at 426
>>>>> In fileio_read_event at 11
>>>>> In spm_eeg_convert at 95
>>>>> In spm_eeg_convert_ui at 81
>>>>> converting units from 'm' to 'mm'
>>>>> Warning: reading in weight table: no warranty that this is correct. it
>>>>> seems
>>>>> to work for
>>>>> the Glasgow 248-magnetometer system. if you have some code yourself, and/or
>>>>> would like to
>>>>> test it on your own data, please contact Jan-Mathijs
>>>>>> In fileio\private\read_4d_hdr at 252
>>>>> In fileio\private\read_header at 474
>>>>> In fileio\private\read_sens at 146
>>>>> In fileio\private\read_headshape at 144
>>>>> In fileio_read_headshape at 11
>>>>> In spm_eeg_convert at 398
>>>>> In spm_eeg_convert_ui at 81
>>>>> Warning: Could not obtain fiducials automatically.
>>>>>> In spm_eeg_convert at 400
>>>>> In spm_eeg_convert_ui at 81
>>>>> checkmeeg: no channel type, assigning default
>>>>> checkmeeg: no units, assigning default
>>>>> checkmeeg: transform type missing, assigning default
>>>>> checkmeeg: data scale missing, assigning default
>>>>> checkmeeg: data type is missing or incorrect, assigning default
>>>>> creating layout from cfg.grad
>>>>> creating layout for bti148 system
>>>>>
>>>
>>> --
>>> Donald C. Rojas, Ph.D.
>>> Associate Professor of Psychiatry and Neuroscience
>>> Director, Magnetoencephalography Laboratory
>>> University of Colorado Denver
>>> Department of Psychiatry, Mail Stop F-546
>>> Anschutz Medical Campus, Building 500 N2224G
>>> 13001 E 17th Place
>>> PO Box 6508
>>> Aurora CO 80045-0508
>>> 303-724-4994
>>> [log in to unmask]
>>>
>>> Please note: My email address has changed from [log in to unmask] to
>>> [log in to unmask] Please update your records.
>>>
>
> --
> Donald C. Rojas, Ph.D.
> Associate Professor of Psychiatry and Neuroscience
> Director, Magnetoencephalography Laboratory
> University of Colorado Denver
> Department of Psychiatry, Mail Stop F-546
> Anschutz Medical Campus, Building 500 N2224G
> 13001 E 17th Place
> PO Box 6508
> Aurora CO 80045-0508
> 303-724-4994
> [log in to unmask]
>
> Please note: My email address has changed from [log in to unmask] to
> [log in to unmask] Please update your records.
>
>
function [shape] = read_headshape(filename, varargin)
% READ_HEADSHAPE reads the fiducials and/or the measured headshape
% from a variety of files (like CTF and Polhemus). The headshape and
% fiducials can for example be used for coregistration.
%
% Use as
% [shape] = read_headshape(filename)
%
% See also READ_VOL, READ_SENS
% Copyright (C) 2008, Robert Oostenveld
%
% $Log: read_headshape.m,v $
% Revision 1.8 2009/01/28 18:29:07 vlalit
% Added '4d' type to BTi case
%
% Revision 1.7 2009/01/23 10:32:55 vlalit
% New reader for Neuromag fif format using the MNE toolbox (http://www.nmr.mgh.harvard.edu/martinos/userInfo/data/sofMNE.php) implemented by Laurence Hunt.
%
% Revision 1.6 2008/10/07 16:22:32 roboos
% added option to specify coordinates to be obtained from ctf hc file
%
% Revision 1.5 2008/05/22 14:33:18 vlalit
% Changes related to generalization of fiducials' handling in SPM.
%
% Revision 1.4 2008/05/11 16:30:30 vlalit
% Improved the support of 4d and neuromag
%
% Revision 1.3 2008/04/16 08:04:03 roboos
% allow headshape to be extracted from BEM volume conduction model
%
% Revision 1.2 2008/04/14 20:52:11 roboos
% ensure consistent output for all file formats (thanks to Vladimir)
% added convert_units
%
% Revision 1.1 2008/04/11 12:04:55 roboos
% new impoementation, required for clean interface towards SPM
%
% test whether the file exists
if ~exist(filename)
error(sprintf('file ''%s'' does not exist', filename));
end
% get the options
fileformat = keyval('fileformat', varargin);
coordinates = keyval('coordinates', varargin); if isempty(coordinates), coordinates = 'head'; end
if isempty(fileformat)
fileformat = filetype(filename);
end
% start with an empty structure
shape = [];
shape.pnt = [];
shape.fid.pnt = [];
shape.fid.label = {};
switch fileformat
case {'ctf_ds', 'ctf_hc', 'ctf_meg4', 'ctf_res4'}
[p, f, x] = fileparts(filename);
if strcmp(fileformat, 'ctf_ds')
filename = fullfile(p, [f x], [f '.hc']);
elseif strcmp(fileformat, 'ctf_meg4')
filename = fullfile(p, [f '.hc']);
elseif strcmp(fileformat, 'ctf_res4')
filename = fullfile(p, [f '.hc']);
end
orig = read_ctf_hc(filename);
switch coordinates
case 'head'
shape.fid.pnt = cell2mat(struct2cell(orig.head));
case 'dewar'
shape.fid.pnt = cell2mat(struct2cell(orig.dewar));
otherwise
error('incorrect coordinates specified');
end
shape.fid.label = fieldnames(orig.head);
case 'ctf_shape'
orig = read_ctf_shape(filename);
shape.pnt = orig.pnt;
shape.fid.label = {'NASION', 'LEFT_EAR', 'RIGHT_EAR'};
for i = 1:numel(shape.fid.label)
shape.fid.pnt = cat(1, shape.fid.pnt, ...
getfield(orig.MRI_Info, shape.fid.label{i}));
end
case {'4d_xyz', '4d_m4d', '4d_hs', '4d'}
[p, f, x] = fileparts(filename);
if ~strcmp(fileformat, '4d_hs')
filename = fullfile(p, 'hs_file');
end
[shape.pnt, fid] = read_bti_hs(filename);
% I'm making some assumptions here
% which I'm not sure will work on all 4D systems
fid = fid(1:3, :);
[junk, NZ] = max(fid(:,1));
[junk, L] = max(fid(:,2));
[junk, R] = min(fid(:,2));
shape.fid.pnt = fid([NZ L R], :);
shape.fid.label = {'NZ', 'L', 'R'};
case 'neuromag_fif'
[co,ki,nu] = hpipoints(filename);
fid = co(:,find(ki==1))';
[junk, NZ] = max(fid(:,2));
[junk, L] = min(fid(:,1));
[junk, R] = max(fid(:,1));
shape.fid.pnt = fid([NZ L R], :);
shape.fid.label = {'NZ', 'L', 'R'};
case 'neuromag_mne'
hdr = read_header(filename,'headerformat','neuromag_mne');
nFid = size(hdr.orig.dig,2); %work out number of fiducials
switch coordinates
case 'head' % digitiser points should be stored in head coordinates by default
fidN=1;
pntN=1;
for i=1:nFid %loop over fiducials
%check this point is in head coordinates:
if hdr.orig.dig(i).coord_frame~=4 % 4 is MNE constant for head coordinates
error(['Digitiser point (' num2str(i) ') not stored in head coordinates!']);
end
switch hdr.orig.dig(i).kind % constants defined in MNE - see p.215 of MNE manual
case 1 % Cardinal point (nasion, LPA or RPA)
%get location of fiducial:
shape.fid.pnt(fidN,1:3) = hdr.orig.dig(i).r*100; %multiply by 100 to convert to cm
switch hdr.orig.dig(i).ident
case 1 % LPA
shape.fid.label{fidN} = 'LPA';
case 2 % nasion
shape.fid.label{fidN} = 'Nasion';
case 3 % RPA
shape.fid.label{fidN} = 'RPA';
otherwise
error('Unidentified cardinal point in file!');
end
fidN = fidN + 1;
case 2 % HPI coil
shape.pnt(pntN,1:3) = hdr.orig.dig(i).r*100;
pntN = pntN + 1;
case 3 % EEG electrode location (or ECG)
shape.pnt(pntN,1:3) = hdr.orig.dig(i).r*100;
pntN = pntN + 1;
case 4 % Additional head point
shape.pnt(pntN,1:3) = hdr.orig.dig(i).r*100;
pntN = pntN + 1;
otherwise
warning('Unidentified digitiser point in file!');
end
end
shape.fid.label=shape.fid.label';
case 'dewar'
error('Dewar coordinates not supported for headshape yet (MNE toolbox)');
otherwise
error('Incorrect coordinates specified');
end
case 'polhemus_fil'
[shape.fid.pnt, shape.pnt, shape.fid.label] = read_polhemus_fil(filename, 0);
case 'spmeeg_mat'
tmp = load(filename);
if isfield(tmp.D, 'fiducials') && ~isempty(tmp.D.fiducials)
shape = tmp.D.fiducials;
else
error('no headshape found in SPM EEG file');
end
case 'matlab'
tmp = load(filename);
if isfield(tmp, 'shape')
shape = tmp.shape;
elseif isfield(tmp, 'elec')
shape.fid.pnt = tmp.elec.pnt;
shape.fid.label = tmp.elec.label;
else
error('no headshape found in Matlab file');
end
otherwise
success = 0;
if ~success
% try reading it as electrode positions
% and treat those as fiducials
try
elec = read_sens(filename);
if ~senstype(elec, 'eeg')
error('headshape information can not be read from MEG gradiometer file');
else
shape.fid.pnt = elec.pnt;
shape.fid.label = elec.label;
success = 1;
end
end
end
if ~success
% try reading it as volume conductor
% and treat the skin surface as headshape
try
vol = read_vol(filename);
if ~voltype(vol, 'bem')
error('skin surface can only be extracted from boundary element model');
else
if ~isfield(vol, 'skin')
vol.skin = find_outermost_boundary(vol.bnd);
end
shape.pnt = vol.bnd(vol.skin).pnt;
shape.tri = vol.bnd(vol.skin).tri; % also return the triangulation
success = 1;
end
end
end
if ~success
error('unknown fileformat for head shape information');
end
end
% this will add the units to the head shape
shape = convert_units(shape);
|