Home > bml > io > bml_neuroomega_info_raw.m

bml_neuroomega_info_raw

PURPOSE ^

BML_NEUROOMEGA_INFO_RAW returns table with OS and header info of raw neuroomega.mat (.mpx) files.

SYNOPSIS ^

function info = bml_neuroomega_info_raw(cfg)

DESCRIPTION ^

 BML_NEUROOMEGA_INFO_RAW returns table with OS and header info of raw neuroomega.mat (.mpx) files.

 Use as
   tab = bml_neuroomega_info_raw(cfg);

 'raw' files can be read by ft_read_header.

 The first argument cfg is a configuration structure, which can contain
 the following field:
 cfg.chantype - string: channel type. Required (see table below)
 cfg.path - string: path to the folder containing the .mat files. Defauts to '.'
 cfg.pattern - string: file name pattern (defaults to '*.mat')
 cfg.regexp - string: regular expression to filter files (defaults to '[RL]T[1-5]D[-]{0,1}\d+\.\d+([+-]M){0,1}F\d+\.mat')
 cfg.time_channel - string: channel to use for TimeBegin and TimeEnd 
               defaults to first channel of indicated chantype in first
               file detected.
 cfg.rm_vars - cell of char with variables names to be removed if present
               defaults to {'time_end','time_begin','filenum'}
 cfg.mpx_path - string: path to the folder containing the .mpx_ files. Defauts to cfg.path
 cfg.mpx_pattern - string: file name pattern (defaults to '*.mpx')
 cfg.mpx_regexp - string: regular expression to filter files (defaults to '[RL]T[1-5]D[-]{0,1}\d+\.\d+([+-]M){0,1}F\d+\.mpx')


 Returns a matlab 'table' with the folloing variables:
   start - double: time in seconds (calculated if mpx files are found in cfg.mpx_path)  
   end - double: time in seconds (calculated if mpx files are found in cfg.mpx_path)
   name - cell array of char: filename
   folder - cell array of char: path
   date - cell array of char: data of file modification 
   bytes - double: Size of the file in bytes
   isdir - logical: 1 if name is a folder; 0 if name is a file
   datenum - double: Modification date as serial date number.
   chantype
   Fs
   nSamples
   nChans
   nTrials
   chantype
   chanunit
   duration



 ----------------------------------------
 chantype     |   example channel
 ----------------------------------------
 'macro'      | 'CMacro_RAW_01___Central'
 'micro'      | 'CRAW_01___Central'
 'micro_hp'   | 'CSPK_01___Central'
 'analog'     | 'CANALOG_IN_1'
 'add_analog' | 'CADD_ANALOG_IN_1'
 'micro_lfp'  | 'CLFP_01___Central'
 'macro_lfp'  | 'CMacro_LFP_01___Central
 ----------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function info = bml_neuroomega_info_raw(cfg)
0002 
0003 % BML_NEUROOMEGA_INFO_RAW returns table with OS and header info of raw neuroomega.mat (.mpx) files.
0004 %
0005 % Use as
0006 %   tab = bml_neuroomega_info_raw(cfg);
0007 %
0008 % 'raw' files can be read by ft_read_header.
0009 %
0010 % The first argument cfg is a configuration structure, which can contain
0011 % the following field:
0012 % cfg.chantype - string: channel type. Required (see table below)
0013 % cfg.path - string: path to the folder containing the .mat files. Defauts to '.'
0014 % cfg.pattern - string: file name pattern (defaults to '*.mat')
0015 % cfg.regexp - string: regular expression to filter files (defaults to '[RL]T[1-5]D[-]{0,1}\d+\.\d+([+-]M){0,1}F\d+\.mat')
0016 % cfg.time_channel - string: channel to use for TimeBegin and TimeEnd
0017 %               defaults to first channel of indicated chantype in first
0018 %               file detected.
0019 % cfg.rm_vars - cell of char with variables names to be removed if present
0020 %               defaults to {'time_end','time_begin','filenum'}
0021 % cfg.mpx_path - string: path to the folder containing the .mpx_ files. Defauts to cfg.path
0022 % cfg.mpx_pattern - string: file name pattern (defaults to '*.mpx')
0023 % cfg.mpx_regexp - string: regular expression to filter files (defaults to '[RL]T[1-5]D[-]{0,1}\d+\.\d+([+-]M){0,1}F\d+\.mpx')
0024 %
0025 %
0026 % Returns a matlab 'table' with the folloing variables:
0027 %   start - double: time in seconds (calculated if mpx files are found in cfg.mpx_path)
0028 %   end - double: time in seconds (calculated if mpx files are found in cfg.mpx_path)
0029 %   name - cell array of char: filename
0030 %   folder - cell array of char: path
0031 %   date - cell array of char: data of file modification
0032 %   bytes - double: Size of the file in bytes
0033 %   isdir - logical: 1 if name is a folder; 0 if name is a file
0034 %   datenum - double: Modification date as serial date number.
0035 %   chantype
0036 %   Fs
0037 %   nSamples
0038 %   nChans
0039 %   nTrials
0040 %   chantype
0041 %   chanunit
0042 %   duration
0043 %
0044 %
0045 %
0046 % ----------------------------------------
0047 % chantype     |   example channel
0048 % ----------------------------------------
0049 % 'macro'      | 'CMacro_RAW_01___Central'
0050 % 'micro'      | 'CRAW_01___Central'
0051 % 'micro_hp'   | 'CSPK_01___Central'
0052 % 'analog'     | 'CANALOG_IN_1'
0053 % 'add_analog' | 'CADD_ANALOG_IN_1'
0054 % 'micro_lfp'  | 'CLFP_01___Central'
0055 % 'macro_lfp'  | 'CMacro_LFP_01___Central
0056 % ----------------------------------------
0057 %
0058 
0059 chantype       = bml_getopt(cfg, 'chantype');   
0060 time_channel   = bml_getopt_single(cfg,'time_channel');
0061 
0062 info = bml_neuroomega_info_file(cfg);
0063 
0064 cfg_mpx=[];
0065 cfg_mpx.path    = bml_getopt(cfg,'mpx_path',ft_getopt(cfg,'path','.'));
0066 cfg_mpx.pattern = bml_getopt(cfg,'mpx_pattern','*.mpx');
0067 cfg_mpx.regexp  = bml_getopt(cfg,'mpx_regexp','[RL]T[1-5]D[-]{0,1}\d+\.\d+([+-]M){0,1}F\d+\.mpx');
0068 rm_vars         = bml_getopt(cfg,'rm_vars',{'time_end','time_begin','filenum'});
0069 
0070 info_mpx=bml_info_file(cfg_mpx);
0071 
0072 hdr_vars={'chantype','Fs','nSamples','nChans','nTrials','chanunit','time_begin','time_end'};
0073 hdr_table = cell2table(cell(size(info,1),length(hdr_vars)));
0074 hdr_table.Properties.VariableNames = hdr_vars;
0075 
0076 assert(~isempty(chantype),'cfg.chantype required');
0077 if isempty(time_channel)
0078   hdr1 = ft_read_header(fullfile(info.folder{1},info.name{1}),'chantype','chaninfo');
0079   time_channel = hdr1.chaninfo(strcmp(hdr1.chaninfo.chantype,chantype),:).channel{1};
0080 end
0081 time_begin     = strcat(time_channel,'_TimeBegin');
0082 time_end       = strcat(time_channel,'_TimeEnd');
0083 
0084 for i=1:height(info)
0085   hdr = ft_read_header(fullfile(info.folder{i},info.name{i}),'chantype',chantype);
0086   hdr_table.chantype(i) = {strjoin(unique(hdr.chantype))};
0087   hdr_table.Fs(i) = {hdr.Fs};
0088   hdr_table.nSamples(i) = {hdr.nSamples};
0089   hdr_table.nChans(i) = {hdr.nChans};  
0090   hdr_table.nTrials(i) = {hdr.nTrials};    
0091   hdr_table.chanunit(i) = {strjoin(unique(hdr.chanunit))}; 
0092 
0093   if ismember(time_begin,fields(hdr.orig))
0094     hdr_table.time_begin(i) = {hdr.orig.(time_begin)};
0095     hdr_table.time_end(i) = {hdr.orig.(time_end)};
0096   else
0097     error('%s not present as mat variable in %s. \nSpecify cfg.time_channel as one of %s',...
0098       time_begin,fullfile(cfg.path,info.name{i}), strjoin(hdr.label));
0099   end
0100 end
0101 hdr_table.Fs = cell2mat(hdr_table.Fs);
0102 hdr_table.nSamples = cell2mat(hdr_table.nSamples);
0103 hdr_table.nChans = cell2mat(hdr_table.nChans);
0104 hdr_table.nTrials = cell2mat(hdr_table.nTrials);
0105 hdr_table.time_begin = cell2mat(hdr_table.time_begin);
0106 hdr_table.time_end = cell2mat(hdr_table.time_end);
0107 
0108 info = [info hdr_table];
0109 
0110 if ~isempty(info_mpx) %loading date from .mpx OS info if available
0111   info_mpx.basename = erase(info_mpx.name,'.mpx');
0112   info_mpx=info_mpx(:,{'basename','date','datenum'});
0113   
0114   info.date=[];
0115   info.datenum=[];
0116   info.basename = erase(info.name,'.mat');
0117   
0118   %checking that all mat files have correspondent mpx file
0119   mat_with_no_mpx = setdiff(info.basename,info_mpx.basename);
0120   if numel(mat_with_no_mpx)>0
0121     if numel(mat_with_no_mpx)<10
0122       warning("the following files don't have correspondent .mpx file: %s", strjoin(mat_with_no_mpx));
0123     else
0124       warning("%i .mat files don't have correspondent .mpx file", numel(mat_with_no_mpx));
0125     end
0126     mat_with_no_mpx=table(mat_with_no_mpx);
0127     mat_with_no_mpx.Properties.VariableNames = {'basename'};
0128     mat_with_no_mpx.date(:) = {''};
0129     mat_with_no_mpx.datenum(:) = NaN;
0130     info_mpx = [info_mpx; mat_with_no_mpx];
0131   end
0132   
0133   info=join(info,info_mpx,'Keys','basename');
0134 
0135   %adjusting time_end to bml_date2sec origin.
0136   ends = info.time_end+nanmedian(bml_date2sec(info.date)-info.time_end);
0137   %NOTE: time_start and time_end are time coordinates of the first and
0138   %last data point. Duration is the length of the 'represented' time
0139   %therefore the correct way of calculating duration is as follows:
0140   info.duration = info.time_end - info.time_begin + 1./info.Fs; 
0141   starts = ends - info.duration;
0142   info = [table(starts,ends,'VariableNames',{'starts','ends'}), info];
0143   info.basename = [];
0144   %info=sortrows(info,'starts');
0145   info = bml_annot_table(info);
0146 else
0147   warning('Specify cfg.mpx_path for starts/ends calculation')
0148   info=sortrows(info,'time_begin');
0149 end
0150 
0151 for i=1:numel(rm_vars)
0152   if ismember(rm_vars(i),info.Properties.VariableNames)
0153     info.(rm_vars{i}) = [];
0154   end
0155 end  
0156   
0157 
0158 
0159 
0160

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