Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

pRF_AvgSessions.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function pRF_AvgSessions(MONKEY)
  2. if nargin < 1
  3. MONKEY={'M01','M02'};
  4. end
  5. %% Merge median BOLD signals
  6. clc;
  7. startfld=pwd;
  8. cd ../../
  9. SHARED_ROOT_FLD = pwd;
  10. cd(startfld)
  11. for m=1:length(MONKEY)
  12. fprintf(['==== Processing monkey: ' MONKEY{m} ' ====\n']);
  13. cd(fullfile(SHARED_ROOT_FLD,'Raw_data','MRI','Raw_matlab','us-padded',MONKEY{m}));
  14. fls = dir('medianBOLD*');
  15. MB.medianBOLD=[]; MB.medianBOLD_inv=[];
  16. MB.nRuns=[]; MB.nRuns_inv=[];
  17. MB.stim={}; MB.stim_inv={};
  18. for f=1:length(fls)
  19. fprintf(['Adding ' fls(f).name '\n']);
  20. M = load(fls(f).name);
  21. MB.medianBOLD = cat(5,MB.medianBOLD,M.medianBOLD);
  22. MB.nRuns = cat(5,MB.nRuns,M.nRuns);
  23. MB.stim = M.stim;
  24. if isfield(M,'medianBOLD_inv')
  25. MB.medianBOLD_inv = cat(5,MB.medianBOLD_inv,M.medianBOLD_inv);
  26. MB.nRuns_inv = cat(5,MB.nRuns_inv,M.nRuns_inv);
  27. MB.stim_inv = M.stim_inv;
  28. end
  29. clear M
  30. end
  31. stim.norm=MB.stim;
  32. % normal mean
  33. sess_meanBOLD = nanmean(MB.medianBOLD,5);
  34. % weighted mean by number of runs
  35. sess_wmeanBOLD = nansum(MB.medianBOLD.*MB.nRuns,5)./...
  36. nansum(MB.nRuns,5);
  37. % std
  38. sess_sdBOLD = nanstd(MB.medianBOLD,1,5);
  39. %median
  40. sess_medianBOLD = nanmedian(MB.medianBOLD,5);
  41. if isfield(MB,'medianBOLD_inv')
  42. stim.inv=MB.stim_inv;
  43. % normal mean
  44. sess_meanBOLD_inv = nanmean(MB.medianBOLD_inv,5);
  45. % weighted mean by number of runs
  46. sess_wmeanBOLD_inv = nansum(MB.medianBOLD_inv.*MB.nRuns_inv,5)./...
  47. nansum(MB.nRuns_inv,5);
  48. % std
  49. sess_sdBOLD_inv = nanstd(MB.medianBOLD_inv,1,5);
  50. %median
  51. sess_medianBOLD_inv = nanmedian(MB.medianBOLD_inv,5);
  52. end
  53. % remove volumes for which stim is nan ----
  54. nostim_idx=[];
  55. for i=1:size(stim.norm,2)
  56. if isnan(stim.norm{i}(1,1))
  57. nostim_idx=[nostim_idx i]; %#ok<*AGROW>
  58. end
  59. end
  60. stim.norm(nostim_idx)=[];
  61. sess_meanBOLD(:,:,:,nostim_idx)=[];
  62. sess_wmeanBOLD(:,:,:,nostim_idx)=[];
  63. sess_medianBOLD(:,:,:,nostim_idx)=[];
  64. sess_sdBOLD(:,:,:,nostim_idx)=[];
  65. if isfield(MB,'medianBOLD_inv')
  66. nostim_idx=[];
  67. for i=1:size(stim.inv,2)
  68. if isnan(stim.inv{i}(1,1))
  69. nostim_idx=[nostim_idx i];
  70. end
  71. end
  72. stim.inv(nostim_idx)=[];
  73. sess_meanBOLD_inv(:,:,:,nostim_idx)=[];
  74. sess_wmeanBOLD_inv(:,:,:,nostim_idx)=[];
  75. sess_medianBOLD_inv(:,:,:,nostim_idx)=[];
  76. sess_sdBOLD_inv(:,:,:,nostim_idx)=[];
  77. end
  78. % ----
  79. outfld = fullfile(SHARED_ROOT_FLD,'Preprocessed_data','MRI',MONKEY{m});
  80. [~,~,~] = mkdir(outfld);
  81. % save(fullfile(outfld,'AllSessions-avg'),'stim','sess_meanBOLD','sess_meanBOLD_inv',...
  82. % 'sess_wmeanBOLD','sess_wmeanBOLD_inv','sess_medianBOLD','sess_medianBOLD_inv',...
  83. % 'sess_sdBOLD','sess_sdBOLD_inv','MB');
  84. save(fullfile(outfld,'AllSessions-only_avg'),'stim','sess_meanBOLD','sess_meanBOLD_inv',...
  85. 'sess_wmeanBOLD','sess_wmeanBOLD_inv','sess_medianBOLD','sess_medianBOLD_inv',...
  86. 'sess_sdBOLD','sess_sdBOLD_inv');
  87. cd(startfld);
  88. clear MB
  89. fprintf('\n\n');
  90. end