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

Unify function output #689

merged 37 commits into from May 21, 2024

Conversation

dominikbach
Copy link
Contributor

@dominikbach dominikbach commented Apr 17, 2024

Fixes #624. Fixes #519. Fixes #421.

Changes proposed in this pull request:

  1. Functions that write data into channels always return [sts, channel_index] and potentially further output arguments.
  2. Functions that create new files always return [sts, newfilename] and potentially further output arguments.
  3. Functions always work on one data file only unless explicitly designed to work on multiple files (such as pspm_exp).
  4. pspm_write_channel is always called with an index of the channels that were used to create the new channel data. pspm_write_channel will then check whether these channels will be overwritten (if action is replace and the channels have the same type and units) or whether new channels are created.
  5. varargout was removed wherever possible. Some widely used helper functions remain (e.g. pspm_overwrite and pspm_prepdata) and will be addressed in new pull requests.
  6. GUIs and tests were changed accordingly.
  7. Some inconsistencies remain in cfg_run functions and will be addressed in new PR.

Summaries:

Function output was changed:

pspm_combine_markerchannels
pos_of_channel
pspm_convert_au2unit
pspm_convert_ecg2hb
pspm_convert_hb2hp
pspm_convert_ppg2hb
pspm_emg_pp
pspm_find_sounds
pspm_resp_pp
pspm_scr_pp
pspm_pp
pspm_ren
pspm_remove_epochs
pspm_import
pspm_trim
pspm_glm
pspm_interpolate

Write channel behaviour changed

pspm_convert_au2unit
pspm_convert_gaze
pspm_pupil_correct_eyelink
pspm_pupil_pp
pspm_scr_pp
pspm_remove_epochs

Option to work on multiple files removed

pspm_scr_pp
pspm_merge
pspm_trim
pspm_import

Varargout removed

pspm_merge
pspm_split_sessions
pspm_ren
pspm_trim
pspm_dcm
pspm_glm_recon
pspm_sf
pspm_sf_auc
pspm_sf_dcm
pspm_sf_mp
pspm_sf_scl
pspm_transfer_function
pspm_version
pspm_write_channel

Function output unchanged

pspm_convert_ecg2hb_amri
pspm_pupil_correct_eyelink
pspm_pupil_pp

Bugs fixed

pspm_load_channel

Other changes

  • pspm_ren was renamed to pspm_rename for enhanced transparency
  • pspm_rename now uses pspm_load_data to save data and checks whether new file already exists, via options.overwrite
  • improved pspm_write_channel, now uses pspm_select_channels for checks
  • new function pspm_check_data, used in pspm_load_data and pspm_write_channel
  • improved pspm_select_channels

@dominikbach dominikbach added the In Progress Currently being worked on label Apr 17, 2024
@dominikbach dominikbach self-assigned this Apr 19, 2024
@dominikbach dominikbach added Completed & Waiting for Review Completed and waiting for review and removed In Progress Currently being worked on labels Apr 19, 2024
@teddychao
Copy link
Contributor

teddychao commented Apr 19, 2024 via email

Copy link
Contributor

@teddychao teddychao left a comment

Choose a reason for hiding this comment

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

I have reviewed some functions.. I try to finish them in these two days.

src/pspm_check_data.m Outdated Show resolved Hide resolved
src/pspm_cfg/pspm_cfg_merge.m Outdated Show resolved Hide resolved
src/pspm_cfg/pspm_cfg_rename.m Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

The Line 24--27 may not work as fully expected, because the channel action does not have a fallback. Users cannot avoid creating a channel. To fix this, I suggest to change line 24--27 to be

if isfield(d.create_corrected_chan, 'yes')
  options.channel_action = 'add';
  options.channel_output = 'corrected';
else
  options.channel_action = 'none';
end

And in pspm_options, it should be modified in line 217, to be

options = autofill_channel_action(options,            'add',     {'replace', 'none'} );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new design is to always create a channel (i.e. never give the GUI user the option not to). But this was incorrectly implemented in the GUI. It should be fixed now.

src/pspm_sf_mp.m Show resolved Hide resolved
src/pspm_pupil_correct_eyelink.m Show resolved Hide resolved
infos = cell(2,1);
data = cell(2,1);
for iNum = 1:2
[sts_load_data, infos, data] = pspm_load_data(infile{iNum});
Copy link
Contributor

Choose a reason for hiding this comment

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

This line does not seem to be right. I run the data with the GUI's merge feature, and the variable fn cannot be identified correctly. This is because the input is a cell instead of a string.
Screenshot 2024-05-13 at 14 39 33

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for spotting this; pspm_cfg_run_merge is fixed now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure this file is working. I checked and saw it reported error when I tried to rename a file. The job.file did not exist in this occasion. My understanding of what has been updated to pspm_cfg_run_merge is to make it consistent to the output from other functions, so it is not expecting to change the functionality of "rename". Maybe you could have a look and see if any unexpected update has caused this issue?
Screenshot 2024-05-13 at 15 01 47

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, this is fixed now.

@@ -1,26 +1,29 @@
function sts = pspm_combine_markerchannels(datafile, options)
function [sts, outchannel] = pspm_combine_markerchannels(datafile, options)
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be useful to update pspm_cfg_run_combine_markerchannels and add output at its line 11. Similarly, for pspm_combine_markerchannels_test, the lines 22, 28, 48, 66 may need to be updated to add the output.

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 & tests will be updated in future PR, no change required for now.

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.

@@ -82,30 +75,16 @@ function scr_pp_test_missing(this, channels)
'deflection_threshold', 0, ...
'expand_epochs', 0, ...
'channel_action', 'add');
options6 = struct('change_data', 0);
% Verifying the situation with missing epochs filename option without
% saving to datafile
pspm_testdata_gen(channels, this.duration, this.fn);
[~, out] = pspm_scr_pp(this.fn, options4);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think for the test here, options4 shall include the channel_action, in this case shall be set to be none or withdraw. If not set, this channel_action will use the default fallback, which is add. It is better to sort it to be none which means the processed data will not be saved to the original file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests can be updated later.

% ● Description
% pspm_convert_ecg2hb identifies the position of QRS complexes in ECG data and
% writes them as heart beat channel into the datafile. This function
% implements the algorithm by Pan & Tompkins (1985) with some adjustments.
% ● Format
% sts = pspm_convert_ecg2hb(fn, options)
% [sts, channel_index, quality_info] = pspm_convert_ecg2hb(fn, options)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it is useful to say outchannel and debug_info here, since they are named in the code..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stylistic issue, no change required.

@@ -9,8 +9,8 @@
% it will either replace an existing heartbeat channel or add it as a new
% channel to the provided file.
% ● Format
% [sts, out_channel] = pspm_convert_ecg2hb_amri(fn)
% [sts, out_channel] = pspm_convert_ecg2hb_amri(fn, options)
% [sts, channel_index] = pspm_convert_ecg2hb_amri(fn)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, both channel_index and out_channel can be used, but better to choose one of them and rename the variables to it...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just stylistic.

src/pspm_convert_au2unit.m Show resolved Hide resolved
src/pspm_convert_hb2hp.m Show resolved Hide resolved
src/pspm_convert_ppg2hb.m Show resolved Hide resolved
this.fn = pspm_import(this.raw_input_filename, 'eyelink', import, options);
this.fn = this.fn{1};
[sts, this.fn] = pspm_import(this.raw_input_filename, 'eyelink', import, options);
this.fn = this.fn;
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 just deleted...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -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.

?

% ● Description
% pspm_find_sounds finds and if required analyzes sound events in a pspm file.
% A sound is accepted as event if it is longer than 10 ms and events are
% recognized as different if they are at least 50 ms appart.
% ● Format
% [sts, infos] = pspm_find_sounds(file,options)
% [sts, channel_index, info] = pspm_find_sounds(fn, options)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe consistent variable naming is required here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just stylistic.

src/pspm_find_sounds.m Show resolved Hide resolved
@dominikbach dominikbach merged commit 7ccbf06 into develop May 21, 2024
1 check passed
@dominikbach dominikbach deleted the unify-function-output branch May 21, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Completed & Waiting for Review Completed and waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve pspm_write_channel Streamline function output pspm_write_channel variable assignment
2 participants