Commit aed4c722 authored by Jesse Heckman's avatar Jesse Heckman

added: - data conversion/zipping; improved minor functions: gaussians,...

added: - data conversion/zipping; improved minor functions: gaussians, pythagoras, getfile, niceboxplot. Also reset safety settings vPrime.
parent 8223984d
......@@ -2,11 +2,15 @@
% Empty, Clear, Clean, Set globals.
pb_clean;
path = '/Users/jjheckman/Documents/Data/PhD/Experiment/vestibular_frequencies/JJH-0004-19-09-24/';
fn = 'Converted_Data.mat';
fullname = [path fn];
blocknumber = 5;
cfn = 0;
[fn,path] = pb_getfile('cdir',pb_datapath);
fullname = [path fn];
blocknumber = 4;
load(fullname);
D = Data;
datl = length(D);
load(fullname);
changefonts; % set fonts to avenir next
......@@ -844,7 +848,6 @@ relPhase = mdlVOR.shift-mdlVEST.shift
gain = mdlVOR.yscale/-mdlVEST.yscale
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
......
function D = pb_convertdata(fn,varargin)
% PB_CONVERTDATA
%
% PB_CONVERTDATA() converts and bulks all datafiles for each block in the vestibular setup together
%
% See also PB_ZIPBLOCKS
% PBToolbox (2020): JJH: j.heckman@donders.ru.nl
% Prep Data
load(fn);
datl = length(dat);
D = struct('Pup',[],'Opt',[],'Sensehat',[],'VC',[],'Timestamp',[]);
D(datl).Pup = [];
fn = pb_fsplit(fn);
%% Get Data
% Convert Pupil & Optitrack data, synchronize and store.
for iSig = 1:datl
% Loop over pb_data
% temp variables
pup = dat(iSig).pupil_labs;
pup.Data = lsl_pupil_convert2soa(pup);
opt = dat(iSig).optitrack;
opt.Data = lsl_optitrack_convert2soa(opt);
sensehat = dat(iSig).sensehat;
D(iSig).Pup = pup;
D(iSig).Opt = opt;
D(iSig).Sensehat = mat2struct(sensehat.Data,struct_sensehat_fields);
D(iSig).VC = dat(iSig).vestibular_signal;
D(iSig).Timestamp.Pup = lsl_correct_pupil_timestamps(pup);
D(iSig).Timestamp.Opt = lsl_correct_lsl_timestamps(opt);
D(iSig).Timestamp.Sense = lsl_correct_lsl_timestamps(sensehat);
dat(iSig).block_info.fn = fn;
D(iSig).Block_Info = dat(iSig).block_info;
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2020) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function fn = pb_zipblocks(cdir,varargin)
% PB_ZIPBLOCKS
%
% PB_ZIPBLOCKS(cdir) converts and bulks all datafiles for each block in the
% vestibular setup together. Input: experimental folder. Output: merged
% converted data.
%
% See also PB_CONVERTDATA
% PBToolbox (2020): JJH: j.heckman@donders.ru.nl
if nargin == 0; cdir = pb_getdir('dir','/Users/jjheckman/Documents/Data/PhD/Experiment'); end
cd(cdir);
listing = dir('block_info_*.mat');
Data = struct([]);
for iL = 1:length(listing)
disp(['>> Unpacking: ' listing(iL).name '...']);
disp(' >> Converting data...');
tmp = pb_convertdata([cd filesep listing(iL).name]);
disp(' << Data succesfully converted.');
tmpsz = length(tmp);
% Zip blocks
if isempty(Data)
Data = tmp;
else
Data(end+1:end+tmpsz) = tmp;
disp([' << ' num2str(tmpsz) ' block(s) appended.']);
end
end
fn = listing(1).name(1:end-9);
fn = strrep(fn,'block_info_','converted_data_');
fn = [fn '.mat'];
save([cd filesep fn], 'Data');
disp(['<< Zipd complete... (fn: ' fn ')']);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2020) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
%%
function [x,y] = pb_rot2zero(x,y,varargin)
% PB_ROTEYE
%
% PB_ROTEYE(x,y) ...
%
% See also ...
% PBToolbox (2020): JJH: j.heckman@donders.ru.nl
xlen = length(x);
ylen = length(y);
if ~eq(xlen,ylen); error(['Vectors X & Y must be the same length (resp.' num2str(xlen) '-by-' num2str(ylen) ')']); end
v = varargin;
axis2zero = pb_keyval('axis2zero',v,'y');
% Rotate axis
if strcmp(axis2zero,'y')
a = abs(y);
b = abs(x);
c = sqrt(a.^2 + b.^2);
x = sign(x) .* c;
y = zeros(size(x));
else
a = abs(x);
b = abs(y);
c = sqrt(a.^2 + b.^2);
y = sign(y) .* c;
x = zeros(size(y));
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2020) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function [x,y] = pb_rot2zero(x,y,varargin)
% PB_ROTEYE
%
% PB_ROTEYE(x,y) ...
%
% See also ...
% PBToolbox (2020): JJH: j.heckman@donders.ru.nl
xlen = length(x);
ylen = length(y);
if ~eq(xlen,ylen); error(['Vectors X & Y must be the same length (resp.' num2str(xlen) '-by-' num2str(ylen) ')']); end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2020) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -14,7 +14,7 @@ function signal = pb_vSafety(signal)
% DO NOT CHANGE THESE!
thresh_dur = 300;
thresh_amp = 100;
thresh_fre = 1;
thresh_fre = 0.65;
for iAx = 1:2
......
......@@ -14,11 +14,11 @@ function sn = pb_mountserver(varargin)
prfx = '';
cin = ['mount -t smbfs //' getcredentials(srv) '@' srv '-srv.science.ru.nl/' srv '/ ~/sharename/'];
cin = ['mount -t smbfs //' getcredentials(srv) '@' srv '-srv.science.ru.nl/' srv '/ /Volumes/mbaudit5'];
[s,cout] = system(cin);
if s > 0 && s ~= 64; disp(cout); end
if s == 64 && ~force; system('umount ~/sharename/'); prfx = 'un'; end
if s == 64 && ~force; system('umount /Volumes/mbaudit5'); prfx = 'un'; end
if s == 0 && flag || flag && force; pb_open; end
disp([srv ' is ' prfx 'mounted.' newline]);
end
......
......@@ -8,7 +8,7 @@ function cout = pb_open(folder, varargin)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
if nargin == 0
folder = '~/sharename';
folder = '/Volumes/smb';
end
if exist(folder,'dir')
......
function [file,path] = pb_fsplit(fn)
% PB_FSPLIT
%
% PB_FSPLIT(fn) splits file and path.
%
% See also ...
% PBToolbox (2020): JJH: j.heckman@donders.ru.nl
if strcmp(fn(end),filesep); error(['Filename cannot end with a filesep (' filesep ').']); end
seps = strfind(fn,filesep);
file = fn(seps(end)+1:end);
path = fn(1:seps(end));
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2020) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -10,7 +10,7 @@ function pb_niceboxplot(h, varargin)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% Set initial variables
if nargin == 0; h = gcf; end
if nargin == 0; h = gcf; end
outliers = pb_keyval('outliers',varargin,0);
ac = pb_keyval('ac',varargin,0);
......@@ -22,16 +22,18 @@ function pb_niceboxplot(h, varargin)
linestyle = pb_keyval('linestyle',varargin,'-');
%% Body
axx = pb_fobj(gcf,'Type','Axes');
axx = pb_fobj(h,'Type','Axes');
for iAxes=1:length(axx)
ax = axx(iAxes);
ax = axx(iAxes);
hpatch = pb_fobj(gcf,'Tag','Boxplot Patch');
delete(hpatch);
% Remove BS
if ~ac; delete(pb_fobj(ax,'Tag','Upper Adjacent Value')); delete(pb_fobj(ax,'Tag','Lower Adjacent Value')); end
if ~outliers; delete(pb_fobj(ax,'Tag','Outliers')); end
nBP = length(pb_fobj(ax,'Tag','Box'));
lines = pb_fobj(ax,'Type','Line');
lines = pb_fobj(ax,'Type','Line','-not','Tag','Outliers');
% Create color pattern
if isempty(col); col = pb_selectcolor(nBP,def); end
......@@ -48,7 +50,7 @@ function pb_niceboxplot(h, varargin)
end
bx = pb_fobj(ax,'Tag','Box');
for k=1:length(bx)
patch(axx(iAxes),get(bx(k),'XData'),get(bx(k),'YData'),col(k,:),'FaceAlpha',alpha,'EdgeColor',col(k,:),'LineWidth',linewidth);
patch(axx(iAxes),get(bx(k),'XData'),get(bx(k),'YData'),col(k,:),'FaceAlpha',alpha,'EdgeColor',col(k,:),'LineWidth',linewidth,'Tag','Boxplot Patch');
end
end
figure(gcf);
......
......@@ -10,6 +10,8 @@ function [fname, path] = pb_getfile(varargin)
cdir = pb_keyval('dir',varargin,cd);
cd(cdir);
ext = pb_keyval('ext',varargin,'*.*');
title = pb_keyval('title',varargin,'Open file...'); % titles have been removed from matlab ui's in OS X - El capitain
......
......@@ -13,7 +13,7 @@ function x = pb_gaussfun(len,varargin)
P = pb_keyval('P',v);
if ~isempty(P); sigma = sqrt(P); end
x = sigma*randn(len,1)+mu;
x = sigma*rot90(randn(len,1))+mu;
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
......@@ -7,6 +7,8 @@ function c = pb_pythagoras(a,b)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
if mean(a)<0; sign = -1; else; sign = 1; end
if mean(b)<0; sign = -1 * sign; end
......
Markdown is supported
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