Home > data-vis > vis_streams.m

vis_streams

PURPOSE ^

Plots visualized cstream or cevent data

SYNOPSIS ^

function h = vis_streams(subexpIDs, vars, labels, directory, setcolors, flag_edge, h)

DESCRIPTION ^

 Plots visualized cstream or cevent data

 subexpIDs : array of subject IDs or experiment IDs
 vars : cell array of variable names, cstreams, cevents and events only. Each element of this array is a row
 in the visualization plot.
 vars can also be a structure, for more control of how the data is represented.

       data.sub_list : array of subjects that correspond to data.data cell array
       data.data : cell array, 1 per subject, with each cell being Nx3 cevents
       data.colors : Nx3 matrix giving custom colormap for the cevent data
       data.edge : 1 or 0 indicating whether a solid black line borders the
           visualized cevents; 0 is recommended for continuous data that has
           been converted to cevents.
       data.box : 1 or 0 indicating whether to draw a larger box for the
           given data. This box will cover the entire subplot and is intended
           to represent meta-data.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function h = vis_streams(subexpIDs, vars, labels, directory, setcolors, flag_edge, h)
0002 % Plots visualized cstream or cevent data
0003 %
0004 % subexpIDs : array of subject IDs or experiment IDs
0005 % vars : cell array of variable names, cstreams, cevents and events only. Each element of this array is a row
0006 % in the visualization plot.
0007 % vars can also be a structure, for more control of how the data is represented.
0008 %
0009 %       data.sub_list : array of subjects that correspond to data.data cell array
0010 %       data.data : cell array, 1 per subject, with each cell being Nx3 cevents
0011 %       data.colors : Nx3 matrix giving custom colormap for the cevent data
0012 %       data.edge : 1 or 0 indicating whether a solid black line borders the
0013 %           visualized cevents; 0 is recommended for continuous data that has
0014 %           been converted to cevents.
0015 %       data.box : 1 or 0 indicating whether to draw a larger box for the
0016 %           given data. This box will cover the entire subplot and is intended
0017 %           to represent meta-data.
0018 
0019 if nargin == 1 && ischar(subexpIDs)
0020     switch subexpIDs
0021         case 'demo1'
0022             close all;
0023             subexpIDs = [7207];
0024             vars = {
0025                 'cstream_inhand_left-hand_obj-all_child'
0026                 'cstream_inhand_right-hand_obj-all_child'
0027                 'cstream_inhand_left-hand_obj-all_parent'
0028                 'cstream_inhand_right-hand_obj-all_parent'
0029                 'cstream_eye_roi_child'
0030                 'cstream_eye_roi_parent'
0031                 };
0032             labels = {'cl', 'cr', 'pl', 'pr', 'ceye', 'peye'};
0033             enableGUI = 1;
0034         case 'demo2'
0035             close all;
0036             subexpIDs = [7207];
0037             vars = {
0038                 'cstream_inhand_left-hand_obj-all_child'
0039                 'cstream_inhand_right-hand_obj-all_child'
0040                 'cstream_inhand_left-hand_obj-all_parent'
0041                 'cstream_inhand_right-hand_obj-all_parent'
0042                 'cstream_eye_roi_child'
0043                 'cstream_eye_roi_parent'
0044                 };
0045             labels = {'cl', 'cr', 'pl', 'pr', 'ceye', 'peye'};
0046             enableGUI = 1;
0047             camIDs = [];
0048     end
0049 end
0050 
0051 if ~exist('labels', 'var') || isempty(labels)
0052     labels = cell(1, numel(vars));
0053     for l = 1:numel(vars)
0054         labels{1,l} = num2str(l);
0055     end
0056 end
0057 
0058 if ~exist('flag_edge', 'var') || isempty(flag_edge)
0059     flag_edge = 1;
0060 end
0061 
0062 % if ~exist('enableGUI', 'var') || isempty(enableGUI)
0063 %     enableGUI = 0;
0064 % end
0065 
0066 vars = vars(end:-1:1);
0067 labels = labels(end:-1:1);
0068 
0069 height = 1;
0070 space = 0.03;
0071 
0072 % setcolors can be an Nx3 matrix, like colors above, or a scalar indicating
0073 % how many different colors you need
0074 if exist('setcolors', 'var') && ~isempty(setcolors)
0075     colors = set_colors(setcolors);
0076 else
0077     colors = set_colors();
0078 end
0079 
0080 labels = cellfun(@(a) strrep(a, '_', '\_'), labels, 'un', 0);
0081 
0082 subs = cIDs(subexpIDs);
0083 
0084 if ~exist('h', 'var') || isempty(h)
0085     h = figure('visible', 'on', 'position', [50 100 960 540]);
0086 end
0087 for s = 1:numel(subs)
0088     if ishghandle(h)
0089         figure(h);
0090         clf;
0091         bottom = 0;
0092         label_pos = [];
0093         numvars = numel(vars);
0094         for v = 1:numel(vars)
0095             if isstruct(vars{v})
0096                 if isfield(vars{v}, 'box') && vars{v}.box
0097                     numvars = numvars - 1;
0098                 end
0099             end
0100         end
0101         ex.individual_ranges = get_variable(subs(s), 'cevent_trials');
0102         for v = 1:numel(vars)
0103             % defaults
0104             tmpcolors = colors;
0105             flag_box = 0;
0106             
0107             if ischar(vars{v})
0108                 data = get_variable(subs(s), vars{v}, 1);
0109                 if isequal(data, false)
0110                     fprintf('%d : %s does not exist\n', subs(s), vars{v});
0111                 end
0112                 if vars{v}(1) == 'e'
0113                     data = cellfun(@(a) [a ones(size(a,1), 1)], data, 'un', 0);
0114                 end
0115             else % data was supplied, make sure it is partitioned into trials
0116                 datastr = vars{v};
0117                 if ischar(datastr.data)
0118                     data = get_variable(subs(s), datastr.data);
0119                     if datastr.data(1) == 'e'
0120                         data = cellfun(@(a) [a ones(size(a,1), 1)], data, 'un', 0);
0121                     end
0122                 else
0123                     log = datastr.sub_list == subs(s);
0124                     data = datastr.data{log};
0125                 end
0126                 if isfield(datastr, 'colors')
0127                     tmpcolors = datastr.colors;
0128                 end
0129                 if isfield(datastr, 'edge')
0130                     flag_edge = datastr.edge;
0131                 end
0132                 if isfield(datastr, 'box')
0133                     flag_box = datastr.box;
0134                 end
0135             end
0136             if ~isempty(data)
0137                 if ~iscell(data)
0138                     if size(data, 2) < 3
0139                         data = extract_ranges(data, 'cstream', ex.individual_ranges);
0140                     else
0141                         data = extract_ranges(data, 'cevent', ex.individual_ranges);
0142                     end
0143                 end
0144             end
0145             
0146             for c = 1:numel(data)
0147                 if ~isempty(data{c})
0148                     if size(data{c}, 2) < 3
0149                         cev = cstream2cevent(data{c});
0150                     else
0151                         cev = data{c};
0152                     end
0153                     
0154                     subplot(numel(data),1,c);
0155                     if ~isempty(cev)
0156                         xlim([ex.individual_ranges(c,1) ex.individual_ranges(c,2)]);
0157                         
0158                         for i = 1:size(cev, 1)
0159                             if ~isnan(cev(i,3))
0160                                 tmp = cev(i,:);
0161                                 width = tmp(2) - tmp(1);
0162                                 if width > 0
0163                                     r = rectangle('Position', [tmp(1), bottom, width, height], 'facecolor', tmpcolors(tmp(3),:), 'edgecolor', 'none');
0164                                     if flag_edge
0165                                         set(r, 'edgecolor', 'black', 'linewidth', 0.5);
0166                                     end
0167                                     if flag_box
0168                                         set(r, 'Position', [tmp(1), 0, width, (numvars + numvars*space)], 'facecolor', 'none', 'linewidth', 2.5, 'clipping', 'off');
0169                                     end
0170                                 end
0171                             end
0172                         end
0173                         
0174                     end
0175                 end
0176             end
0177             if ~flag_box
0178                 label_pos = cat(2, label_pos, bottom + height/2);
0179                 bottom = bottom + 1 + space;
0180             end
0181             
0182         end
0183         
0184         for p = 1:numel(data)
0185             subplot(numel(data),1,p);
0186             if p == 1
0187                 title(subs(s));
0188             end
0189             set(gca, 'position', [0.05, 0.75-.24*(p-1), 0.92, 0.21]);
0190             ylim([0, numvars + numvars*space]);
0191             set(gca, 'ytick', label_pos);
0192             set(gca, 'yticklabel', labels);
0193             set(gca, 'ticklength', [0 0])
0194         end
0195         
0196 %         mainpos = h.Position;
0197 %         b = figure('visible', 'on', 'position', [mainpos(1)+mainpos(3)+10 mainpos(2) 300 420]);
0198 %         m = figure('visible', 'on');
0199 %         if ~exist('camIDs', 'var')
0200 %             camIDs = [1 2];
0201 %         end
0202 %         load_frame_ui(h, b, m, subs(s), camIDs); % b is handle to frame figure
0203         
0204         if exist('directory', 'var') && ~isempty(directory)
0205             if ~exist(directory, 'dir')
0206                 error('%s does not exist as a directory\n', directory);
0207             end
0208             set(h, 'position', [100 100 1280 720]);
0209             export_fig(h, sprintf('%s/%d', directory, subs(s)), '-png', '-r90', '-a1', '-nocrop');
0210         else
0211             set(h, 'visible', 'on');
0212             if numel(subs) > 1
0213                 fprintf('Press any key to view next figure\n');
0214                 pause;
0215             end
0216         end
0217     end
0218 end

Generated on Tue 23-May-2017 02:00:59 by m2html © 2005