plotRFEnsemble.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. function hRFEnsembleAx = plotRFEnsemble(xFilters, yFilters, splitSign, doSmoothing, rfInds, plotImage, hue, useSubplots)
  2. %% hRFEnsembleAx = plotRFEnsemble(xFilters, yFilters, splitSign, doSmoothing, rfInds, plotImage, hue, useSubplots)
  3. %% Get an array with all xFilters and all yFilters, get RF image from the
  4. % cartesian product and plot the ensemble image of all RFs.
  5. % fi
  6. % createFullScreenFig;
  7. normFactor = 0.2626;%[];
  8. if ~exist('splitSign', 'var')
  9. splitSign = 0;
  10. end
  11. if ~exist('doSmoothing', 'var')
  12. doSmoothing = 0;
  13. end
  14. if exist('rfInds', 'var')
  15. if ~isempty(rfInds)
  16. xFilters = xFilters(rfInds, :);
  17. yFilters = yFilters(rfInds, :);
  18. end
  19. end
  20. if ~exist('plotImage', 'var')
  21. plotImage = 1;
  22. useSubplots = 0;
  23. elseif plotImage == 0 && ~exist('useSubplots', 'var')
  24. useSubplots = 1;
  25. end
  26. if ~exist('hue', 'var')
  27. hue = [];
  28. end
  29. if doSmoothing
  30. xFilters = smoothdata(xFilters, 2, 'gaussian', floor(size(xFilters, 2) * 0.15));
  31. yFilters = smoothdata(yFilters, 2, 'gaussian', floor(size(xFilters, 2) * 0.15));
  32. end
  33. % This adds a nan colum for each cell to introduce a break in case of
  34. % plotting as a single row trace several RFs.
  35. if ~plotImage
  36. xFilters = [xFilters nan * ones(size(xFilters, 1), 1)];
  37. yFilters = [yFilters nan * ones(size(yFilters, 1), 1)];
  38. end
  39. nRFs = size(yFilters, 1);
  40. % Assuming equal length tuning curves for x and y.
  41. nXPixelsPerRF = size(xFilters, 2);
  42. nYPixelsPerRF = size(yFilters, 2);
  43. nRFsPerRow = ceil( sqrt( nRFs) );
  44. nRFsPerCol = ceil(nRFs / nRFsPerRow);
  45. xFilters = [xFilters; ones(nRFsPerCol * nRFsPerRow - nRFs, size(xFilters, 2)) * nan];
  46. yFilters = [yFilters; ones(nRFsPerCol * nRFsPerRow - nRFs, size(yFilters, 2)) * nan];
  47. nRFs = size(yFilters, 1);
  48. alphaMarker = 0.7;
  49. % nRFsPerRow = floor( sqrt( nRFs) );
  50. % while mod( nRFs, nRFsPerRow )
  51. % nRFsPerRow = nRFsPerRow - 1;
  52. % end
  53. % nRFsPerCol = ceil(nRFs / nRFsPerRow);
  54. if plotImage
  55. if splitSign
  56. if ~isempty(normFactor)
  57. allRFsCell = arrayfun(@(x) getRFIm(xFilters(x, :), yFilters(x, :), normFactor), 1:nRFs, 'UniformOutput', false);
  58. else
  59. allRFsCell = arrayfun(@(x) getRFIm(xFilters(x, :), yFilters(x, :)), 1:nRFs, 'UniformOutput', false);
  60. end
  61. else
  62. allRFsCell = arrayfun(@(x) yFilters(x, :)' * xFilters(x, :), 1:nRFs, 'UniformOutput', false);
  63. end
  64. allRFsArray = cell2mat(reshape(allRFsCell, [], nRFsPerRow));
  65. hAllRFsIm = imagesc(allRFsArray, ZeroCenteredBounds(allRFsArray, [0 100]));
  66. hRFEnsembleAx = gca;
  67. hRFEnsembleAx.XTick = linspace(0.5, nXPixelsPerRF * nRFsPerRow + 0.5, nRFsPerRow + 1);
  68. hRFEnsembleAx.YTick = linspace(0.5, nYPixelsPerRF * nRFsPerCol + 0.5, nRFsPerCol + 1);
  69. hRFEnsembleAx.XAxis.Visible = 'off';
  70. hRFEnsembleAx.YAxis.Visible = 'off';
  71. hRFEnsembleAx.Layer = 'top';
  72. if splitSign
  73. set(hRFEnsembleAx, 'xgrid', 'on', 'ygrid', 'on', 'gridlinestyle', '-', 'xcolor', 'w', 'ycolor', 'w');
  74. else
  75. set(hRFEnsembleAx, 'xgrid', 'on', 'ygrid', 'on', 'gridlinestyle', '-', 'xcolor', 'k', 'ycolor', 'k');
  76. end
  77. pbaspect([nXPixelsPerRF * nRFsPerRow, nYPixelsPerRF * nRFsPerCol, 1])
  78. axis tight
  79. % axis square
  80. colormap(brewermap([], 'RdBu'))
  81. cptFile = 'greenPurple'; %'PRGn_11'; %
  82. colormapG2P = cptcmap(cptFile, 'ncol', 256);
  83. colormap(colormapG2P);
  84. else
  85. if useSubplots
  86. for iRow = 1: nRFsPerCol
  87. for jCol = 1: nRFsPerRow
  88. rfInd = nRFsPerRow * (iRow - 1) + jCol;
  89. hSubAx(rfInd) = subplot_tight(nRFsPerCol, nRFsPerRow, rfInd, [0 0]);
  90. hXLines = plot(xFilters(rfInd, :), '-', 'LineWidth', 2, 'MarkerSize', 6);
  91. hold on;
  92. hYLines = plot(yFilters(rfInd, :), '-', 'LineWidth', 2, 'MarkerSize', 6);
  93. hRFEnsembleAx = gca;
  94. if ~isempty(hue)
  95. % Fill in the values of hue to match the extra NaN
  96. % filters used to make a square plot.
  97. hue = [hue ones(1, size(xFilters, 1) - numel(hue))];
  98. colorMap = flipud(colormap(inferno));
  99. colorMap = colorMap(ceil(size(colorMap, 1) * 0.2): end, :);
  100. colors = colorMap(round(((hue - min(hue)) / range(hue) * (size(colorMap, 1) - 1)) + 1), :);
  101. hXLines.Color = colors(rfInd, :);
  102. hYLines.Color = alphaMarker * colors(rfInd, :) + (1 - alphaMarker) * [1 1 1];
  103. hXLines.MarkerFaceColor = colors(rfInd, :);
  104. hYLines.MarkerFaceColor = alphaMarker * colors(rfInd, :) + (1 - alphaMarker) * [1 1 1];
  105. hXLines.MarkerEdgeColor = 'none';
  106. hYLines.MarkerEdgeColor = 'none';
  107. else
  108. [hXLines.Color] = deal('k');
  109. [hYLines.Color] = deal('r');
  110. end
  111. hRFEnsembleAx.XAxis.Visible = 'off';
  112. hRFEnsembleAx.YAxis.Visible = 'off';
  113. axis tight
  114. minY = min([xFilters(:); yFilters(:)]);
  115. maxY = max([xFilters(:); yFilters(:)]);
  116. ylim([minY, maxY])
  117. pbaspect([nXPixelsPerRF, nYPixelsPerRF, 1])
  118. end
  119. end
  120. hRFEnsembleAx = hSubAx;
  121. else
  122. vertPlotOffset = max(range(xFilters(:)), range(yFilters(:)));
  123. hXLines = plot(reshape(xFilters', nXPixelsPerRF * nRFsPerRow, []) + ...
  124. repmat((1 : nRFsPerCol), nXPixelsPerRF * nRFsPerRow, 1) * ...
  125. vertPlotOffset);
  126. hold on;
  127. hYLines = plot(reshape(yFilters', nYPixelsPerRF * nRFsPerRow, []) + ...
  128. repmat((1 : nRFsPerCol), nYPixelsPerRF * nRFsPerRow, 1) * ...
  129. vertPlotOffset);
  130. hRFEnsembleAx = gca;
  131. hRFEnsembleAx.XTick = linspace(0.5, nXPixelsPerRF * nRFsPerRow + 0.5, nRFsPerRow + 1);
  132. hRFEnsembleAx.YTick = linspace(vertPlotOffset, vertPlotOffset * nRFsPerCol, nRFsPerCol);
  133. [hXLines.Color] = deal('k');
  134. [hYLines.Color] = deal('r');
  135. set(hRFEnsembleAx, 'xgrid', 'on', 'ygrid', 'on', 'gridlinestyle', '-', 'xcolor', 'k', 'ycolor', 'k');
  136. hRFEnsembleAx.XAxis.Visible = 'off';
  137. hRFEnsembleAx.YAxis.Visible = 'off';
  138. hRFEnsembleAx.Layer = 'top';
  139. pbaspect([nXPixelsPerRF * nRFsPerRow, nYPixelsPerRF * nRFsPerCol, 1])
  140. axis tight
  141. end
  142. end
  143. % title('Cartesian product (X \times Y) of white noise spatial filters')
  144. % axis square
  145. end