function PlotUSDR(SS,frmax,zeroTime)
% CSDR(SS,FRMAX) Channel Spike Detection Rate. Takes information from the csdr
% property to display data as image wherein the firing rate on each channel
% is shown in grey scale from 0 to FRMAX Hz. FRMAX is set to the maximal detected
% firing rate by default.
%
%       Created by: Jon Newman (jnewman6 at gatech dot edu)
%       Location: The Georgia Institute of Technology
%       Created on: Feb 2, 2011
%       Last modified: Feb 2, 2011
% 	Licensed under the GPL: http://www.gnu.org/licenses/gpl.txt

if isempty(SS.asdr)
    warning('You need to calculate the ASDR before plotting the CSDR');
    return;
end

if nargin < 2 || isempty(frmax)
    frmax = inf;
end

figure()
img = log10(SS.usdr(:,2:end)');
%img = SS.usdr(:,2:end)';
img(img == -inf) = -2;
%low = min(low);
%img(img == -inf) = round(low - 1);

% Create a color map that is good at displaying a wide range of data
cmp = jet(200);
cmp(1,:) = 0;
%cmp = flipud(cmp.^3);
%cmp(1,:) = 0;

% Smooth along each channel
for i = 1:size(img,1)
    img(i,:) = smooth(img(i,:),3);
end

if sum(sum(img > frmax)) > 0
    img(img > frmax ) = frmax;
elseif frmax ~= inf
    img(end) = frmax;
end

% Blur the image with a Gaussian Filter
colormap(cmp);
q = imagesc(img);
c = colorbar();
ylabel(c,'Firing Rate (Hz)')

% labels
title('Unit Wide Spike Detection Rate')
xlabel('Time (hours)')
ylabel('Unit')
set(gca,'YDir','normal')
%caxis([10^(min(img)) 10^(max(img))

% tick mark edits
tmax = max(SS.time);
zeroTime = 75098;
lowTick = floor(zeroTime/3600);
set(gca,'XTick',[(zeroTime-lowTick*3600):4*3600:tmax-(zeroTime-lowTick*3600)]/60,...
'XTickLabel',[-lowTick:4:tmax/3600-lowTick]);
%set(gca,'XTick',[0:4*60:tmax/60], 'XTickLabel',[0:4:tmax/3600]);
minLabel = round(min(min(img)));
maxLabel = round(max(max(img)));
labelNum = minLabel:maxLabel;
for ind = 1:length(labelNum)
    c_label{ind,:} = sprintf('10^%d', labelNum(ind));
end
set(c,'YTickLabel',c_label);
end
