% Jon Newman
% 2013 01 26
% Look at reactivity of each the three wells

fid = 'yam22669_12DIV_wash6_01';
% fid = 'yam22669_10DIV_nodrug_01';
spk = loadspk([fid '.spk']);
ss = SqueakySpk(fid,spk.meta.fs_Hz,1,spk);


w = zeros(6,9);
w(1,:) = [3 4 5 12 13 20 21 28 29];
w(2,:) = [7 14 15 16 22 23 24 30 31];
w(3,:) = [38 39 40 46 47 48 55 56 63];
w(4,:) = [36 37 44 45 52 53 60 61 62];
w(5,:) = [34 35 41 42 43 49 50 51 58];
w(6,:) = [2 9 10 17 18 19 25 26 27];

ws = {'A','B','C','D','E','F'};
dt_asdr = 1; % sec
dt_asdr2 = 300; % sec
ylimit = [0 700];


% close all
figure

for i = 1:size(w,1)

    
    % Get clean spikes
    ss.ResetClean();
    ss.RemoveChannel(setdiff(1:64,w(i,:)));
    sc = ss.ReturnClean();
    
    % Get 3 hr fr
    disp(['Well: ' ws{i}])
    %     avgFR_1hr  = length(sc.time(sc.time > max(sc.time) - 1*3600))/(1*3600)
    avgFR_3hr  = length(sc.time(sc.time > max(sc.time) - 3*3600))/(3*3600)
    %     avgFR_6hr  = length(sc.time(sc.time > max(sc.time) - 6*3600))/(6*3600)
    %     avgFR_12hr = length(sc.time(sc.time > max(sc.time) - 12*3600))/(12*3600)
    
    
    % Plot ASDR
    ax(i) = subplot(6,1,i);
    if i == 1
        title(fid,'Interpreter','none')
    end
    
    bin = max(sc.time)-12*3600:dt_asdr:max(sc.time);
    xlimit = [max(sc.time)-12*3600 max(sc.time)]/3600;
    asdr = histc(sc.time,bin);
    plot(bin/3600,asdr/dt_asdr);
    
%     hold on
%     bin = max(sc.time)-12*3600:dt_asdr2:max(sc.time);
%     asdr = histc(sc.time,bin);
%     plot(bin/3600,asdr/dt_asdr2,'r');
    
    ylim(ylimit)
    xlim(xlimit)
    ylabel('FR (Hz)')
    if i == 6
        xlabel('Time (sec)')
    end
    
end
 linkaxes(ax,'x');


