Dear Andrej,
I looked at the file you sent me and found two problems, both minor.
The first problem was that the user interface of conversion only
allowed selecting files with a dot in their name. The only file with
the dot in its name in this case was not the right file to select. I'm
not an expert on BTi file format and I don't know why fileio still
recognizes that file and tries to convert it and why you get the
result you get, but that's probably something that should be fixed. If
you put the attached spm_eeg_convert_ui in SPM directory you'll be
able to select the right file (in this case the largest) and the
problem with extra-channels will go away.
The second problem has to do with the fact that BTi was not yet
supported by the chantype function that provides SPM with information
about what the MEG channels are. Actually in your version of SPM this
might not be a problem because there the things work slightly
differently. Anyway, put the attached chantype.m in
external/fileio/private and it should work. I put in some basic
support based on channel labels. Perhaps there is additional
information in the header that Don or Jan-Mathijs could add, but at
least for MEG channels this seems to be sufficient.
Let me know if everything works now.
Best,
Vladimir
On Wed, Jan 28, 2009 at 8:17 PM, Stancak, Andrej
<[log in to unmask]> wrote:
> Dear Vladimir and Don,
>
> I have copied the new read_headshape.m as suggested, and it worked. The
> fiducials are in the spm8_*.mat and they look reasonable.
>
> However, there are still problems with data (signals) as they are read into
> SPM8b. I have read them with "just view" and then clicked MEG to visualise
> only the MEG channels. What was correct was that 148 signals labeled Annn
> (nnn = channel number) were plotted. However, the signals themselves are not
> all right. Three channels are clearly just 50 Hz noise (probably
> misplacement of an MEG channel with e.g. Gx), and when I compare the signals
> with BESA screen, they do not match. I have also tried to read by defining
> the read parameters (and manually indicated the MEG channels) but the
> outcome was the same as "just read". The size of the data matrix (according
> to the spm8_*.mat file) clearly gives 290 channels and not 165 as it should
> be.
>
> I can procede with "Montage" and write a routine that regroups the MEG
> channels and discards the rest, and compare this new data matrix with BESA.
> However, I still think "Convert" should be able to read the 148-sensor data
> well.
>
> Thank you very much for sorting out the fiducials problem.
>
> Andrej
>
> Prof. Andrej Stancak, PhD.
> The University of Liverpool
> School of Psychology
> The Eleanor Rathbone Building
> Bedford Street South, Room 209
> Liverpool
> L69 7ZA
>
> E:mail: [log in to unmask] (primary)
> [log in to unmask] (secondary)
> Phone: 0151 7946951
> Office hours: Monday 10-12, Wednesday 10-12
>
>
>
> -----Original Message-----
> From: Vladimir Litvak [mailto:[log in to unmask]]
> Sent: Wed 28/01/2009 18:36
> To: Rojas Don
> Cc: jan-mathijs schoffelen; Stancak, Andrej; spm
> Subject: Re: [SPM] SPM8b - MEEG: reading 4D-148 sensors problem
>
> 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 type = chantype(input, desired)
% CHANTYPE determines for each channel what type it is, e.g. planar/axial gradiometer or magnetometer
%
% Use as
% type = chantype(hdr)
% type = chantype(sens)
% type = chantype(label)
% or as
% type = chantype(hdr, desired)
% type = chantype(sens, desired)
% type = chantype(label, desired)
% Copyright (C) 2008, Robert Oostenveld
%
% $Log: chantype.m,v $
% Revision 1.4 2009/01/29 11:45:12 vlalit
% Basic support for BTi based on code from channelselection
%
% Revision 1.3 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.2 2009/01/21 16:42:41 vlalit
% Added support for EEG systems.
%
% Revision 1.7 2008/11/12 20:32:31 roboos
% refined ctf headloc channels
%
% Revision 1.6 2008/11/03 11:36:09 roboos
% added work-around for unusual/spm5 ctf headers -> give warning and keep all at unknown
% give error for weird input
%
% Revision 1.5 2008/10/22 07:22:46 roboos
% also detect refmag and refgrad from ctf labels, use regexp and local subfunction
%
% Revision 1.4 2008/10/21 20:32:47 roboos
% added second input argument (desired type)
% besides hdr, also allow grad and label input (ctf only sofar)
%
% Revision 1.3 2008/10/20 15:14:06 roboos
% added missing semicolon
%
% Revision 1.2 2008/09/10 10:06:07 roboos
% added ctf headloc
%
% Revision 1.1 2008/09/10 10:04:22 roboos
% new function
%
% determine the type of input
isheader = isa(input, 'struct') && isfield(input, 'label') && isfield(input, 'Fs');
isgrad = isa(input, 'struct') && isfield(input, 'pnt') && isfield(input, 'ori');
islabel = isa(input, 'cell') && isa(input{1}, 'char');
hdr = input;
grad = input;
label = input;
if isheader
numchan = length(hdr.label);
elseif isgrad
numchan = length(grad.label);
elseif islabel
numchan = length(label);
else
error('the input that was provided to this function cannot be deciphered');
end
% start with unknown type
type = cell(numchan,1);
for i=1:length(type)
type{i} = 'unknown';
end
if senstype(input, 'neuromag')
% channames-KI is the channel kind, 1=meg, 202=eog, 2=eeg, 3=trigger (I am nut sure, but have inferred this from a single test file)
% chaninfo-TY is the Coil type (0=magnetometer, 1=planar gradiometer)
if isfield(hdr, 'orig') && isfield(hdr.orig, 'channames')
for sel=find(hdr.orig.channames.KI(:)==202)'
type{sel} = 'eog';
end
for sel=find(hdr.orig.channames.KI(:)==2)'
type{sel} = 'eeg';
end
for sel=find(hdr.orig.channames.KI(:)==3)'
type{sel} = 'trigger';
end
% determinge the MEG channel subtype
selmeg=find(hdr.orig.channames.KI(:)==1)';
for i=1:length(selmeg)
if hdr.orig.chaninfo.TY(i)==0
type{selmeg(i)} = 'magnetometer';
elseif hdr.orig.chaninfo.TY(i)==1
type{selmeg(i)} = 'planar';
end
end
elseif isfield(hdr, 'orig') && isfield(hdr.orig, 'chs') && isfield(hdr.orig.chs, 'coil_type')
%all the chs.kinds and chs.coil_types are obtained from the MNE
%manual, p.210-211
for sel=find([hdr.orig.chs.kind]==1 & [hdr.orig.chs.coil_type]==3012)' %planar gradiometers
[type{sel}] = deal('planar');
end
for sel=find([hdr.orig.chs.kind]==1 & [hdr.orig.chs.coil_type]==3022)' %magnetometers
[type{sel}] = deal('magnetometer');
end
for sel=find([hdr.orig.chs.kind]==301)' %MEG reference channel, located far from head
[type{sel}] = deal('meg_ref');
end
for sel=find([hdr.orig.chs.kind]==2)' %EEG channels
[type{sel}] = deal('eeg');
end
for sel=find([hdr.orig.chs.kind]==201)' %MCG channels
[type{sel}] = deal('mcg');
end
for sel=find([hdr.orig.chs.kind]==3)' %Stim channels
[type{sel}] = deal('trigger');
end
for sel=find([hdr.orig.chs.kind]==202)' %EOG
[type{sel}] = deal('eog');
end
for sel=find([hdr.orig.chs.kind]==302)' %EMG
[type{sel}] = deal('emg');
end
for sel=find([hdr.orig.chs.kind]==402)' %ECG
[type{sel}] = deal('ecg');
end
for sel=find([hdr.orig.chs.kind]==502)' %MISC
[type{sel}] = deal('misc');
end
for sel=find([hdr.orig.chs.kind]==602)' %Resp
[type{sel}] = deal('respiration');
end
end
elseif senstype(input, 'ctf') && islabel
% the channels have to be identified based on their name alone
sel = myregexp('^M[ZLR][A-Z][0-9][0-9]$', label);
type(sel) = {'meg'}; % normal gradiometer channels
sel = myregexp('^B[GPR][0-9]$', label);
type(sel) = {'refmag'}; % reference magnetometers
sel = myregexp('^[GPQR][0-9][0-9]$', label);
type(sel) = {'refgrad'}; % reference gradiometers
elseif senstype(input, 'ctf') && isgrad
% in principle it is possible to look at the number of coils, but here the channels are identified based on their name
sel = myregexp('^M[ZLR][A-Z][0-9][0-9]$', grad.label);
type(sel) = {'meg'}; % normal gradiometer channels
sel = myregexp('^B[GPR][0-9]$', grad.label);
type(sel) = {'refmag'}; % reference magnetometers
sel = myregexp('^[GPQR][0-9][0-9]$', grad.label);
type(sel) = {'refgrad'}; % reference gradiometers
elseif senstype(input, 'ctf') && isheader
% meg channels are 5, refmag 0, refgrad 1, adcs 18, trigger 11, eeg 9
if isfield(hdr, 'orig') && isfield(hdr.orig, 'sensType')
origSensType = hdr.orig.sensType;
elseif isfield(hdr, 'orig') && isfield(hdr.orig, 'res4')
origSensType = [hdr.orig.res4.senres.sensorTypeIndex];
else
warning('could not determine channel type from the CTF header');
origSensType = [];
end
for sel=find(origSensType(:)==5)'
type{sel} = 'meg';
end
for sel=find(origSensType(:)==0)'
type{sel} = 'refmag';
end
for sel=find(origSensType(:)==1)'
type{sel} = 'refgrad';
end
for sel=find(origSensType(:)==18)'
type{sel} = 'adc';
end
for sel=find(origSensType(:)==11)'
type{sel} = 'trigger';
end
for sel=find(origSensType(:)==9)'
type{sel} = 'eeg';
end
for sel=find(origSensType(:)==29)'
type{sel} = 'reserved'; % these are "reserved for future use", but relate to head localization
end
for sel=find(origSensType(:)==13)'
type{sel} = 'headloc'; % these represent the x, y, z position of the head coils
end
for sel=find(origSensType(:)==28)'
type{sel} = 'headloc_gof'; % these represent the goodness of fit for the head coils
end
% for sel=find(origSensType(:)==23)'
% type{sel} = 'SPLxxxx'; % I have no idea what these are
% end
elseif senstype(input, 'bti')
if isheader || isgrad
label = input.label;
end
% all 4D-BTi MEG channels start with "A"
% all 4D-BTi reference channels start with M or G
[type{strncmp('A', label, 1)}] = deal('magnetometer');
[type{strncmp('M', label, 1)}] = deal('refmag');
[type{strncmp('G', label, 1)}] = deal('refgrad');
elseif senstype(input, 'eeg') && islabel
% use an external helper function to define the list with EEG channel names
[type{match_str(label, senslabel(senstype(label)))}] = deal('eeg');
elseif senstype(input, 'eeg') && isheader
% use an external helper function to define the list with EEG channel names
[type{match_str(hdr.label, senslabel(senstype(hdr)))}] = deal('eeg');
end % senstype
if nargin>1
% return a boolean vector
type = strcmp(desired, type);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% helper function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function match = myregexp(pat, list)
match = false(size(list));
for i=1:numel(list)
match(i) = ~isempty(regexp(list{i}, pat, 'once'));
end
function spm_eeg_convert_ui(S)
% User interface for M/EEG conversion function
% FORMAT spm_eeg_convert_ui(S)
% S - existing configuration struct (optional)
% _______________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
% $Id: spm_eeg_convert_ui.m 2667 2009-01-29 11:42:49Z vladimir $
if nargin == 0
S=[];
end
[Finter,Fgraph,CmdLine] = spm('FnUIsetup','MEEG data conversion ',0);
if ~isfield(S, 'dataset')
S.dataset = spm_select(1, '.*', 'Select M/EEG data file');
end
if isempty(S.dataset)
error('No dataset specified');
end
if spm_input('Define settings?','+1','yes|just read',[1 0], 0);
if ~isfield(S, 'continuous')
S.continuous = spm_input('How to read?','+1','continuous|trials',[1 0], 1);
end
if S.continuous
readall = spm_input('Read everything?','+1','yes|no',[1 0]);
if ~isfield(S, 'timewindow')
S.timewindow = [];
end
if ~readall && isempty(S.timewindow);
S.timewindow = spm_input('Input time window ([start end] in sec)', '+1', 'r', '', 2);
end
else
res = spm_input('Where to look for trials?','+1','data|define|file',[1 2 3], 1);
switch res
case 1
S.usetrials = 1;
case 2
S.usetrials = 0;
[trl, conditionlabel, S] = spm_eeg_definetrial(S);
S.trl = trl;
S.conditionlabel = conditionlabel;
case 3
S.usetrials = 0;
if ~isfield(S, 'trlfile')
S.trlfile = spm_select(1, '\.mat$', 'Select a trial definition file');
end
end
end
if S.continuous || ~S.usetrials
S.checkboundary = spm_input('Read across trial borders?','+1','yes|no',[0 1]);
end
if ~isfield(S, 'channels')
S.channels = spm_input('What channels?','+1','all|meg|eeg|gui|file');
end
S = spm_eeg_channelselection(S);
if ~isfield(S, 'outfile')
if S.continuous
prefix = 'spm8_';
else
prefix = 'espm8_';
end
S.outfile = spm_input('SPM EEG file name', '+1', 's', [prefix spm_str_manip(S.dataset,'tr')]);
end
end
D = spm_eeg_convert(S);
if ~isfield(S, 'review') || S.review
spm_eeg_review(D);
end
|