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

fid = 'vivy21367_10DIV_nodrug_02';
% t_end = loadspk([fid '.spk'],'last');
 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'};

figure

for i = 1:size(w,1)
subplot(6,1,i);    
    ss.ResetClean();
    ss.RemoveChannel(setdiff(1:64,w(i,:)));
    sc = ss.ReturnClean();
    
    
    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)
    
    
    dt_asdr = 1; % sec
    bin = max(sc.time)-24*3600:dt_asdr:max(sc.time);
    asdr = histc(sc.time,bin);
    plot(bin,asdr/dt_asdr);
    ylim([0 700])
    
    
    
end



% b = loadbang([fid '.bang']);


% %%
% close all
% figure
% dt_asdr = 60; % sec
% bin = max(sc.time)-12*3600:dt_asdr:max(sc.time);
% asdr = histc(sc.time,bin);
% plot(bin,asdr/dt_asdr,'k-'); hold on;
% plot([max(sc.time)-1*3600, max(sc.time)],[avgFR_1hr,avgFR_1hr],'-m','LineWidth',2);
% plot([max(sc.time)-3*3600, max(sc.time)],[avgFR_3hr,avgFR_3hr],'-g','LineWidth',2);
% plot([max(sc.time)-6*3600, max(sc.time)],[avgFR_6hr,avgFR_6hr],'-b','LineWidth',2);
% plot([max(sc.time)-12*3600,max(sc.time)],[avgFR_12hr,avgFR_12hr],'-r','LineWidth',2);
%
% %%
% % close all
% % ss.ASDR(0.01)
% % plot(ss.asdr.bin,ss.asdr.asdr,'r')
% % hold on
% % plot(b.time,b.meas)
% %
% % sum(b.meas/100)
% % length(ss.time)
% %
% % mean(b.meas)
% % mean(ss.asdr.asdr)
%
%
%
%
%
% figure
%
% % Spontd FR
%
% % Evoked FR
% ws = [1 3 5];
% wn = {'A';'C';'E'};
% for f = 1:length(fids)
%     fid = fids{f};
%
%     s = loadspk([fid '.spk']);
%     ss = SqueakySpk(fid,s.meta.fs_Hz,1,s);
%     ss.RemoveChannel(setdiff(1:64,w(ws(f),:)));
%
%     subplot(3,3,f)
%     ss.ASDR(10,[0 120])
%     xlim([0 120])
%     ylim([0 10])
%     text(20,8,[wn{f} ' pre spont.'])
%     set(gca,'XTick',[0 120 ])
%
%     subplot(3,3,f+3)
%     ss.ASDR(10,[120 240])
%     xlim([120 240])
%     ylim([0 10])
%     text(140,8,[wn{f} ' evoke.'])
%     set(gca,'XTick',[120 240])
%
%     subplot(3,3,f+6)
%     ss.ASDR(10,[240 360])
%     xlim([240 360])
%     ylim([0 10])
%     text(260,8,[wn{f} ' post spont.'])
%     set(gca,'XTick',[240 360])
%
%
% end
%
% export_fig('-pdf','-transparent',fid(1:end-6))
