Skip to content

Commit

Permalink
Update GUI and python definition
Browse files Browse the repository at this point in the history
  • Loading branch information
teddychao committed May 20, 2024
1 parent 15f8fa7 commit f3b0b48
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/Import/acq/acqread_python.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,41 @@
% import: the import struct of importing settings
% ● History
% Introduced in PsPM 6.1.2
% Written in May 2024 by Madni Abdul Wahab (Uni Bonn)

% Written in May 2024 by Madni Abdul Wahab (Uni Bonn) and Teddy

%% Initialise python
if isempty(options.python_path)
psts = pspm_check_python;
else
psts = pspm_check_python(options.python_path);
end

%% Set the Python environment and the filename
py_filename = py.str(filename);
acq_data = py.bioread.read(py_filename); % Load the data using Bioread

num_channels = length(acq_data.channels); % Determine the number of channels
data.channels = cell(1, num_channels);

%% Iterate through each channel
for idx = 1:num_channels
channel = acq_data.channels{idx};
data.channels{idx} = struct();
channel = acq_data.channels{idx};
data.channels{idx} = struct();

% Convert Python dir() list to MATLAB cell array
attrs = cell(py.dir(channel));

% Convert all attributes to strings to ensure compatibility with startsWith
attrs = cellfun(@char, attrs, 'UniformOutput', false);

% Manually filter out private attributes (those starting with '_') in MATLAB
filtered_attrs = attrs(~startsWith(attrs, '_'));

% Iterate over attributes and fetch their values
for attr_name = filtered_attrs
% Python getattr to get attribute value
attr_value = py.getattr(channel, attr_name{1});

% Try converting Python data types to MATLAB data types
try
if isa(attr_value, 'py.numpy.ndarray')
Expand All @@ -55,10 +62,10 @@
catch
matlab_value = []; % If conversion fails, set as empty
end

% Assign converted value to the struct
data.channels{idx}.(char(attr_name{1})) = matlab_value;
end
end

return;
34 changes: 34 additions & 0 deletions src/pspm_get_acq_python.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function [sts, import, sourceinfo] = pspm_get_acq_python(datafile, import)
% ● Description
% pspm_get_acq is the main function for import of biopac/acknowledge files
% ● Format
% [sts, import, sourceinfo] = pspm_get_acq(datafile, import);
% this function uses the conversion routine acqread.m version 2.0 (2007-08-21)
% by Sebastien Authier and Vincent Finnerty at the University of Montreal
% which supports all files created with Windows/PC versions of
% AcqKnowledge (3.9.0 or below), BSL (3.7.0 or below), and BSL PRO
% (3.7.0 or below).
% ● Arguments
% datafile: the acq data file
% import: the struct for importing settings
% .channel: data channels to be imported
% .type: data channel types to be imported
% .sr: sampling frequency
% .data: imported data
% .marker: imported markers
% ● History
% Introduced in PsPM 6.1.2
% Written in 2024 by Teddy

%% initialise
global settings
if isempty(settings)
pspm_init;
end
sts = -1;
sourceinfo = [];
addpath(pspm_path('Import','acq'));

%% load data but suppress output
[sts, data] = evalc('acqread_python(datafile)');
end
14 changes: 14 additions & 0 deletions src/pspm_init.m
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,20 @@
'autosr', 1,...
'help', helptext_import_acq);
%
% 4.10 bioread converted Biopac Acqknowledge (any version, with python)
defaults.import.datatypes(end+1) = struct(...
'short', 'acq_python',...
'long', 'Biopac Acqknowledge (any version) with python',...
'ext', 'acq',...
'funct', @pspm_get_acq_python,...
'channeltypes', {{defaults.importchanneltypes.type}},...
'chandescription', 'channel',...
'multioption', 1,...
'searchoption', 1,...
'automarker', 0,...
'autosr', 1,...
'help', helptext_import_acq_python);
%
% 4.8 exported Biopac Acqknowledge (tested on version 4.2.0)
defaults.import.datatypes(end+1) = struct(...
'short', 'acqmat',...
Expand Down
1 change: 1 addition & 0 deletions src/pspm_text.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function pspm_text(path)
% Introduced in PsPM 6.0
% Written and maintained in 2022 by Teddy Chao (UCL)
helptext_import_acq = '';
helptext_import_acq_python = 'Load acq files directly to PsPM with Python';
helptext_import_acqmat = '';
helptext_import_bioread = 'Loads mat files which have been converted using the bioread tool acq2mat. Bioread can be installed using pip (installed by python) or can be downloaded and installed manually from here https://github.com/njvack/bioread. It requires python and the python libraries numpy and scipy.';
helptext_import_csv = 'Read using comma as a delimiter.';
Expand Down

0 comments on commit f3b0b48

Please sign in to comment.