0001 function outdata = ensemble_physio_adjust(indata,params)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 if (iscell(indata) && ~isempty(indata) && ...
0033 isfield(indata{1},'task') && ...
0034 ~isempty(strmatch('return_outdir',indata{1}.task))) || ...
0035 (isstruct(indata) && isfield(indata,'task') && ...
0036 ~isempty(strmatch('return_outdir',indata.task)))
0037 outdata = '';
0038 return
0039 elseif ~isstruct(params) || ...
0040 ~isfield(params,'ensemble_jobman_interactive') ...
0041 || ~params.ensemble_jobman_interactive
0042 outdata = '';
0043 error('please run within an interactive session');
0044 end
0045
0046 outdata = ensemble_init_data_struct();
0047
0048 global r
0049
0050 r = init_results_struct;
0051
0052 r.type = 'physio_summ';
0053 r.report_on_fly = 1;
0054
0055
0056 if isstruct(indata), indata = {indata}; end
0057
0058 try masdp = params.manual_adjust_signal_data; catch masdp = struct(); end
0059
0060
0061 for in=1:length(indata)
0062
0063 if isfield(indata{in},'type')
0064 switch indata{in}.type
0065 case {'gsr_epoch','cardiac_epoch','gsr_epochs','cardiac_epochs'}
0066
0067 data = indata{in};
0068 cols = set_var_col_const(data.vars);
0069
0070
0071 if ~isfield(cols,'signal')
0072 warning('no signal variable for indata %d, SKIPPING',in);
0073 continue
0074 else
0075 signals = data.data{cols.signal};
0076 ne = length(signals);
0077 end
0078
0079 if isfield(cols,'srate')
0080 srates = data.data{cols.srate};
0081 elseif ~isfield(params,'srate')
0082 srates = repmat(params.srate,ne,1);
0083 else
0084 warning('no sampling rate for indata %d, SKIPPING',in);
0085 continue
0086 end
0087
0088 if isfield(cols,'pidxs')
0089 peaks = data.data{cols.pidxs};
0090 pcol = 'pidxs';
0091 elseif isfield(cols,'peakidxs')
0092 peaks = data.data{cols.peakidxs};
0093 pcol = 'peakidxs';
0094 else
0095 peaks = cell(ne,1);
0096 pcol = '';
0097 end
0098
0099 if ~isfield(cols,'subject_id')
0100 warning('no subject info in indata %d',in);
0101 subids = [];
0102 else
0103 subids = data.data{cols.subject_id};
0104 end
0105
0106
0107 for ie=1:ne
0108
0109 masdp.samplingRate = srates(ie);
0110 if ~isempty(subids)
0111 vars = {sprintf('subject: %s, epoch %1.0f',subids{ie},ie)};
0112 else
0113 vars = {sprintf('epoch %1.0f',ie)};
0114 end
0115
0116
0117 [lsig,lpeaks] = manual_adjust_signal_data('signal',signals{ie},...
0118 'peaks',peaks(ie),'params',masdp,'vars',vars);
0119
0120
0121 data.data{cols.signal}{ie} = lsig;
0122 if ~isempty(pcol)
0123 data.data{cols.(pcol)}{ie} = lpeaks;
0124 end
0125 end
0126
0127 outdata.vars = [outdata.vars data.type];
0128 outdata.data = [outdata.data data];
0129 case {'physio_paths'}
0130 warning('this option is not yet supported, SKIPPING');
0131 otherwise
0132 warning('unknown type %s, SKIPPING',indata{in}.type);
0133 end
0134 end
0135 end