Home > bml > io > bml_neuroomega_load.m

bml_neuroomega_load

PURPOSE ^

BML_NEUROOMEGA_LOAD loads a NeuroOmega dataset as FT_DATATYPE_RAW data structure.

SYNOPSIS ^

function [Rec] = bml_neuroomega_load(cfg)

DESCRIPTION ^

 BML_NEUROOMEGA_LOAD loads a NeuroOmega dataset as FT_DATATYPE_RAW data structure. 

 Use as
   rec = bml_load_neuroomega(cfg);

 The first argument cfg is a configuration structure, which may contain
 the following fields:
 cfg.path - string: path to the folder containing the .mat files. Defauts to '.'
 cfg.depth - double: depths to be loaded. If empty (defaults) all depths
             are loaded
 cfg.files_table - table: compatible with output of bml_neuroomega_info_file
             should conatin vars 'depth', 'name', 'folder'
 cfg.chantype - cell array of strings: defines channel types to be loaded.
                use an invalid channel as '?' to get a table of available
                channels and chantypes printed out. An error will stop
                further analysis. 

 Returns a struct.array, where each element contains the following fields
 Rec(i).files - cell array of strings: .mat filenames
 Rec(i).depth - float: depth of the record
 Rec(i).<chantype1> - FT_DATATYPE_RAW containing the data of <chantype1>
 Rec(i).<chantype2> - FT_DATATYPE_RAW containing the data of <chantype2>

 chantypes can be any of the following
   micro - high impedance microelectrode raw signal
   macro - low impedance "ring" electrode raw signal
   analog - analog input, usually audio
   micro_lfp - low-pass filtered and downsampled version of micro
   micro_hf - high-pass filtered version of micro
   macro_lfp - low-pass filtered and downsampled version of macro
   digital - digital input (up and down)
   add_analog - additional analog channels

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Rec] =  bml_neuroomega_load(cfg)
0002 
0003 % BML_NEUROOMEGA_LOAD loads a NeuroOmega dataset as FT_DATATYPE_RAW data structure.
0004 %
0005 % Use as
0006 %   rec = bml_load_neuroomega(cfg);
0007 %
0008 % The first argument cfg is a configuration structure, which may contain
0009 % the following fields:
0010 % cfg.path - string: path to the folder containing the .mat files. Defauts to '.'
0011 % cfg.depth - double: depths to be loaded. If empty (defaults) all depths
0012 %             are loaded
0013 % cfg.files_table - table: compatible with output of bml_neuroomega_info_file
0014 %             should conatin vars 'depth', 'name', 'folder'
0015 % cfg.chantype - cell array of strings: defines channel types to be loaded.
0016 %                use an invalid channel as '?' to get a table of available
0017 %                channels and chantypes printed out. An error will stop
0018 %                further analysis.
0019 %
0020 % Returns a struct.array, where each element contains the following fields
0021 % Rec(i).files - cell array of strings: .mat filenames
0022 % Rec(i).depth - float: depth of the record
0023 % Rec(i).<chantype1> - FT_DATATYPE_RAW containing the data of <chantype1>
0024 % Rec(i).<chantype2> - FT_DATATYPE_RAW containing the data of <chantype2>
0025 %
0026 % chantypes can be any of the following
0027 %   micro - high impedance microelectrode raw signal
0028 %   macro - low impedance "ring" electrode raw signal
0029 %   analog - analog input, usually audio
0030 %   micro_lfp - low-pass filtered and downsampled version of micro
0031 %   micro_hf - high-pass filtered version of micro
0032 %   macro_lfp - low-pass filtered and downsampled version of macro
0033 %   digital - digital input (up and down)
0034 %   add_analog - additional analog channels
0035 %
0036 %
0037 
0038 %2017.10.12 AB Based on Ahmad's function ReadNeuroOmega_AA.m, adapted for
0039 %fieltrip
0040 REQUIRED_VARS = {'depth','name','folder'};
0041 
0042 depth = ft_getopt(cfg,'depth',[]);
0043 files = ft_getopt(cfg,'files_table',[]);
0044 chantype = ft_getopt(cfg,'chantype',{'micro','macro','analog'});
0045 if ~iscell(chantype); chantype={chantype}; end
0046 
0047 if isempty(files)
0048   files = bml_neuroomega_info_file(cfg);
0049 elseif ~all(ismember(REQUIRED_VARS,files.Properties.VariableNames))
0050   error(['variables ' strjoin(REQUIRED_VARS,', ') ' required in cfg.files_table']);
0051 end
0052 
0053 depth_all = unique([files.depth]);
0054 if isempty(depth); depth=depth_all; end
0055 
0056 depth_sel=intersect(depth,depth_all);
0057 if isempty(depth_sel)
0058   error(['No depth selected. Available depths are : ',strjoin(depth_all,' ')]);
0059 end
0060 
0061 N=numel(depth_sel);
0062 Rec(N)=struct();
0063 for m=1:N %cycling through depths
0064     fprintf('\n--- Processing Depth %f ---\n', depth_sel(m));
0065     db = files([files.depth]==depth_sel(m),:);
0066     db = sortrows(db,'name');
0067     Rec(m).folder=db.folder;    
0068     Rec(m).filename=db.name;
0069     Rec(m).depth=depth_sel(m);
0070    
0071     for i=1:numel(chantype) %cycling through chantypes
0072       tmp=cellfun(@(x) ft_preprocessing(...
0073           struct('dataset',x,'chantype',chantype{i})),...
0074           fullfile(Rec(m).folder,Rec(m).filename),'UniformOutput',false);
0075       Rec(m).(chantype{i})=ft_appenddata(struct('appenddim','time'),tmp{:});       
0076     end   
0077 end
0078

Generated on Tue 25-Sep-2018 10:08:19 by m2html © 2005