123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- function [rasax,psthax,sampz]=psth_on_raster(ev, ts,varargin)
- iod = @utils.inputordefault;
- pre = iod('pre',1.5,varargin);
- post = iod('post',1.5,varargin);
- binsz = iod('binsz',0.01,varargin);
- krn = iod('krn',0.1,varargin);
- figh = iod('figh',[],varargin);
- ref_marker = iod('ref_marker','o',varargin);
- cout_marker = iod('cout_marker','o',varargin);
- rasax = iod('ax_handle',[],varargin);
- renderer =iod('renderer','opengl',varargin);
- x_label=iod('x_label','',varargin);
- pre_mask=iod('pre_mask', -inf,varargin);
- post_mask=iod('post_mask',+inf,varargin);
- cout=iod('cout',[],varargin);
- errorbars=iod('errorbars',1,varargin);
- show_yinfo=iod('show_yinfo',0,varargin);
- sortby=iod('sortby',[],varargin);
- mkcolor = iod('mkcolor',[0.8 0.2 0.2],varargin);
- coutcolor = iod('coutcolor',[0.8 0.2 0.2],varargin);
- tar_time = iod('tar_time',[],varargin);
- linecolor = iod('linecolor',[0,0,0],varargin);
- set(gcf, 'Renderer',renderer);
- [ntrials,nrefs]=size(ev);
- sampz = ntrials;
- mutau=zeros(1,nrefs);
- for rx=2:nrefs
- mutau(rx)=nanmedian(ev(:,rx)-ev(:,1));
- end
- if isscalar(pre_mask)
- pre_mask=zeros(1,ntrials)+pre_mask;
- elseif numel(pre_mask)~=ntrials
- fprintf(1,'numel(pre_mask) must equal num ref events or be scalar');
- return;
- end
- if isscalar(post_mask)
- post_mask=zeros(1,ntrials)+post_mask;
- elseif numel(post_mask)~=ntrials
- fprintf(1,'numel(post_mask) must equal num ref events or be scalar');
- return;
- end
- if isscalar(krn)
- dx=ceil(5*krn);
- kx=-dx:binsz:dx;
- krn=normpdf(kx,0, krn);
- if isempty(find(kx==0, 1))
- error('Your binsz needs to divide 1 second into interger # of bins');
- end
- krn(kx<0)=0;
- krn=krn/sum(krn);
- end
- ref = 1:numel(ev);
- if ~isempty(sortby)
- idx=1:ntrials; idx=idx(:); ref=ref(:);
- ref=sortrows([sortby(ref) idx(ref)]);
- ref=ref(:,2);
- end
- [y2,x2]=draw.rasterplot(ev(ref,1),ts,pre,post,'pre_mask',pre_mask(ref),'post_mask',post_mask(ref),'plotthis',0);
- if isempty(figh)
- figh = figure();
- else
- figure(figh);
- end
- if isempty(rasax)
- rasax = draw.jaxes();
- else
- axes(rasax);
- end
- hold on;
- %% Plot the rasters
- if ~isempty(tar_time)
- 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])
- end
- ll=line(x2,y2,'Parent',rasax);
- set(ll,'color','k');
- if isempty(y2)
- set(rasax,'YLim',[0 1e-8]);
- else
- set(rasax,'YLim',[0 max(y2)]);
- end
- set(rasax,'XLim',[-pre post]);
- % plot markers.
- h=plot(rasax,mutau,1:sampz,ref_marker,'Color',mkcolor,'MarkerFaceColor',mkcolor,'MarkerSize',5);
- h=plot(rasax,cout(ref),1:sampz,cout_marker,'Color',coutcolor,'MarkerFaceColor',coutcolor,'MarkerSize',5);
- set(rasax,'YColor','none')
- % plot psth
- %[Y,x,W]=warpfilter(ev,ts,krn,'pre',pre,'post',post,'kernel_bin_size',binsz);
- [y,x]=stats.spike_filter(ev,ts,krn,'pre',pre,'post',post,'kernel_bin_size',binsz);
- [y x]=draw.maskraster(x,y,pre_mask ,post_mask );
- ymn = nanmean(y,1);
- yst= stats.nanstderr(y,1);
- psthax = axes('Position',rasax.Position);
- hold on
- if strcmpi(renderer,'opengl')
- sh =draw.shadeplot(x,ymn -yst ,ymn +yst ,{linecolor ,psthax,0.8});
- set(sh,'FaceColor',linecolor);
- % lh=line(x,ymn ,'Color',clrs ,'LineWidth',2);
- else
- if errorbars
- hh(1)=line(x,ymn -yst ,'Parent',psthax);
- hh(2)=line(x,ymn +yst ,'Parent',psthax);
- set(hh,'LineWidth',1,'LineStyle','-','Color',linecolor);
- %lh=line(x,ymn ,'Color',clrs ,'LineWidth',1,'Parent',psthax);
- lh=hh(1);
- sh =lh;
- else
- hh(1)=line(x,ymn ,'Parent',psthax);
- set(hh,'LineWidth',2,'LineStyle','-','Color',linecolor);
- %lh=line(x,ymn ,'Color',clrs ,'LineWidth',1,'Parent',psthax);
- lh=hh(1);
- sh =lh;
- end
-
- end
- set(psthax,'XLim',rasax.XLim);
- if ~isempty(x_label)
- xh=xlabel(psthax,x_label);set(xh,'interpreter','none');
- end
- if show_yinfo
- ylabel(psthax,'Hz \pm SE')
- else
- set(psthax,'YTick',[]);
- end
- set(psthax, 'Color','none','Box','off','NextPlot','add','TickDir','out','TickLength',[0.018 0.01]);
- set(rasax, 'Color','none','XColor','none','YColor','none','XTickLabel',[],'YTickLabel',[]);
- end
|