Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify function output #689

Merged
merged 37 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5e40e47
modify pspm_combine_markerchannels
Apr 12, 2024
a803376
modify pspm_convert_au2unit and pspm_convert_area2diameter
Apr 12, 2024
9b391cc
fix pspm_load_channel
Apr 12, 2024
cb6813c
modify pspm_convert_hb2hp
Apr 12, 2024
9e5d630
modify pspm_convert_ppg2hb & pspm_emg_pp
Apr 12, 2024
2608a84
modify pspm_find_sounds
Apr 12, 2024
3ecf795
modify pspm_pupil_correct_eyelink
Apr 13, 2024
25345c1
modify pspm_resp_pp
Apr 13, 2024
545af94
modify pspm_scr_pp
Apr 13, 2024
d69277b
modify pspm_pp
Apr 13, 2024
5e973c7
modify pspm_merge
Apr 14, 2024
48a9edb
modify pspm_split_sessions
Apr 14, 2024
9d62414
modify pspm_remove_epochs
Apr 14, 2024
8b092c1
modify pspm_trim
Apr 15, 2024
afc20b9
modify pspm_import
Apr 16, 2024
ffe2f70
modify pspm_dcm
Apr 16, 2024
ae4a435
modify pspm_dcm_inv
Apr 16, 2024
ba1d6ff
modify pspm_glm
Apr 16, 2024
91d3fca
remove varargout in pspm_sf_... and pspm_transfer_function
Apr 16, 2024
72eaf15
modify pspm_version
Apr 16, 2024
06bad35
fixes after testing
Apr 18, 2024
cb29ec1
fixes after testing
Apr 18, 2024
31618c4
Merge branch 'develop' into unify-function-output
teddychao Apr 19, 2024
f2225b9
Merge branch 'develop' into unify-function-output
dominikbach Apr 19, 2024
c88cca3
modify pspm_interpolate
Apr 19, 2024
94cfdc8
improve pspm_select_channels
Apr 19, 2024
109035e
test fix
Apr 19, 2024
6b9c365
test fix
Apr 19, 2024
2dbd2fb
remove comment numbering in pspm_check_data
May 14, 2024
4969a2b
fix pspm_cfg_rename
May 14, 2024
ef8241b
fix pspm_cfg_find_sounds
May 15, 2024
b7fdc3e
Merge branch 'develop' into unify-function-output
dominikbach May 20, 2024
5a8a12b
fix pspm_version and GUI for pspm_merge
May 21, 2024
bd999ac
fix pspm_rename and GUI item
May 21, 2024
9f8a9b4
improve test for gaze_convert
May 21, 2024
74ceee8
Merge branch 'unify-function-output' of github.com:bachlab/PsPM into …
May 21, 2024
17e42f1
fix test for pspm_rename
May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 27 additions & 35 deletions src/pspm_cfg/pspm_cfg_find_sounds.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,6 @@
roi.help = {['Region of interest for discovering sounds. ', ...
'Only sounds between the 2 timestamps will be considered.']};

%% Channel action
chan_action = cfg_menu;
chan_action.name = 'Channel action';
chan_action.tag = 'channel_action';
chan_action.val = {'replace'};
chan_action.values = {'add', 'replace'};
chan_action.labels = {'add', 'replace'};
chan_action.help = {['Add will append the new marker channel as ', ...
'additional channel to the specified PsPM file. Replace will ', ...
'overwrite the last marker channel of the PsPM file ', ...
'(be careful with reference markers).']};

%% Create Channel
new_chan = cfg_branch;
new_chan.name = 'Create Channel';
new_chan.tag = 'create_chan';
new_chan.val = {chan_action};
new_chan.help = {['The new data channel contains by default all ', ...
'marker onsets found in the specified data file. If you want ', ...
'specific sounds defined by a marker, use the diagnostics option.']};

%% Text only
text_only = cfg_const;
Expand Down Expand Up @@ -112,19 +92,19 @@
no.help = {''};

%% yes
yes = cfg_branch;
yes = cfg_const;
yes.name = 'Yes';
yes.tag = 'yes';
yes.val = {chan_action};
yes.val = {1};
yes.help = {''};

%% New corrected channel
new_corrected_chan = cfg_choice;
new_corrected_chan.name = 'Create channel with specific sounds';
new_corrected_chan.name = 'Output specific sounds only';
new_corrected_chan.tag = 'create_corrected_chan';
new_corrected_chan.val = {no};
new_corrected_chan.values = {no, yes};
new_corrected_chan.help = {['Create new data channel which contains ', ...
new_corrected_chan.help = {['By default, all sounds are outputted. Choose ''yes'' here to create new data channel which contains ', ...
'only marker onsets which could have been assigned to a ', ...
'marker in the specified marker channel.']};

Expand Down Expand Up @@ -162,28 +142,40 @@
'If too few sounds are found, threshold is lowered until specified ', ...
'count is reached.']};

%% Diagnostics: which ones?
diag_yes = cfg_branch;
diag_yes.name = 'Yes';
diag_yes.tag = 'diagnostics';
diag_yes.val = {diag_output, new_corrected_chan, marker_chan, max_delay, ...
min_delay, n_sounds};
diag_yes.help = {};

%% Diagnostics
diagnostic = cfg_branch;
diagnostic = cfg_choice;
diagnostic.name = 'Diagnostic';
diagnostic.tag = 'diagnostic';
diagnostic.val = {diag_output, new_corrected_chan, marker_chan, max_delay, ...
min_delay, n_sounds};
diagnostic.val = {no};
diagnostic.values = {diag_yes, no};
diagnostic.help = {['Analyze delays between existing marker channel ', ...
'and detected sound onsets.']};

%% Output
output = cfg_choice;
output.name = 'Output';
output.tag = 'output';
output.val = {new_chan};
output.values = {new_chan, diagnostic};
output.help = {''};
%% Channel action
chan_action = cfg_menu;
chan_action.name = 'Channel action';
chan_action.tag = 'channel_action';
chan_action.val = {'add'};
chan_action.values = {'add', 'replace'};
chan_action.labels = {'add', 'replace'};
chan_action.help = {['Add will append the new marker channel as ', ...
'additional channel to the specified PsPM file. Replace will ', ...
'overwrite the last marker channel of the PsPM file ', ...
'(be careful with reference markers).']};

%% Executable branch
find_sounds = cfg_exbranch;
find_sounds.name = 'Find startle sound onsets';
find_sounds.tag = 'find_sounds';
find_sounds.val = {datafile, chan, threshold, roi, output};
find_sounds.val = {datafile, chan, threshold, roi, diagnostic, chan_action};
find_sounds.prog = @pspm_cfg_run_find_sounds;
find_sounds.vout = @pspm_cfg_vout_find_sounds;
find_sounds.help = {['Translate continuous sound data into an event marker ', ...
Expand Down
29 changes: 12 additions & 17 deletions src/pspm_cfg/pspm_cfg_merge.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@

%% First file
first_file = cfg_files;
first_file.name = 'First file(s)';
first_file.name = 'First file';
first_file.tag = 'first_file';
first_file.num = [1 Inf];
first_file.num = [1 1];
first_file.help = {['Specify the first of the two files to be ', ...
'merged. This can be one file or a set of files. The output file ', ...
'merged. The output file ', ...
'will have the name of the first file prepended with an ''m''.'],...
' ',settings.datafilehelp};

%% Second file
second_file = cfg_files;
second_file.name = 'Second file(s)';
second_file.name = 'Second file';
second_file.tag = 'second_file';
second_file.num = [1 Inf];
second_file.help = {['Specify the second of the two files to be merged. ', ...
'This can be one file or a set of files. This set must have the same ', ...
'length as the set defined as first file(s).'],' ',settings.datafilehelp};
second_file.num = [1 1];
second_file.help = {['Specify the second of the two files to be merged. '], ...
' ', settings.datafilehelp};

%% Data files
datafiles = cfg_branch;
Expand Down Expand Up @@ -66,8 +65,8 @@
marker_chan.val = {[0 0]};
marker_chan.num = [1 2];
marker_chan.strtype = 'i';
marker_chan.help = {['Specify for each file (first and second) a ', ...
'channel which should be used as marker reference. A 1x2 vector is ', ...
marker_chan.help = {['Specify for both files a numerical ', ...
'channel index, which should be used as marker reference. A 1x2 vector is ', ...
'expected. If equal to 0, the first marker channel is used. ', ...
'Default: [0 0]']};

Expand All @@ -86,14 +85,10 @@
merge.prog = @pspm_cfg_run_merge;
merge.vout = @pspm_cfg_vout_merge;
merge.help = {['Allows to merge (i.e. stack) two files that were acquired ', ...
'simultaneously but contain different channels. Multiple files are ', ...
'allowed and are processed in a sequential manner. This means the ', ...
'first element of second set of files is merged into the first ', ...
'element of first set of files and so on. Therefore first set and ', ...
'second set must have the same number of elements. The files are ', ...
'simultaneously but contain different channels. The files are ', ...
'aligned according to the first event of a given marker channel or ', ...
'to the start of the file. The output file consists of an ''m'' at ', ...
'the beginning and the name of the first file appended. ']};
'to the start of the file. The output file name consists of an ''m'' ', ...
'prepended to the name of the first file. ']};

function vout = pspm_cfg_vout_merge(job)
vout = cfg_dep;
Expand Down
5 changes: 2 additions & 3 deletions src/pspm_cfg/pspm_cfg_pp_scr.m
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,9 @@
scr_pp_options.channel_action = job.chan_action;
[sts, output] = pspm_scr_pp(scr_pp_datafile, scr_pp_options);
if sts == 1
% out = {output.channel};
out = output{1};
out = output;
else
out = {-1};
out = -1;
end
end

Expand Down
12 changes: 3 additions & 9 deletions src/pspm_cfg/pspm_cfg_rename.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
filename.name = 'File Name';
filename.tag = 'filename';
filename.num = [1 1];
%filename.filter = '\.mat$';
filename.filter = '\.mat$';
filename.help = {'Choose name of original file.'};

newfilename = cfg_entry;
newfilename.name = 'New File Name';
newfilename.tag = 'newfilename';
newfilename.strtype = 's';
%newfilename.num = [1 1];
newfilename.num = [1 inf];
newfilename.help = {''};

file = cfg_branch;
Expand All @@ -24,17 +24,11 @@
file.val = {filename,newfilename};
file.help = {''};

rename_file = cfg_repeat;
rename_file.name = 'Rename';
rename_file.tag = 'rename_file';
rename_file.values = {file};
rename_file.help = {'Choose how many files to rename.'};

%% Executable branch
rename = cfg_exbranch;
rename.name = 'Rename File';
rename.tag = 'rename';
rename.val = {rename_file};
rename.val = {filename, newfilename};
rename.prog = @pspm_cfg_run_rename;
rename.vout = @pspm_cfg_vout_rename;
rename.help = {'Rename PsPM data file. This renames the file and updates the file information.'};
Expand Down
13 changes: 2 additions & 11 deletions src/pspm_cfg/pspm_cfg_run_dcm.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,5 @@
if eventnameflag
options.eventnames = eventnames;
end
[varargout] = pspm_dcm(model, options);
if numel(varargout) < 2
out = varargout;
dcm = [];
else
out = varargout{1};
dcm = varargout{2};
end
if ~iscell(out)
out = {out};
end
[out, dcm] = pspm_dcm(model, options);

26 changes: 5 additions & 21 deletions src/pspm_cfg/pspm_cfg_run_find_sounds.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,13 @@
options.roi = job.roi.region;
end
options = pspm_update_struct(options, job, 'threshold');
options.channel_action = 'none';
f = fieldnames(job.output);
switch f{1}
case 'create_chan'
options.diagnostics = false;
options = pspm_update_struct(options, job.output.create_chan, 'channel_action');
[sts, infos] = pspm_find_sounds(file, options);
if sts == 1
out = infos.channel;
else
out = 0;
end
case 'diagnostic'
d = job.output.diagnostic;
if isfield(job.diagnostic, 'diagnostics')
d = job.diagnostic.diagnostics;
if isfield(d.create_corrected_chan, 'yes')
options = pspm_update_struct(options, d.create_corrected_chan.yes, 'channel_action');
options.channel_output = 'corrected';
options.channel_output = 'corrected';
end
options.marker_chan_num = pspm_cfg_channel_selector('run', d.chan);
if job.output.diagnostic.n_sounds > 0
if d.n_sounds > 0
options.expectedSoundCount = job.output.diagnostic.n_sounds;
end
options.maxdelay = d.max_delay;
Expand All @@ -38,8 +25,5 @@
case 'text_only'
options.plot = false;
end
[~, infos] = pspm_find_sounds(file, options);
if isfield(infos, 'channel')
out = infos.channel;
end
[~, out, infos] = pspm_find_sounds(file, options);
end
2 changes: 1 addition & 1 deletion src/pspm_cfg/pspm_cfg_run_import.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@
end
options = struct();
options = pspm_update_struct(options, job, 'overwrite');
out = pspm_import(datafiles, datatype, import, options);
[sts, out] = pspm_import(datafiles, datatype, import, options);
10 changes: 3 additions & 7 deletions src/pspm_cfg/pspm_cfg_run_merge.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function [out] = pspm_cfg_run_merge(job)
% Updated on 08-01-2024 by Teddy
% load input files
infile1 = job.datafiles.first_file;
infile2 = job.datafiles.second_file;
infile1 = job.datafiles.first_file{1};
infile2 = job.datafiles.second_file{1};
% set reference
ref = job.reference;
options = struct();
Expand All @@ -12,8 +12,4 @@
options.marker_chan_num = job.options.marker_chan;
end
% run merge
[out] = pspm_merge(infile1, infile2, ref, options);
% ensure output is always a cell
if ~iscell(out)
out = {out};
end
[sts, out] = pspm_merge(infile1, infile2, ref, options);
4 changes: 2 additions & 2 deletions src/pspm_cfg/pspm_cfg_run_pp_emg_data.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
options.mains_freq = job.options(1).mains_freq;
options.channel_action = job.options(1).chan_action;
options.channel = pspm_cfg_channel_selector('run', job.options(1).chan);
[sts, output] = pspm_emg_pp(job.datafile{1}, options);
[sts, outchannel] = pspm_emg_pp(job.datafile{1}, options);
if sts == 1
out = {output.channel};
out = {outchannel};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw other functions, such as pspm_cfg_run_merge has removed out={out} if it is not a cell. I am not sure if this is still necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GUI dependencies will be updated in a future PR.

else
out = {-1};
end
16 changes: 8 additions & 8 deletions src/pspm_cfg/pspm_cfg_run_pp_heart_data.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
{'semi', 'twthresh'});
options = pspm_update_struct(options, job, 'channel_action');
% call function
[sts, winfo] = pspm_convert_ecg2hb(fn, options);
[sts, outchannel] = pspm_convert_ecg2hb(fn, options);
case 'ecg2hb_amri'
options = pp_field.opt;
options.channel = chan;
options = pspm_update_struct(options, job, 'channel_action');
winfo = struct();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this line can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

[sts, winfo.channel] = pspm_convert_ecg2hb_amri(fn, options);
[sts, outchannel] = pspm_convert_ecg2hb_amri(fn, options);
case 'hb2hp'
sr = job.pp_type{i}.hb2hp.sr;
options = struct();
options.channel = chan;
options.limit = job.pp_type{i}.hb2hp.limit;
options = pspm_update_struct(options, job, 'channel_action');
[sts, winfo] = pspm_convert_hb2hp(fn, sr, options);
[sts, outchannel] = pspm_convert_hb2hp(fn, sr, options);
case 'ecg2hp'
sr = job.pp_type{i}.ecg2hp.sr;
% copy options
Expand All @@ -51,16 +51,16 @@
options = pspm_update_struct(options, job, {'channel_action'});
options.channel = chan;
% call ecg2hb
[sts, winfo] = pspm_convert_ecg2hb(fn, options);
[sts, outchannel] = pspm_convert_ecg2hb(fn, options);
if sts ~= -1
% replace channel
options.channel_action = 'replace';
options = pspm_update_struct(options, ...
job.pp_type{i}.ecg2hp, ...
'limit');
options.channel = winfo.channel;
options.channel = outchannel;
% call ecg2hp
[sts, winfo] = pspm_convert_hb2hp(fn, sr, options);
[sts, outchannel] = pspm_convert_hb2hp(fn, sr, options);
end
case 'ppg2hb'
options = struct();
Expand All @@ -73,10 +73,10 @@
end
options.channel = chan;
options = pspm_update_struct(options, job, {'channel_action'});
[sts, winfo] = pspm_convert_ppg2hb(fn, options);
[sts, outchannel] = pspm_convert_ppg2hb(fn, options);
end
if sts ~= -1
outputs{i} = winfo.channel;
outputs{i} = outchannel;
else
outputs{i} = [];
warning('Error occured during conversion. Could not finish correctly.');
Expand Down
11 changes: 3 additions & 8 deletions src/pspm_cfg/pspm_cfg_run_rename.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
function out = pspm_cfg_run_rename(job)
% Updated on 08-01-2024 by Teddy
n = size(job.file,2);
filename = cell(n,1);
newfilename = cell(1,n);
for i = 1:n
filename{i} = job.file(i).filename{1};
newfilename{i} = job.file(i).newfilename;
end
out = pspm_ren(filename, newfilename);
filename = job.filename{1};
newfilename = job.newfilename;
[sts, out] = pspm_rename(filename, newfilename);
if ~iscell(out)
out = {out};
end
6 changes: 2 additions & 4 deletions src/pspm_cfg/pspm_cfg_run_trim.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@
if ~isfield(options,'marker_chan_num')
options.marker_chan_num = 0; % Default value
end
out = pspm_trim(job.datafile, from, to, ref, options);
if ~iscell(out)
out = {out};
end
[sts, out] = pspm_trim(job.datafile{1}, from, to, ref, options);

Loading
Loading