procEye.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. %% ANALYZE THE 5 Hz LOGS OF THE EYE POSITION DATA
  2. %% EPHYS ==================================================================
  3. cd ..
  4. bf = fullfile(pwd);
  5. cd 'Analysis_code'
  6. f = {fullfile(bf,'Preprocessed_data','EPHYS',...
  7. 'M03','20180807_B2','M03_20180807_B2_STIM.mat'),...
  8. fullfile(bf,'Preprocessed_data','EPHYS',...
  9. 'M04','20181004_B1','M04_20181004_B1_STIM.mat')};
  10. medX=[];medY=[];iqrX=[];iqrY=[];IQRX=[];IQRY=[];X=[];Y=[];
  11. for M=1:2
  12. load(f{M});
  13. for s=1:length(B)
  14. % Tracker-log based
  15. EC(s,M).t = [B(s).Log.Eye.t]';
  16. EC(s,M).X=[]; EC(s,M).Y=[];
  17. ppd = B(s).Par.PixPerDeg;
  18. for i=1:length(B(s).Log.Eye)
  19. EC(s,M).X = [EC(s,M).X; B(s).Log.Eye(i).CurrEyePos(1)./ppd];
  20. EC(s,M).Y = [EC(s,M).Y; B(s).Log.Eye(i).CurrEyePos(2)./ppd];
  21. end
  22. X=[X;EC(s,M).X ones(size(EC(s,M).X)).*M ones(size(EC(s,M).X)).*s];
  23. Y=[Y;EC(s,M).Y ones(size(EC(s,M).X)).*M ones(size(EC(s,M).X)).*s];
  24. medX = [medX; median(EC(s,M).X)];
  25. iqrX = [iqrX; iqr(EC(s,M).X)];
  26. IQRX = [IQRX; [medX(end)-iqrX(end)/2 medX(end)+iqrX(end)/2]];
  27. medY = [medY; median(EC(s,M).Y)];
  28. iqrY = [iqrY; iqr(EC(s,M).Y)];
  29. IQRY = [IQRY; [medY(end)-iqrY(end)/2 medY(end)+iqrY(end)/2]];
  30. end
  31. end
  32. %% Give stats =============================================================
  33. % Per animal ---
  34. m={'M03','M04'};
  35. fprintf('============================================\n');
  36. fprintf('EPHYS DATA ---------------------------------\n');
  37. fprintf('============================================\n');
  38. for i =1:2
  39. fprintf(['Eye-positions monkey ' m{i} '\n']);
  40. s=X(:,2)==i;
  41. cmedX = median(X(s,1));
  42. cmedY = median(Y(s,1));
  43. cmedE = median(sqrt(X(s,1).^2 + Y(s,1).^2));
  44. ciqrX = iqr(X(s,1));
  45. ciqrY = iqr(Y(s,1));
  46. ciqrE = iqr(sqrt(X(s,1).^2 + Y(s,1).^2));
  47. fprintf(['Median [iqr] X-POS: ' num2str(cmedX) ' [' num2str(ciqrX) ']\n']);
  48. fprintf(['Median [iqr] Y-POS: ' num2str(cmedY) ' [' num2str(ciqrY) ']\n']);
  49. fprintf(['Median [iqr] ECC: ' num2str(cmedE) ' [' num2str(ciqrE) ']\n\n']);
  50. end
  51. % Both monkeys ---
  52. fprintf(['Eye-positions both monkeys\n']);
  53. cmedX = median(X(:,1));
  54. cmedY = median(Y(:,1));
  55. cmedE = median(sqrt(X(:,1).^2+Y(:,1).^2));
  56. ciqrX = iqr(X(:,1));
  57. ciqrY = iqr(Y(:,1));
  58. ciqrE = iqr(sqrt(X(:,1).^2+Y(:,1).^2));
  59. fprintf(['Median [iqr] X-POS: ' num2str(cmedX) ' [' num2str(ciqrX) ']\n']);
  60. fprintf(['Median [iqr] Y-POS: ' num2str(cmedY) ' [' num2str(ciqrY) ']\n']);
  61. fprintf(['Median [iqr] ECC: ' num2str(cmedE) ' [' num2str(ciqrE) ']\n\n']);
  62. %% fMRI ===================================================================
  63. % Which logfiles?
  64. SLIST = {fullfile(bf,'Analysis_code','MRI','pRF_PrepDatalist_M01.m'),...
  65. fullfile(bf,'Analysis_code','MRI','pRF_PrepDatalist_M02.m')};
  66. MM={'M01';'M02'}; ppd3T=63.3; HW3T=960; HH3T=540;
  67. fld = '/media/8TB/NHP-BIDS';
  68. mri_eye=[];
  69. for m=1:length(SLIST)
  70. run(SLIST{m})
  71. fprintf(['Getting eye data for ' MM{m} '\n'])
  72. for d=1:length(DATA)
  73. sess = DATA{d,1}(1:8);
  74. runnr = DATA{d,2};
  75. bsinc = DATA{d,3};
  76. fprintf(['Sess ' sess ', run ' runnr '\n'])
  77. % load log
  78. logfile = fullfile(bf,'Analysis_code','Eye','MRI_eyelog',MM{m},...
  79. ['sub-' MM{m} '_ses-' sess '_task-prf_run-' runnr '_model'],...
  80. 'EyeX.txt');
  81. TX=readtable(logfile);
  82. TX.Properties.VariableNames = {'t','d','x'};
  83. logfile = fullfile(bf,'Analysis_code','Eye','MRI_eyelog',MM{m},...
  84. ['sub-' MM{m} '_ses-' sess '_task-prf_run-' runnr '_model'],...
  85. 'EyeY.txt');
  86. TY=readtable(logfile);
  87. TY.Properties.VariableNames = {'t','d','y'};
  88. logfile = fullfile(bf,'Analysis_code','Eye','MRI_eyelog',MM{m},...
  89. ['sub-' MM{m} '_ses-' sess '_task-prf_run-' runnr '_model'],...
  90. 'Log_ALL_eventlog.csv');
  91. TE=readtable(logfile);
  92. % get bar sweep series start & stop
  93. p0=(bsinc(1)-1)*20+1; p1=bsinc(1)*20;
  94. for ev=1:size(TE,1)
  95. if strcmp(TE.info{ev},num2str(p0))
  96. t0 = TE.time_s(ev);
  97. elseif strcmp(TE.info{ev},num2str(p1))
  98. tE = TE.time_s(ev);
  99. end
  100. end
  101. mri_eye = [mri_eye; ...
  102. TX.x(TX.t>t0 & TX.t<tE)./ppd3T ...
  103. TY.y(TY.t>t0 & TY.t<tE)./ppd3T ...
  104. ones(sum(TX.t>t0 & TX.t<tE),1)*m ...
  105. ones(sum(TX.t>t0 & TX.t<tE),1)*d];
  106. end
  107. end
  108. %% Give stats =============================================================
  109. % Per animal ---
  110. m={'M01','M02'};
  111. fprintf('============================================\n');
  112. fprintf('MRI DATA -----------------------------------\n');
  113. fprintf('============================================\n');
  114. for i =1:2
  115. fprintf(['Eye-positions monkey ' m{i} '\n']);
  116. s=mri_eye(:,3)==i;
  117. cmedX = median(mri_eye(s,1));
  118. cmedY = median(mri_eye(s,2));
  119. cmedE = median(sqrt(mri_eye(s,1).^2 + mri_eye(s,2).^2));
  120. ciqrX = iqr(mri_eye(s,1));
  121. ciqrY = iqr(mri_eye(s,2));
  122. ciqrE = iqr(sqrt(mri_eye(s,1).^2 + mri_eye(s,2).^2));
  123. fprintf(['Median [iqr] X-POS: ' num2str(cmedX) ' [' num2str(ciqrX) ']\n']);
  124. fprintf(['Median [iqr] Y-POS: ' num2str(cmedY) ' [' num2str(ciqrY) ']\n']);
  125. fprintf(['Median [iqr] ECC: ' num2str(cmedE) ' [' num2str(ciqrE) ']\n\n']);
  126. end
  127. % Both monkeys ---
  128. fprintf('Eye-positions both monkeys\n');
  129. cmedX = median(mri_eye(:,1));
  130. cmedY = median(mri_eye(:,2));
  131. cmedE = median(sqrt(mri_eye(:,1).^2+mri_eye(:,2).^2));
  132. ciqrX = iqr(mri_eye(:,1));
  133. ciqrY = iqr(mri_eye(:,2));
  134. ciqrE = iqr(sqrt(mri_eye(:,1).^2+mri_eye(:,1).^2));
  135. fprintf(['Median [iqr] X-POS: ' num2str(cmedX) ' [' num2str(ciqrX) ']\n']);
  136. fprintf(['Median [iqr] Y-POS: ' num2str(cmedY) ' [' num2str(ciqrY) ']\n']);
  137. fprintf(['Median [iqr] ECC: ' num2str(cmedE) ' [' num2str(ciqrE) ']\n\n']);