Skip to content

Commit fe5bb1a

Browse files
committed
temp change to pspm_dcm and update to pspm_get_rf
1 parent 8b3d64f commit fe5bb1a

2 files changed

Lines changed: 87 additions & 12 deletions

File tree

src/pspm_dcm.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,26 @@
731731
return
732732
end
733733

734+
%% temp rf solution
735+
% In RF-only mode, pspm_dcm_inv returns RF posterior information but no
736+
% trial-wise session field dcm.sn. Therefore skip stats/name assembly.
737+
if options.getrf
738+
dcm.dcmname = model.modelfile;
739+
dcm.modelfile = model.modelfile;
740+
dcm.input = model;
741+
dcm.options = options;
742+
dcm.warnings = warnings;
743+
dcm.modeltype = 'dcm';
744+
dcm.modality = settings.modalities.dcm;
745+
746+
if ~options.nosave
747+
save(model.modelfile, 'dcm');
748+
end
749+
750+
sts = 1;
751+
return
752+
end
753+
734754
%% 7 Assemble stats & names
735755
dcm.stats = [];
736756
cTrl = 0;

src/pspm_get_rf.m

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@
1414
% SPM style onsets file with one event type, or (3) an epochs file
1515
% (see pspm_dcm or pspm_get_epochs).
1616
% * outfile : (optional) a file to write the response function to
17-
% * channel : (optional) data channel (default: look for first SCR channel)
17+
% * channel : (optional) data channel (default: look for first SCR channel)
1818
% * options : [struct] to be passed on to pspm_dcm
1919
% ● History
2020
% Introduced in PsPM 3.0
2121
% Written in 2008-2015 by Dominik R Bach (Wellcome Trust Centre for Neuroimaging)
22+
% Updated in 2026 by Bernhard A. von Raußendorf
2223

2324
%% initialise
2425
global settings
2526
if isempty(settings)
2627
pspm_init;
2728
end
2829
sts = -1;
29-
rf = [];
30+
rf = []; % in the m-function can be removed
31+
theta = [];
3032

3133
%% check input
3234
if nargin < 1
@@ -40,28 +42,73 @@
4042
[pth infn ext] = fileparts(fn);
4143
outfile = fullfile(pth, ['RF_', infn, ext]);
4244
end
43-
if nargin < 4
45+
if nargin < 4 || isempty(channel)
4446
channel = 'scr';
4547
end
48+
if nargin < 5 || isempty(options)
49+
options = struct();
50+
end
51+
4652

4753
%% call DCM
4854
options = pspm_options(options, 'get_rf');
4955
% options.getrf = 1;
5056
%try options.nosave, catch, options.nosave = 1; end
51-
options.channel = channel;
52-
[foo dcm] = pspm_dcm(fn, '', events, options);
53-
if numel(dcm{1}.prior.posterior) == 2
57+
if options.invalid
58+
warning('options invalid') % change!
59+
return;
60+
end
61+
62+
% prepare timing for pspm_dcm -> maybe change!
63+
if isnumeric(events)
64+
if isvector(events)
65+
events = {events(:)};
66+
else
67+
events = {events};
68+
end
69+
end
70+
71+
model.datafile = {fn};
72+
model.timing = {events};
73+
model.channel = channel;
74+
model.modelfile = [tempname, '.mat'];
75+
76+
[dsts, dcm] = pspm_dcm(model, options);
77+
if dsts < 1 || isempty(dcm)
78+
warning('RF estimation failed in pspm_dcm.'); % change!
79+
return;
80+
end
81+
82+
% options.channel = channel;
83+
% [foo dcm] = pspm_dcm(fn, '', events, options);
84+
85+
86+
if iscell(dcm)
87+
dcm_rf = dcm{1};
88+
else
89+
dcm_rf = dcm;
90+
end
91+
92+
if numel(dcm_rf.prior.posterior) == 2
5493
% based on eSCR
55-
theta = dcm{1}.prior.posterior(2).muTheta(1:7)';
94+
theta = dcm_rf.prior.posterior(2).muTheta(1:7)';
5695
else
5796
% based on aSCR (i. e. updated RF)
58-
theta = dcm{1}.prior.posterior(3).muTheta(1:7)';
97+
theta = dcm_rf.prior.posterior(3).muTheta(1:7)';
5998
end
6099

100+
% if numel(dcm{1}.prior.posterior) == 2
101+
% % based on eSCR
102+
% theta = dcm{1}.prior.posterior(2).muTheta(1:7)';
103+
% else
104+
% % based on aSCR (i. e. updated RF)
105+
% theta = dcm{1}.prior.posterior(3).muTheta(1:7)';
106+
% end
107+
61108
%% write response function to file
62-
if ~isempty(outfile)
109+
if ~isempty(outfile) % should never be empty!
63110
[pth fn ext] = fileparts(outfile);
64-
c = clock;
111+
c = clock; % timestamp
65112
job{1} = sprintf('function [rf, theta] = %s(td)', fn);
66113
job{2} = '%-----------------------------------------------------------------------';
67114
job{3} = ['% Response function created by pspm_get_rf, ', date, sprintf(' %02.0f:%02.0f', c(4:5))];
@@ -82,9 +129,17 @@
82129
job{18} = sprintf('rf = Xt(1, :);');
83130
job{19} = sprintf('rf = rf/max(rf);');
84131
job{20} = sprintf('rf = rf(:);');
85-
job = strvcat(job');
132+
% job = strvcat(job');
133+
% outfile = fullfile(pth, [fn, '.m']);
134+
% dlmwrite(outfile, job, 'delimiter', '');
86135
outfile = fullfile(pth, [fn, '.m']);
87-
dlmwrite(outfile, job, 'delimiter', '');
136+
137+
fid = fopen(outfile, 'w');
138+
fprintf(fid, '%s\n', job{:});
139+
fclose(fid);
88140
end
141+
89142
sts = 1;
90143
return
144+
145+
end

0 commit comments

Comments
 (0)