Home > data-vis > vis_streams_data.m

vis_streams_data

PURPOSE ^

each element of celldata is a cstream or cevent data

SYNOPSIS ^

function h = vis_streams_data(celldata, window_times, streamlabels, args)

DESCRIPTION ^

 each element of celldata is a cstream or cevent data
 {cev1, cev2, cev3}
 the element can also be another cell, B, where B{1} is cev or cstream and B{2} is a colorset
 {cev1, {cev2, colormap}, cev3}
 this is useful if you want one of the cevents to have a unique colormap, such as when we have a continuous stream converted to cevent

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function h = vis_streams_data(celldata, window_times, streamlabels, args)
0002 % each element of celldata is a cstream or cevent data
0003 % {cev1, cev2, cev3}
0004 % the element can also be another cell, B, where B{1} is cev or cstream and B{2} is a colorset
0005 % {cev1, {cev2, colormap}, cev3}
0006 % this is useful if you want one of the cevents to have a unique colormap, such as when we have a continuous stream converted to cevent
0007 
0008 if ischar(celldata)
0009     switch celldata
0010         case 'demo1'
0011             sub = 7206;
0012             celldata = {get_variable(sub, 'cstream_eye_roi_child'), get_variable(sub, 'cevent_eye_roi_parent')};
0013 %             window_times = get_variable(sub, 'cevent_trials');
0014             window_times = [];
0015             streamlabels = {'ceye', 'peye'};
0016     end
0017 end
0018 
0019 if ~exist('args', 'var')
0020     args = struct();
0021 end
0022 
0023 if ~isfield(args, 'titlelabel')
0024     args.titlelabel = [];
0025 end
0026 
0027 if ~isfield(args, 'colors')
0028     args.colors = set_colors([]);
0029 end
0030 
0031 if ~isfield(args, 'draw_edge')
0032     args.draw_edge = 1;
0033 end
0034 
0035 if ~isfield(args, 'isCont')
0036     args.isCont = 0;
0037 end
0038 
0039 if ~exist('streamlabels', 'var') || isempty(streamlabels)
0040     for c = 1:numel(celldata)
0041         streamlabels{1,c} = sprintf('%d', c);
0042     end
0043 end
0044 
0045 if ~exist('window_times', 'var')
0046     window_times = [];
0047 end
0048 
0049 streamlabels = cellfun(@(a) strrep(a, '_', '\_'), streamlabels, 'un', 0);
0050 streamlabels = streamlabels(end:-1:1);
0051 celldata = celldata(end:-1:1);
0052 
0053 space = 0.03;
0054 height = 1;
0055 bottom = 0;
0056 
0057 numdata = numel(celldata);
0058 
0059 for d = 1:numel(celldata)
0060     cevorcst = celldata{d};
0061     if ~isstruct(cevorcst)
0062         if size(cevorcst,2) == 2
0063             cev = cstream2cevent(cevorcst);
0064         else
0065             cev = cevorcst;
0066         end
0067         celldata{d} = cev;
0068     end
0069 end
0070 
0071 if isempty(window_times) % create trials, 120 seconds each, starting from earliest timestamp in the data
0072     begin_times = zeros(1,numel(celldata));
0073     end_times = begin_times;
0074     for c = 1:numel(celldata)
0075         if ~isempty(celldata{c})
0076             begin_times(c) = celldata{c}(1,1);
0077             end_times(c) = celldata{c}(end,2);
0078         else
0079             begin_times(c) = Inf;
0080             end_times(c) = -Inf;
0081         end
0082     end
0083     begin_time = min(begin_times);
0084     end_time = max(end_times);
0085     numtrials = ceil((end_time - begin_time)/120);
0086     window_times_list = begin_time:120:(begin_time+numtrials*120);
0087     window_times(:,1) = window_times_list(1:end-1);
0088     window_times(:,2) = window_times_list(2:end);
0089 end
0090 
0091 numplots = size(window_times,1);
0092 
0093 h = figure('position', [50 100 1280 720]);
0094 axh = cell(numplots,1);
0095 for n = 1:numplots
0096     axh{n,1} = axes();
0097     axh{n,1}.Position = [0.05, 0.75-.24*(n-1), 0.92, 0.21];
0098     ylim([0, numdata + numdata*space]);
0099     xlim([window_times(n,1) window_times(n,2)]);
0100     if n == 1
0101         if ~isempty(args.titlelabel)
0102             title(strrep(args.titlelabel, '_', '\_'));
0103         end
0104     end
0105 end
0106 
0107 label_pos = [];
0108 cont_colormap = [];
0109 for d = 1:numel(celldata)
0110     this_args = args;
0111     cev = celldata{d}; % cevent or cstream
0112     if ~isempty(cev)
0113         if isstruct(cev) && ~isempty(cev.data)
0114             this_args = cev.args;
0115             cev = cev.data;
0116         end
0117         if this_args.isCont
0118             cellcev = cont_extract_ranges(cev, window_times);
0119         else
0120             cellcev = event_extract_ranges(cev, window_times);
0121         end
0122         for c = 1:numel(cellcev)
0123             h.CurrentAxes = axh{c};
0124             cevpart = cellcev{c};
0125             if ~isempty(cevpart)
0126                 if this_args.isCont
0127                     cm_size = size(cont_colormap, 1);
0128                     cont_colormap = cat(1, cont_colormap, this_args.colors);
0129                     im = imagesc('CData', cevpart(:,2)'+cm_size, 'XData', cevpart(:,1), 'YData', bottom+.5);
0130                     im.CDataMapping = 'direct';
0131                 else
0132                     for i = 1:size(cevpart, 1)
0133                         tmp = cevpart(i,:);
0134                         width = tmp(2) - tmp(1);
0135                         if width > 0
0136                             r = rectangle('Position', [tmp(1), bottom, width, 1], 'facecolor', this_args.colors(tmp(3),:), 'edgecolor', 'none');
0137                             if this_args.draw_edge
0138                                 set(r, 'edgecolor', 'black', 'linewidth', 0.5);
0139                             end
0140                         end
0141                     end
0142                 end
0143             end
0144         end
0145     end
0146     
0147     label_pos = cat(2, label_pos, bottom + height/2);
0148     bottom = bottom + 1 + space;
0149 
0150 end
0151 colormap(cont_colormap);
0152 for n = 1:numplots
0153     h.CurrentAxes = axh{n};
0154     set(gca, 'ytick', label_pos);
0155     set(gca, 'yticklabel', streamlabels);
0156     set(gca, 'ticklength', [0 0])
0157 end
0158 p = pan(h);
0159 p.Motion = 'horizontal';
0160 z = zoom(h);
0161 z.Motion = 'horizontal';
0162 
0163 end

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005