%% Update this with map, etc.....from matlab figures file!!!
% this code is not optimized, but it works

%% get calcium above baseline
CaVidOr = aboveBaseline(orig,1);
CaVidUnw = aboveBaseline(unwarped,1);


%% get calcium intensity at regions
Ca2Or  = getIntensity(CaVidOr,preComp);
Ca2Unw = getIntensity(CaVidUnw,preComp);
% set starting values equal for comparison
Ca2Unw = Ca2Unw + (Ca2Or(:,1)-Ca2Unw(:,1));
%% get dilation
J = getJ(mechanics);
[regions, frames] = size(J);
J = 1-J; % turn into contraction

%% apply smoothing
J = sgolayfilt(J',3,11)';

%% plot results
xn = round(linspace(1,regions,25));
num = numel(xn);
rc = ceil(sqrt(num));
for n = 1:num
    figure(1)
    subplot(rc,rc,n)
    plot(1:frames,Ca2Or(xn(n),:), 1:frames,Ca2Unw(xn(n),:))
    grid
     if n == 1, legend('orig','unwarped'), end
    figure(2)
    subplot(rc,rc,n)
    plot(Ca2Unw(xn(n),:), J(xn(n),:))
    xlabel('Ca2+')
    ylabel('contraction')
    %grid
end

figure(3)
subplot(2,1,1)
Javg = mean(J,1);
Cavg = mean(Ca2,1);
plot(Cavg(:),Javg(:))
xlabel('calcium')
ylabel('contraction')
subplot(2,1,2)
plot(Cavg), hold on
plot(Javg), hold off
legend('Ca','Contraction')
