| | function [sens] = ft_read_sens(filename, varargin) |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | filename = fetch_url(filename); |
| |
|
| | |
| | if ~exist(filename, 'file') |
| | error('file ''%s'' does not exist', filename); |
| | end |
| |
|
| | |
| | fileformat = ft_getopt(varargin, 'fileformat', ft_filetype(filename)); |
| | senstype = ft_getopt(varargin, 'senstype', 'eeg'); |
| | coordsys = ft_getopt(varargin, 'coordsys', 'head'); |
| | coilaccuracy = ft_getopt(varargin, 'coilaccuracy'); |
| |
|
| | switch fileformat |
| | |
| | |
| | |
| | case 'asa_elc' |
| | sens = read_asa_elc(filename); |
| | |
| | case 'polhemus_pos' |
| | sens = read_brainvision_pos(filename); |
| | |
| | case 'besa_elp' |
| | error('unknown fileformat for electrodes or gradiometers'); |
| | |
| | fid = fopen(filename); |
| | |
| | tmp = textscan(fid, '%s%s%f%f'); |
| | fclose(fid); |
| | sel = strcmpi(tmp{1}, 'EEG'); |
| | sens.label = tmp{2}(sel); |
| | az = tmp{3}(sel) * pi/180; |
| | el = tmp{4}(sel) * pi/180; |
| | r = ones(size(el)); |
| | [x, y, z] = sph2cart(az, el, r); |
| | sens.chanpos = [x y z]; |
| | |
| | case 'besa_pos' |
| | tmp = importdata(filename); |
| | if ~isnumeric(tmp) |
| | error('unexpected file format for fileformat=besa_pos') |
| | end |
| | [nchan,nrow] = size(tmp); |
| | if nrow==3 |
| | sens.pnt = tmp; |
| | elseif nrow==9 |
| | pnt1 = tmp(:,1:3); |
| | pnt2 = tmp(:,4:6); |
| | ori = tmp(:,7:9); |
| | sens.pnt = [pnt1; pnt2]; |
| | sens.ori = [ori; ori]; |
| | sens.tra = [eye(nchan) -eye(nchan)]; |
| | else |
| | error('unexpected file format for fileformat=besa_pos') |
| | end |
| | [p, f, x] = fileparts(filename); |
| | elpfile = fullfile(p, [f '.elp']); |
| | elafile = fullfile(p, [f '.ela']); |
| | if exist(elpfile, 'file') |
| | warning('reading channel labels from %s', elpfile); |
| | |
| | lbl = importdata(elpfile); |
| | sens.label = strrep(lbl.textdata(:,2) ,'''', ''); |
| | elseif exist(elafile, 'file') |
| | warning('reading channel labels from %s', elafile); |
| | |
| | lbl = importdata(elafile); |
| | lbl = strrep(lbl, 'MEG ', ''); |
| | lbl = strrep(lbl, 'EEG ', ''); |
| | sens.label = lbl; |
| | else |
| | |
| | warning('creating fake channel names for besa_pos'); |
| | for i=1:nchan |
| | sens.label{i} = sprintf('%03d', i); |
| | end |
| | end |
| | |
| | case 'besa_sfh' |
| | sfh = readBESAsfh(filename); |
| | sens.label = sfh.SurfacePointsLabels(:); |
| | sens.elecpos = sfh.SurfacePointsCoordinates(:,1:3); |
| | sel = true(sfh.NrOfPoints, 1); |
| | for i=1:sfh.NrOfPoints |
| | tok = tokenize(sens.label{i}, '_'); |
| | sens.label{i} = tok{2}; |
| | sel(i) = ~strcmp(tok{1}, 'Fid'); |
| | end |
| | sens.label = sens.label(sel); |
| | sens.elecpos = sens.elecpos(sel,:); |
| | |
| | case 'besa_sfp' |
| | [lab, pos] = read_besa_sfp(filename); |
| | |
| | sens.label = lab; |
| | sens.elecpos = pos; |
| | |
| | case {'ctf_ds', 'ctf_res4', 'ctf_old', 'neuromag_fif', 'neuromag_mne', '4d', '4d_pdf', '4d_m4d', '4d_xyz', 'yokogawa_ave', 'yokogawa_con', 'yokogawa_raw', 'itab_raw' 'itab_mhd', 'netmeg'} |
| | |
| | hdr = ft_read_header(filename, 'headerformat', fileformat, 'coordsys', coordsys, 'coilaccuracy', coilaccuracy); |
| | |
| | if isfield(hdr, 'elec') && isfield(hdr, 'grad') |
| | switch lower(senstype) |
| | case 'eeg' |
| | warning('both electrode and gradiometer information is present, returning the electrode information'); |
| | sens = hdr.elec; |
| | case 'meg' |
| | warning('both electrode and gradiometer information is present, returning the gradiometer information'); |
| | sens = hdr.grad; |
| | end |
| | elseif ~isfield(hdr, 'elec') && ~isfield(hdr, 'grad') |
| | error('neither electrode nor gradiometer information is present'); |
| | elseif isfield(hdr, 'grad') |
| | sens = hdr.grad; |
| | elseif isfield(hdr, 'elec') |
| | sens = hdr.elec; |
| | end |
| | |
| | case 'neuromag_mne_grad' |
| | |
| | |
| | hdr = ft_read_header(filename, 'headerformat', 'neuromag_mne', 'coordsys', coordsys, 'coilaccuracy', coilaccuracy); |
| | sens = hdr.grad; |
| | |
| | case 'neuromag_mne_elec' |
| | |
| | |
| | hdr = ft_read_header(filename, 'headerformat', 'neuromag_mne', 'coordsys', coordsys, 'coilaccuracy', coilaccuracy); |
| | sens = hdr.elec; |
| | |
| | case {'spmeeg_mat', 'eeglab_set'} |
| | |
| | hdr = ft_read_header(filename, 'coordsys', coordsys, 'coilaccuracy', coilaccuracy); |
| | if isfield(hdr, 'grad') |
| | sens = hdr.grad; |
| | elseif isfield(hdr, 'elec') |
| | sens = hdr.elec; |
| | else |
| | error('no electrodes or gradiometers found in the file') |
| | end |
| | |
| | case 'polhemus_fil' |
| | |
| | [sens.fid.pnt, sens.pnt, sens.fid.label] = read_polhemus_fil(filename, 0); |
| | |
| | warning('no channel names in polhemus file, using numbers instead'); |
| | for i=1:size(sens.pnt, 1) |
| | sens.label{i} = sprintf('%03d', i); |
| | end |
| | |
| | case 'matlab' |
| | |
| | matfile = filename; |
| | ws = warning('off', 'MATLAB:load:variableNotFound'); |
| | tmp = load(matfile, 'elec', 'grad', 'sens', 'elc'); |
| | warning(ws); |
| | if isfield(tmp, 'grad') |
| | sens = tmp.grad; |
| | elseif isfield(tmp, 'elec') |
| | sens = tmp.elec; |
| | elseif isfield(tmp, 'sens') |
| | sens = tmp.sens; |
| | elseif isfield(tmp, 'elc') |
| | sens = tmp.elc; |
| | else |
| | error('no electrodes or gradiometers found in MATLAB file'); |
| | end |
| | |
| | case 'zebris_sfp' |
| | |
| | [sens.fid.pnt, sens.chanpos, sens.fid.label, sens.label] = read_zebris(filename, 0); |
| | |
| | sens.label = sens.label(:); |
| | sens.fid.label = sens.fid.label(:); |
| | |
| | case '4d_el_ascii' |
| | fid = fopen(filename, 'rt'); |
| | c = textscan(fid, '%s%s%f%f%f'); |
| | l = c{:,1}; |
| | s = c{:,2}; |
| | x = c{:,3}; |
| | y = c{:,4}; |
| | z = c{:,5}; |
| | |
| | sel = isnan(z); |
| | z(sel) = y(sel); |
| | y(sel) = x(sel); |
| | x(sel) = str2double(s(sel)); |
| | s(sel) = {''}; |
| | fclose(fid); |
| | if false |
| | |
| | |
| | sens = []; |
| | sens.label = l; |
| | sens.elecpos = [x y z]; |
| | else |
| | |
| | |
| | sens = []; |
| | sens.label = l(~sel); |
| | sens.elecpos = [x(~sel) y(~sel) z(~sel)]; |
| | sens.fid.label = l(sel); |
| | sens.fid.pnt = [x(sel) y(sel) z(sel)]; |
| | end |
| | |
| | case {'localite_pos','localite_ins'} |
| | if ~usejava('jvm') |
| | fid = fopen(filename); |
| | |
| | |
| | tmp = textscan(fid,'%s'); |
| | |
| | fclose(fid); |
| | |
| | |
| | selx = strncmp('data0',tmp{1},5); |
| | sely = strncmp('data1',tmp{1},5); |
| | selz = strncmp('data2',tmp{1},5); |
| | sellab = strncmp('description',tmp{1},5); |
| | |
| | |
| | xtemp = tmp{1}(selx); |
| | ytemp = tmp{1}(sely); |
| | ztemp = tmp{1}(selz); |
| | labtemp = tmp{1}(sellab); |
| | |
| | |
| | |
| | |
| | settemp = tmp{1}(strncmp('set',tmp{1},3)); |
| | selset = strncmp('set="f',settemp,6); |
| | |
| | |
| | xtemp(selset) = []; |
| | ytemp(selset) = []; |
| | ztemp(selset) = []; |
| | labtemp(selset) = []; |
| | |
| | |
| | x = []; |
| | y = []; |
| | z = []; |
| | lbl = []; |
| | |
| | for i=1:numel(xtemp) |
| | x(i,1) = str2double(xtemp{i}(8:end-1)); |
| | y(i,1) = str2double(ytemp{i}(8:end-1)); |
| | z(i,1) = str2double(ztemp{i}(8:end-3)); |
| | lbl{i,1} = labtemp{i}(14:end-1); |
| | end; |
| | |
| | |
| | sens = []; |
| | sens.elecpos = [x y z]; |
| | sens.chanpos = sens.elecpos; |
| | sens.label = lbl; |
| | else |
| | tmp = xml2struct(filename); |
| | |
| | sens = []; |
| | |
| | |
| | |
| | |
| | for i=1:numel(tmp) |
| | if strcmp(tmp(i).Marker.set,'true') |
| | sens.elecpos(i,1) = str2double(tmp(i).Marker.ColVec3D.data0); |
| | sens.elecpos(i,2) = str2double(tmp(i).Marker.ColVec3D.data1); |
| | sens.elecpos(i,3) = str2double(tmp(i).Marker.ColVec3D.data2); |
| | sens.label{i} = tmp(i).Marker.description; |
| | end; |
| | end; |
| | |
| | sens.chanpos = sens.elecpos; |
| | end; |
| | |
| | case 'easycap_txt' |
| | |
| | fid = fopen(filename); |
| | tmp = textscan(fid,'%s%s%s%s'); |
| | fclose(fid); |
| | |
| | sens = []; |
| | if all(cellfun(@isempty, tmp{4})) |
| | |
| | sens.label = tmp{1}(2:end); |
| | theta = cellfun(@str2double, tmp{2}(2:end)); |
| | phi = cellfun(@str2double, tmp{3}(2:end)); |
| | radians = @(x) pi*x/180; |
| | warning('assuming a head radius of 85 mm'); |
| | x = 85*cos(radians(phi)).*sin(radians(theta)); |
| | y = 85*sin(radians(theta)).*sin(radians(phi)); |
| | z = 85*cos(radians(theta)); |
| | sens.unit = 'cm'; |
| | sens.elecpos = [x y z]; |
| | sens.chanpos = [x y z]; |
| | else |
| | |
| | sens.label = tmp{1}(2:end); |
| | x = cellfun(@str2double, tmp{2}(2:end)); |
| | y = cellfun(@str2double, tmp{3}(2:end)); |
| | z = cellfun(@str2double, tmp{4}(2:end)); |
| | sens.elecpos = [x y z]; |
| | sens.chanpos = [x y z]; |
| | end |
| | |
| | otherwise |
| | error('unknown fileformat for electrodes or gradiometers'); |
| | end |
| |
|
| | |
| | |
| | sens = ft_datatype_sens(sens); |
| |
|