Commit ef4069ac authored by Jesse Heckman's avatar Jesse Heckman
Browse files

automated sphere analyses prep & vPrime update

parent e93c0f44
function pb_prepSac()
% PB_PREPSAC()
%
% PB_PREPSAC() ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
cdir = '/Users/jjheckman/Documents/Data/PhD/Setups/Sphere/introduction/';
[fn, path] = pb_getfile('dir',cdir,'ext','*.*','title','Select an experimentfile');
[ext,~] = pb_fext(fn);
cd(path);
%% Get variables
experimenter = pb_delreadstr(fn,'delimiter','-','n',1);
participant = pb_delreadstr(fn,'delimiter','-','n',2);
year = pb_delreadstr(fn,'delimiter','-','n',3);
month = pb_delreadstr(fn,'delimiter','-','n',4);
day = pb_delreadstr(fn,'delimiter','-','n',5);
prefix = [experimenter '-' participant '-' year '-' month '-' day '-'];
%%
n = pb_spheretrial2complete();
for iBlock = 1:n
f_tmp = [prefix num2str(iBlock-1,'%04d') ext];
disp(f_tmp)
sphere2hoopdat(f_tmp);
sphere2hoopcsv(f_tmp);
end
pa_calibrate();
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function nblocks = pb_spheretrial2complete(dname)
% SPHERETRIAL2COMPLETE
%
% Combine the SPHERE trial files to one file
%
% See also SPHEREMAT2HOOPCSV, SPHEREMAT2HOOPDAT
%% Initialization
if nargin<1
% fname = [];
%dir;
d = what;
dname = d.path;
end
cd(dname);
d = dir('*.sphere');
%% find unique blocks
f = char(d.name);
f = f(:,1:end-12);
ublocks = unique(f,'rows');
%% Load date per block
nblocks = size(ublocks,1);
for blockIdx = 1:nblocks
fname = ublocks(blockIdx,:);
d = dir([fname '*.sphere']);
D = [];
T = [];
for fIdx = 1:numel(d)
%disp(['Loading ' d(fIdx).name]);
load(d(fIdx).name,'-mat');
D = [D data]; %#ok<AGROW>
if exist('dur','var')
trialsingle.duration = dur;
end
T = [T trialsingle]; %#ok<AGROW>
end
data = D;
trial = T; %#ok<NASGU>
fname = fcheckext(fname,'sphere');
fname = fullfile(dname,fname);
save(fname,'data','trial','cfg');
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
...@@ -22,7 +22,7 @@ function varargout = pb_vPrimeGUI(varargin) ...@@ -22,7 +22,7 @@ function varargout = pb_vPrimeGUI(varargin)
% Edit the above text to modify the response to help pb_vPrimeGUI % Edit the above text to modify the response to help pb_vPrimeGUI
% Last Modified by GUIDE v2.5 10-Sep-2018 11:28:27 % Last Modified by GUIDE v2.5 17-Sep-2018 12:27:46
% Begin initialization code - DO NOT EDIT % Begin initialization code - DO NOT EDIT
gui_Singleton = 1; gui_Singleton = 1;
...@@ -58,9 +58,9 @@ function pb_vPrimeGUI_OpeningFcn(hObject, eventdata, handles, varargin) ...@@ -58,9 +58,9 @@ function pb_vPrimeGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% Update handles structure % Update handles structure
guidata(hObject, handles); guidata(hObject, handles);
set(handles.editLoad,'string',cd);
if isunix; cd('/Users/jjheckman/Documents/Data'); end cd(datapath);
set(handles.editLoad,'string',cd);
% UIWAIT makes pb_vPrimeGUI wait for user response (see UIRESUME) % UIWAIT makes pb_vPrimeGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1); % uiwait(handles.figure1);
...@@ -87,6 +87,15 @@ function popExperimenter_Callback(hObject, eventdata, handles) ...@@ -87,6 +87,15 @@ function popExperimenter_Callback(hObject, eventdata, handles)
% Hints: contents = cellstr(get(hObject,'String')) returns popExperimenter contents as cell array % Hints: contents = cellstr(get(hObject,'String')) returns popExperimenter contents as cell array
% contents{get(hObject,'Value')} returns selected item from popExperimenter % contents{get(hObject,'Value')} returns selected item from popExperimenter
path = get(handles.editLoad,'string');
if isempty(pb_fext(path))
path = datapath;
contents = get(handles.popExperimenter,'string');
user = contents{get(handles.popExperimenter,'Value')};
newpath = datapath([path filesep user]);
set(handles.editLoad,'string',newpath);
end
end end
% --- Executes during object creation, after setting all properties. % --- Executes during object creation, after setting all properties.
...@@ -145,8 +154,12 @@ function buttonRun_Callback(hObject, eventdata, handles) ...@@ -145,8 +154,12 @@ function buttonRun_Callback(hObject, eventdata, handles)
Exp.expfile = get(handles.editLoad,'string'); Exp.expfile = get(handles.editLoad,'string');
Exp.recording = get(handles.editRec,'string'); Exp.recording = get(handles.editRec,'string');
disp(['Experimenter: ' Exp.experimenter newline 'Expfile: ' Exp.expfile newline 'Subject ID: ' Exp.SID newline 'Recording: ' Exp.recording newline]); % Sets parameters & run exp
Exp = mkDat(Exp,handles);
disp(['Experimenter: ' Exp.experimenter newline ...
'Expfile: ' Exp.expfile newline ...
'Subject ID: ' Exp.SID newline ...
'Recording: ' Exp.recording newline]);
pb_vRunExp(Exp,handles); pb_vRunExp(Exp,handles);
end end
end end
...@@ -166,9 +179,12 @@ function buttonLoad_Callback(hObject, eventdata, handles) ...@@ -166,9 +179,12 @@ function buttonLoad_Callback(hObject, eventdata, handles)
% eventdata reserved - to be defined in a future version of MATLAB % eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA) % handles structure with handles and user data (see GUIDATA)
editTxt = get(handles.editLoad,'string'); path = get(handles.editLoad,'string');
[ext, ~] = pb_fext(editTxt); path = datapath(path);
if isempty(ext); cdir = editTxt; else; fol = dir(editTxt); cdir = fol.folder; end set(handles.editLoad,'string',path);
[ext, ~] = pb_fext(path);
if isempty(ext); cdir = path; else; fol = dir(path); cdir = fol.folder; end
[fn, path] = pb_getfile('dir',cdir,'ext','*.exp','title','Load exp-file..' ); [fn, path] = pb_getfile('dir',cdir,'ext','*.exp','title','Load exp-file..' );
if fn ~= 0 if fn ~= 0
...@@ -223,3 +239,41 @@ function editRec_CreateFcn(hObject, eventdata, handles) ...@@ -223,3 +239,41 @@ function editRec_CreateFcn(hObject, eventdata, handles)
set(hObject,'BackgroundColor','white'); set(hObject,'BackgroundColor','white');
end end
end end
function exp = mkDat(exp,handles)
% Creates directory and sets parameters for data storage
datname = [exp.experimenter '-' exp.SID '-' datestr(now,'yy-mm-dd')]; %% <-- SET PATH FOR WINDOWS DATADIR
path = [datapath filesep exp.experimenter filesep 'Recordings' filesep datname];
if ~exist(path,'dir'); mkdir(path); cd(path); mkdir('trial'); end
path = [path filesep 'trial']; exp.dir = path; cd(path);
fname = [datname '-' exp.recording '-0001.vc'];
while exist(fname,'file')
% Check for existing recordings
quest = 'Recording already exists. How to proceed?';
answer = questdlg(quest,'Choices','Overwrite', 'Increment','Stop','Stop');
switch answer
case 'Overwrite'
break;
case 'Increment'
exp.recording = num2str(str2double(exp.recording)+1,'%04d');
set(handles.editRec,'string',exp.recording);
case 'Stop'
error('Run stopped.');
end
fname = [datname '-' num2str(exp.recording,'%04d') '-0001.vc'];
end
end
function path = datapath(path)
if nargin == 0; path = []; end
if isempty(path) || ~exist(path)
if isunix
path = '/Users/jjheckman/Documents/Data/PhD/Experiment/VC';
else
path = 'C:/VC/DATA';
end
end
end
function pb_vClearTrial(cnt,blck,trl)
% PB_VCLEARTRIAL()
%
% PB_VCLEARTRIAL() ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
disp([newline '<strong>New Trial started...</strong> '...
newline ' Trial: ' num2str(cnt) ' (B' num2str(blck) 'T' num2str(trl) ')']);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function pb_vRecordData(exp,trial)
% PB_VRECORDDATA()
%
% PB_VRECORDDATA() ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
cd(exp.dir)
day = datestr(now,'yy-mm-dd');
trial = num2str(trial,'%04d');
fname = [exp.experimenter '-' ...
exp.SID '-' ...
day '-' ...
exp.recording '-' ...
trial '.vc'];
fid = fopen(fname, 'wt');
fprintf(fid,'test\n');
fclose(fid);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
...@@ -7,9 +7,6 @@ function Dat = pb_vRunVC(signal) ...@@ -7,9 +7,6 @@ function Dat = pb_vRunVC(signal)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl % PBToolbox (2018): JJH: j.heckman@donders.ru.nl
dur = 10;
vSignal = pb_vCreateSignal(1, signal(1).duration, 10, 1, signal(1).type); vSignal = pb_vCreateSignal(1, signal(1).duration, 10, 1, signal(1).type);
hSignal = pb_vCreateSignal(1, signal(2).duration, 10, 1, signal(2).type); hSignal = pb_vCreateSignal(1, signal(2).duration, 10, 1, signal(2).type);
...@@ -17,7 +14,6 @@ function Dat = pb_vRunVC(signal) ...@@ -17,7 +14,6 @@ function Dat = pb_vRunVC(signal)
Dat.v.t = (0:1:length(Dat.v.x)-1)/10; Dat.v.t = (0:1:length(Dat.v.x)-1)/10;
Dat.h.x = hSignal.x .* signal(2).amplitude; Dat.h.x = hSignal.x .* signal(2).amplitude;
Dat.h.t = (0:1:length(Dat.h.x)-1)/10; Dat.h.t = (0:1:length(Dat.h.x)-1)/10;
end end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
...@@ -20,11 +20,15 @@ function pb_vRunExp(expinfo,h) ...@@ -20,11 +20,15 @@ function pb_vRunExp(expinfo,h)
tDat(nTotTrials) = struct; tDat(nTotTrials) = struct;
set(h.buttonClose, 'Enable', 'off') % avoid closing GUI during executing run function set(h.buttonClose, 'Enable', 'off') % avoid closing GUI during executing run function
set(h.buttonRun, 'Enable', 'off'); set(h.buttonRun, 'Enable', 'off')
set(h.buttonLoad, 'Enable', 'off') set(h.buttonLoad, 'Enable', 'off')
h.signals; cla;
%% BODY %% BODY
% Iterate experiment % Iterate experiment
pause(2);
for iBlock = 1:nblocks for iBlock = 1:nblocks
% Runs blocks of trials with a vestibular condition % Runs blocks of trials with a vestibular condition
nTrials = length(block(iBlock).trial); nTrials = length(block(iBlock).trial);
...@@ -38,7 +42,10 @@ function pb_vRunExp(expinfo,h) ...@@ -38,7 +42,10 @@ function pb_vRunExp(expinfo,h)
bDat(iBlock).signal = pb_vRunVC(signal); bDat(iBlock).signal = pb_vRunVC(signal);
% Plot signals % Plot signals
h.signals; cla; hold on; col = pb_selectcolor(2,2); h.signals; cla; hold on;
h.signals.YLim = [-50 50];
col = pb_selectcolor(2,2);
plot(bDat(iBlock).signal.v.t,bDat(iBlock).signal.v.x,'Color',col(1,:)); plot(bDat(iBlock).signal.v.t,bDat(iBlock).signal.v.x,'Color',col(1,:));
plot(bDat(iBlock).signal.h.t,bDat(iBlock).signal.h.x,'Color',col(2,:)); plot(bDat(iBlock).signal.h.t,bDat(iBlock).signal.h.x,'Color',col(2,:));
...@@ -47,17 +54,19 @@ function pb_vRunExp(expinfo,h) ...@@ -47,17 +54,19 @@ function pb_vRunExp(expinfo,h)
cnt = cnt+1; cnt = cnt+1;
updateTrial(h, iTrial, cnt, nTotTrials, tDat); updateTrial(h, iTrial, cnt, nTotTrials, tDat);
%pb_vClearTrial(); pb_vClearTrial(cnt,iBlock,iTrial);
%pb_vRecordData(); pb_vRecordData(expinfo,cnt);
%pb_vRunTrial(experiment(iTrial)); %pb_vRunTrial(experiment(iTrial));
%pb_vFeedbackGUI(); %pb_vFeedbackGUI();
pause(.1); pause(1);
end end
pause(2) pause(2)
end end
%% CHECK OUT %% CHECK OUT
% store data % store data
disp([newline newline 'Experiment finished!'])
set(h.buttonClose, 'Enable', 'on'); set(h.buttonClose, 'Enable', 'on');
set(h.buttonRun, 'Enable', 'on'); set(h.buttonRun, 'Enable', 'on');
set(h.buttonLoad, 'Enable', 'on'); set(h.buttonLoad, 'Enable', 'on');
...@@ -69,7 +78,7 @@ function updateBlock(h, iBlock, signal) ...@@ -69,7 +78,7 @@ function updateBlock(h, iBlock, signal)
bn = pb_sentenceCase(num2str(iBlock,'%03d')); % count block bn = pb_sentenceCase(num2str(iBlock,'%03d')); % count block
set(h.Bn,'string',bn); set(h.Bn,'string',bn);
vs = ['V = ' pb_sentenceCase(signal(1).type) ... % VC stim vs = ['V = ' pb_sentenceCase(signal(1).type) ... % VC stim
', H = ' pb_sentenceCase(signal(2).type)]; ', H = ' pb_sentenceCase(signal(2).type)];
set(h.Vs,'string',vs); set(h.Vs,'string',vs);
end end
...@@ -77,9 +86,9 @@ end ...@@ -77,9 +86,9 @@ end
function updateTrial(h, iTrial, cnt, nTotTrials, Dat) function updateTrial(h, iTrial, cnt, nTotTrials, Dat)
% Updates the trial information to the GUI % Updates the trial information to the GUI
h.figure1.Name = ['vPrime - ' num2str(cnt) '/' num2str(nTotTrials) ' Trials']; % counting title h.figure1.Name = ['vPrime - ' num2str(cnt) '/' num2str(nTotTrials) ' Trials']; % counting title
tn = num2str(iTrial,'%03d'); % blocktrial tn = num2str(iTrial,'%03d'); % blocktrial
set(h.Tn,'string',tn) set(h.Tn,'string',tn)
end end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment