Home > data-import > make_inhand_activity.m

make_inhand_activity

PURPOSE ^

SYNOPSIS ^

function make_inhand_activity(subexpIDs)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function make_inhand_activity(subexpIDs)
0002 subs = cIDs(subexpIDs);
0003 agents = {'child', 'parent'};
0004 hands = {'left', 'right'};
0005 for s = 1:numel(subs)
0006     timebase = get_variable(subs(s), 'cstream_trials');
0007     for a = 1:numel(agents)
0008         agent = agents{a};
0009         for h = 1:2
0010             hand = hands{h};
0011             if has_variable(subs(s), sprintf('cont_motion_pos-speed_%s-hand_%s', hand, agent))
0012                 sub = subs(s);
0013                 gt = get_trial_times(sub);
0014                 data = get_variable(sub, sprintf('cont_motion_pos-speed_%s-hand_%s', hand, agent));
0015                 param.threshold = 150;
0016                 param.flag = 'above';
0017                 active = cont2event(data, param);
0018                 active(:,3) = 1;
0019                 active = cevent_merge_segments(active, 0.5);
0020                 log = active(:,2)- active(:,1) < 0.5;
0021                 active(log,:) = [];
0022                 active = active(:,[1 2]);
0023                 record_variable(sub, sprintf('event_motion_pos_%s-hand_active_%s', hand, agent), active);
0024                 
0025                 param.threshold = 50;
0026                 passive = cont2event(data, param);
0027                 passive(:,3) = 1;
0028                 passive = cevent_merge_segments(passive, 0.5);
0029                 active_not = event_NOT(active, [gt(1) gt(end)]);
0030                 passive = extract_ranges(passive, 'event', active_not);
0031                 passive = vertcat(passive{:});
0032                 passive = sortrows(passive, [1 2]);
0033                 log = passive(:,2) - passive(:,1) < 0.5;
0034                 passive(log,:) = [];
0035                 passive = passive(:,[1 2]);
0036                 record_variable(sub, sprintf('event_motion_pos_%s-hand_passive_%s', hand, agent), passive);
0037                 
0038                 resting = event_NOT(passive, [gt(1) gt(end)]);
0039                 resting = event_AND(resting, active_not);
0040                 
0041                 record_variable(sub, sprintf('event_motion_pos_%s-hand_resting_%s', hand, agent), resting);
0042                 
0043                 inhand = get_variable(sub, sprintf('cstream_inhand_%s-hand_obj-all_%s', hand, agent));
0044                 
0045                 cev = cstream2cevent(inhand);
0046                 inhand = cevent2cstreamtb(cev, timebase);
0047 %                 cevinhand = cstream2cevent(inhand);
0048 %                 cevinhand = cevent_merge_segments(cevinhand, 0.1);
0049 %                 log = cevinhand(:,2) - cevinhand(:,1) < 0.1;
0050 %                 cevinhand(log,:) = [];
0051 %                 cevinhand = cevent_merge_segments(cevinhand, 0.1);
0052 %                 inhand = cevent2cstreamtb(cevinhand, inhand);
0053                 activity_inhand = inhand;
0054                 active_inhand = inhand;
0055                 passive_inhand = inhand;
0056                 resting_inhand = inhand;
0057                 
0058                 log = inhand(:,2) > 0;
0059                 log1 = mark_ranges(activity_inhand, active) & log;
0060                 log2 = mark_ranges(activity_inhand, passive) & log;
0061                 log3 = mark_ranges(activity_inhand, resting) & log;
0062                 
0063                 activity_inhand(log1,2) = 3; % active
0064                 activity_inhand(log2,2) = 2; % passive
0065                 activity_inhand(log3,2) = 1; % resting
0066                 
0067                 record_variable(sub, sprintf('cstream_motion-inhand_%s-hand_all_%s', hand, agent), activity_inhand);
0068 %                 cev = cstream2cevent(activity_inhand);
0069 %                 record_variable(sub, sprintf('cevent_motion-inhand_%s-hand_all_%s', hand, agent), cev);
0070                 
0071                 log = mark_ranges(active_inhand, active);
0072                 active_inhand(~log, 2) = 0;
0073                 
0074                 log = mark_ranges(passive_inhand, passive);
0075                 passive_inhand(~log, 2) = 0;
0076                 log = mark_ranges(resting_inhand, resting);
0077                 resting_inhand(~log, 2) = 0;
0078                 
0079                 record_variable(sub, sprintf('cstream_motion-inhand_%s-hand_active_%s', hand, agent), active_inhand);
0080 %                 cev = cstream2cevent(active_inhand);
0081 %                 record_variable(sub, sprintf('cevent_motion-inhand_%s-hand_active_%s', hand, agent), cev);
0082                 
0083                 record_variable(sub, sprintf('cstream_motion-inhand_%s-hand_passive_%s', hand, agent), passive_inhand);
0084 %                 cev = cstream2cevent(passive_inhand);
0085 %                 record_variable(sub, sprintf('cevent_motion-inhand_%s-hand_passive_%s', hand, agent), cev);
0086                 
0087                 record_variable(sub, sprintf('cstream_motion-inhand_%s-hand_resting_%s', hand, agent), resting_inhand);
0088 %                 cev = cstream2cevent(resting_inhand);
0089 %                 record_variable(sub, sprintf('cevent_motion-inhand_%s-hand_resting_%s', hand, agent), cev);
0090  
0091             end        
0092         end
0093     end
0094 end
0095 
0096 
0097 for s = 1:numel(subs)
0098     sub = subs(s);
0099     timebase = get_variable(sub, 'cstream_trials');
0100     for a = 1:2
0101         agent = agents{a};
0102         dl = get_variable(sub, sprintf('cstream_motion-inhand_left-hand_all_%s', agent), 1);
0103         dr = get_variable(sub, sprintf('cstream_motion-inhand_right-hand_all_%s', agent), 1);
0104         hl = get_variable(sub, sprintf('cstream_inhand_left-hand_obj-all_%s', agent), 1);
0105         cev = cstream2cevent(hl);
0106         hl = cevent2cstreamtb(cev, timebase);
0107         hr = get_variable(sub, sprintf('cstream_inhand_right-hand_obj-all_%s', agent), 1);
0108         cev = cstream2cevent(hr);
0109         hr = cevent2cstreamtb(cev, timebase);
0110         if ~isempty(dl) && ~isempty(dr)
0111             both = cat(2, dl(:,2), dr(:,2));
0112             objid = cat(2, hl(:,2), hr(:,2));
0113             [maxact, idx] = max(both, [], 2);
0114             log = idx == 2;
0115             targobj = zeros(length(log),1);
0116             mapping = targobj;
0117             targobj(log) = objid(log,2);
0118             log = idx == 1;
0119             targobj(log) = objid(log, 1);
0120             log = maxact > 0 & targobj > 0;
0121             mapping(log) = sub2ind([3 3], maxact(log), targobj(log));
0122             cst = cat(2,dl(:,1), mapping);
0123             cev = cstream2cevent(cst);
0124             cev = cevent_merge_segments(cev, .1);
0125             log = cev(:,2) - cev(:,1) <.1;
0126             cev(log,:) = [];
0127             cev = cevent_merge_segments(cev, .1);
0128             cst = cevent2cstreamtb(cev, timebase);
0129             record_variable(sub, sprintf('cstream_motion-inhand_either-hand_all_%s', agent), cst);
0130             record_variable(sub, sprintf('cevent_motion-inhand_either-hand_all_%s', agent), cev);
0131             
0132             log = ismember(cev(:,3), [3 6 9]);
0133             cev = cev(log,:);
0134             cev(:,3) = cev(:,3) / 3;
0135             record_variable(sub, sprintf('cevent_motion-inhand_either-hand_active_%s', agent), cev);
0136             log = ismember(cst(:,2), [3 6 9]);
0137             cst(~log,2) = 0;
0138             cst(:,2) = cst(:,2) / 3;
0139             record_variable(sub, sprintf('cstream_motion-inhand_either-hand_active_%s', agent), cst);
0140         end
0141     end
0142 end

Generated on Tue 23-May-2017 03:00:58 by m2html © 2005