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.

psth_on_raster.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. function [rasax,psthax,sampz]=psth_on_raster(ev, ts,varargin)
  2. iod = @utils.inputordefault;
  3. pre = iod('pre',1.5,varargin);
  4. post = iod('post',1.5,varargin);
  5. binsz = iod('binsz',0.01,varargin);
  6. krn = iod('krn',0.1,varargin);
  7. figh = iod('figh',[],varargin);
  8. ref_marker = iod('ref_marker','o',varargin);
  9. cout_marker = iod('cout_marker','o',varargin);
  10. rasax = iod('ax_handle',[],varargin);
  11. renderer =iod('renderer','opengl',varargin);
  12. x_label=iod('x_label','',varargin);
  13. pre_mask=iod('pre_mask', -inf,varargin);
  14. post_mask=iod('post_mask',+inf,varargin);
  15. cout=iod('cout',[],varargin);
  16. errorbars=iod('errorbars',1,varargin);
  17. show_yinfo=iod('show_yinfo',0,varargin);
  18. sortby=iod('sortby',[],varargin);
  19. mkcolor = iod('mkcolor',[0.8 0.2 0.2],varargin);
  20. coutcolor = iod('coutcolor',[0.8 0.2 0.2],varargin);
  21. tar_time = iod('tar_time',[],varargin);
  22. linecolor = iod('linecolor',[0,0,0],varargin);
  23. set(gcf, 'Renderer',renderer);
  24. [ntrials,nrefs]=size(ev);
  25. sampz = ntrials;
  26. mutau=zeros(1,nrefs);
  27. for rx=2:nrefs
  28. mutau(rx)=nanmedian(ev(:,rx)-ev(:,1));
  29. end
  30. if isscalar(pre_mask)
  31. pre_mask=zeros(1,ntrials)+pre_mask;
  32. elseif numel(pre_mask)~=ntrials
  33. fprintf(1,'numel(pre_mask) must equal num ref events or be scalar');
  34. return;
  35. end
  36. if isscalar(post_mask)
  37. post_mask=zeros(1,ntrials)+post_mask;
  38. elseif numel(post_mask)~=ntrials
  39. fprintf(1,'numel(post_mask) must equal num ref events or be scalar');
  40. return;
  41. end
  42. if isscalar(krn)
  43. dx=ceil(5*krn);
  44. kx=-dx:binsz:dx;
  45. krn=normpdf(kx,0, krn);
  46. if isempty(find(kx==0, 1))
  47. error('Your binsz needs to divide 1 second into interger # of bins');
  48. end
  49. krn(kx<0)=0;
  50. krn=krn/sum(krn);
  51. end
  52. ref = 1:numel(ev);
  53. if ~isempty(sortby)
  54. idx=1:ntrials; idx=idx(:); ref=ref(:);
  55. ref=sortrows([sortby(ref) idx(ref)]);
  56. ref=ref(:,2);
  57. end
  58. [y2,x2]=draw.rasterplot(ev(ref,1),ts,pre,post,'pre_mask',pre_mask(ref),'post_mask',post_mask(ref),'plotthis',0);
  59. if isempty(figh)
  60. figh = figure();
  61. else
  62. figure(figh);
  63. end
  64. if isempty(rasax)
  65. rasax = draw.jaxes();
  66. else
  67. axes(rasax);
  68. end
  69. hold on;
  70. %% Plot the rasters
  71. if ~isempty(tar_time)
  72. rectangle('Position',[tar_time(1),0,tar_time(end)-tar_time(1),max(y2)],'FaceColor',[0.7 0.7 0.7],'EdgeColor',[0.7 0.7 0.7])
  73. end
  74. ll=line(x2,y2,'Parent',rasax);
  75. set(ll,'color','k');
  76. if isempty(y2)
  77. set(rasax,'YLim',[0 1e-8]);
  78. else
  79. set(rasax,'YLim',[0 max(y2)]);
  80. end
  81. set(rasax,'XLim',[-pre post]);
  82. % plot markers.
  83. h=plot(rasax,mutau,1:sampz,ref_marker,'Color',mkcolor,'MarkerFaceColor',mkcolor,'MarkerSize',5);
  84. h=plot(rasax,cout(ref),1:sampz,cout_marker,'Color',coutcolor,'MarkerFaceColor',coutcolor,'MarkerSize',5);
  85. set(rasax,'YColor','none')
  86. % plot psth
  87. %[Y,x,W]=warpfilter(ev,ts,krn,'pre',pre,'post',post,'kernel_bin_size',binsz);
  88. [y,x]=stats.spike_filter(ev,ts,krn,'pre',pre,'post',post,'kernel_bin_size',binsz);
  89. [y x]=draw.maskraster(x,y,pre_mask ,post_mask );
  90. ymn = nanmean(y,1);
  91. yst= stats.nanstderr(y,1);
  92. psthax = axes('Position',rasax.Position);
  93. hold on
  94. if strcmpi(renderer,'opengl')
  95. sh =draw.shadeplot(x,ymn -yst ,ymn +yst ,{linecolor ,psthax,0.8});
  96. set(sh,'FaceColor',linecolor);
  97. % lh=line(x,ymn ,'Color',clrs ,'LineWidth',2);
  98. else
  99. if errorbars
  100. hh(1)=line(x,ymn -yst ,'Parent',psthax);
  101. hh(2)=line(x,ymn +yst ,'Parent',psthax);
  102. set(hh,'LineWidth',1,'LineStyle','-','Color',linecolor);
  103. %lh=line(x,ymn ,'Color',clrs ,'LineWidth',1,'Parent',psthax);
  104. lh=hh(1);
  105. sh =lh;
  106. else
  107. hh(1)=line(x,ymn ,'Parent',psthax);
  108. set(hh,'LineWidth',2,'LineStyle','-','Color',linecolor);
  109. %lh=line(x,ymn ,'Color',clrs ,'LineWidth',1,'Parent',psthax);
  110. lh=hh(1);
  111. sh =lh;
  112. end
  113. end
  114. set(psthax,'XLim',rasax.XLim);
  115. if ~isempty(x_label)
  116. xh=xlabel(psthax,x_label);set(xh,'interpreter','none');
  117. end
  118. if show_yinfo
  119. ylabel(psthax,'Hz \pm SE')
  120. else
  121. set(psthax,'YTick',[]);
  122. end
  123. set(psthax, 'Color','none','Box','off','NextPlot','add','TickDir','out','TickLength',[0.018 0.01]);
  124. set(rasax, 'Color','none','XColor','none','YColor','none','XTickLabel',[],'YTickLabel',[]);
  125. end