Home > bml > annot > bml_annot2raw.m

bml_annot2raw

PURPOSE ^

BML_ANNOT2RAW creates a ft_datatype_raw of zeros with ones at annot times

SYNOPSIS ^

function raw = bml_annot2raw(cfg, annot)

DESCRIPTION ^

 BML_ANNOT2RAW creates a ft_datatype_raw of zeros with ones at annot times
 
 Use as
   raw = bml_annot2raw(cfg, annot)
   raw = bml_annot2raw(cfg.roi, annot)
   raw = bml_annot2raw(cfg.template, annot)
   raw = bml_annot2raw(cfg)
   raw = bml_annot2raw(cfg.roi)
   raw = bml_annot2raw(cfg.template)

 cfg.roi - roi table from which to construct raw
 cfg.label - cellstr, names of channels in new raw. Defaults to 'annot'
 cfg.annot_label - string, indicates channel on which events should be
     added. Defaults to cfg.label{1}
 cfg.template - raw to use as template
 annot - annotation table. If omitted a raw of zeros is returned.

 returns a FT_DATAYE_RAW structure with ones during the annotations

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function raw = bml_annot2raw(cfg, annot)
0002 
0003 % BML_ANNOT2RAW creates a ft_datatype_raw of zeros with ones at annot times
0004 %
0005 % Use as
0006 %   raw = bml_annot2raw(cfg, annot)
0007 %   raw = bml_annot2raw(cfg.roi, annot)
0008 %   raw = bml_annot2raw(cfg.template, annot)
0009 %   raw = bml_annot2raw(cfg)
0010 %   raw = bml_annot2raw(cfg.roi)
0011 %   raw = bml_annot2raw(cfg.template)
0012 %
0013 % cfg.roi - roi table from which to construct raw
0014 % cfg.label - cellstr, names of channels in new raw. Defaults to 'annot'
0015 % cfg.annot_label - string, indicates channel on which events should be
0016 %     added. Defaults to cfg.label{1}
0017 % cfg.template - raw to use as template
0018 % annot - annotation table. If omitted a raw of zeros is returned.
0019 %
0020 % returns a FT_DATAYE_RAW structure with ones during the annotations
0021 
0022 if istable(cfg)
0023   cfg = struct('roi',cfg);
0024 elseif isstruct(cfg) && all(ismember({'trial','time','label'},fieldnames(cfg)))  
0025     cfg = struct('template',cfg);
0026 end
0027 roi         = bml_getopt(cfg,'roi');
0028 template    = bml_getopt(cfg,'template');
0029 label       = bml_getopt(cfg,'label',{'annot'});
0030 
0031 assert(~isempty(roi) || ~isempty(template),'cfg.roi or cfg.template required');
0032 
0033 %creating raw
0034 if ~isempty(roi) %from roi
0035   raw=[];
0036   raw.time=cell(1,height(roi));
0037   raw.trial=cell(1,height(roi));
0038   raw.fsample=roi.Fs(1);
0039   raw.label = label;
0040   assert(length(unique(roi.Fs))==1, "Inconsistent Fs in roi");
0041   for i=1:height(roi)
0042     %assert(height(roi)==1,"can't deal with more than one sync chunk after consolidation for now");
0043     raw.time{i}=bml_idx2time(roi(i,:),roi.s1(i):roi.s2(i));
0044     raw.trial{i}=zeros(length(label),size(raw.time{1},2));
0045   end
0046 elseif ~isempty(template) %from template
0047   raw = template;
0048   for i=1:length(raw.trial)
0049     raw.trial{i}=zeros(length(label),size(raw.time{i},2));
0050   end
0051   roi = bml_raw2annot(raw);
0052 else
0053   error('cfg.roi or cfg.template required');
0054 end
0055 
0056 if nargin == 2
0057   annot = bml_annot_table(annot,[],inputname(2));
0058   
0059   % assert(isempty(bml_annot_overlap(annot)),'annot contains overlaps');
0060   % if all(annot.duration==0)
0061   %   annot = bml_annot_extend(annot,mean(diff(raw.time{1}))/2);
0062   % end
0063   
0064   description = annot.Properties.Description;
0065   if isempty(description) 
0066     description = 'annot';
0067   end
0068   if length(raw.label)==1 && strcmp(raw.label{1},'annot')
0069     raw.label={description};
0070   end
0071   annot_label    = bml_getopt(cfg,'annot_label',raw.label{1});
0072   annot_idx   = bml_getidx(annot_label,raw.label);
0073   
0074   for t=1:height(roi)
0075     t_annot = bml_annot_filter(annot,roi(t,:));
0076     for i=1:height(t_annot)
0077       [s,e] = bml_crop_idx_valid(roi(t,:), t_annot.starts(i), t_annot.ends(i));
0078       raw.trial{t}(annot_idx,s:e)=1;
0079     end
0080   end
0081 end
0082 
0083 
0084 
0085

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