% generates plots of modis and Float 0005 data
% seawifs data and code removed
% no mat files are saved

close all
clear all

load float0005Surface_dilate
% float0005Surface_dilate contains:
  % float0005SurfaceChl: [date, Chl_b_corr]

% get first reading of the day
I=find(diff(float0005SurfaceChl(:,1))>4);
time_surf=[float0005SurfaceChl(1,1);float0005SurfaceChl(I+1,1)];
chl_surf=[float0005SurfaceChl(1,2);float0005SurfaceChl(I+1,2)];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MODIS data
% get modis data
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\0005\MODIS\modis_chl_dilate'
% modis_chl_dilate contains:
  % modis_chl_ts (2116x2601) - chl data only from 06/13/04 - 01/01/07 THIS IS A 51X51 GRID
  % modisChl [date, chl] (2116x2602)
  % distgrid (2116x2601) grid of distance around float
modis_date=modisChl(:,1);

%%% get mean and median modis values within specified distances of float by way of Emmanuel's method
[uu vv]=size(modis_chl_ts); % 2116x2601
% 
% for j=1:25
%     j
%     dd=0.5+(j-1);
%     I=find(distgrid(1,:)<dd);
%     for i=1:uu
%         dist_A(i,j)=nanmean(modis_chl_ts(i,I),2);
%         dist_B(i,j)=nanmedian(modis_chl_ts(i,I),2);
%     end
% end

%%%7.5km of float
I7km_modis=find(distgrid(1,:)<7.5); 
for i=1:uu
   dist_7km_A_modis(i)=nanmean(modis_chl_ts(i,I7km_modis),2);
   dist_7km_B_modis(i)=nanmedian(modis_chl_ts(i,I7km_modis),2);
end

dist_7km_mean_modis=dist_7km_A_modis';
dist_7km_median_modis=dist_7km_B_modis';

% remove zero's from plots
I7k_modis=find(dist_7km_mean_modis>0); % size:
I7kk_modis=find(dist_7km_median_modis>0); % size:

%%%%%%%%%%%%%%%%% correlation
float_sat_median_chl=interp1(modis_date(I7kk_modis), dist_7km_median_modis(I7kk_modis), time_surf, 'linear');

I=finite(float_sat_median_chl);
A1=corrcoef(float_sat_median_chl(I), chl_surf(I)); % .8531

size(float_sat_median_chl(I)); % 208

%%%%%%%%%%%%%%%%% plots

% get bb data to put on same figure w/chl
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\0005\APEX\apexModis_bb_dilate.mat'

h=figure('Units','inches','Resize','off','position',[0 0 7.25 6],'paperposition',[0.5 3 7.25 6]);
% subplot(2,2,2); % upper right
subplot('Position',[0.65 0.55 0.25 0.35]);
scatter(float_sat_median_chl, chl_surf,'k.');
hold on;
plot([0 3.5],[0 3.5],'k','LineWidth',1)
hold off;
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
% set(gca,'position',[0.653 0.145 0.301 0.602]);
xlim([0 3.5]);
ylim([0 3.5]);
box on;
xlabel('Chlorophyll, MODIS');
ylabel('Chlorophyll, APEX');

figure(h); % upper left
% subplot(2,2,1);
subplot('Position',[0.1 0.55 0.43 0.35]);
plot(time_surf, chl_surf, 'bo');
hold on;
plot(modis_date(I7kk_modis),dist_7km_median_modis(I7kk_modis),'k*');
plot([732910 732910],[-0.002 4],'k','LineWidth',2)
plot([732985 732985],[-0.002 4],'k','LineWidth',2)
hold off;
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
% set(gca,'position',[0.07 0.145 0.51 0.602]);
set(gca,'XTick',[732115 732480 732850 733215]);
set(gca,'XTick',[]);
% datetick(gca,'x','mmmyy','keepticks');
axis([min(time_surf-1) max(time_surf) 0 3.5]);
ylabel('Chlorophyll [mg ^{-3}]');
% legend('Float 0005','MODIS');
% title({'Median MODIS and Float Surface Chlorophyll','Satellite Data Within 7.5km of Float'});

figure(h); % lower right
% subplot(2,2,4);
subplot('Position',[0.65 0.1 0.25 0.35]);
scatter(apexModis_A1_sat, apexModis_B1_float,'k.');
hold on;
plot([0 0.015],[0 0.015],'k','LineWidth',1)
hold off;
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
% set(gca,'YTick',[0 0.01]);
% set(gca,'position',[0.653 0.145 0.301 0.602]);
xlim([0 0.015]);
ylim([0 0.015]);
box on;
xlabel('b_{bp}(440), MODIS');
ylabel('b_{bp}(440), APEX');

figure(h); % lower left
% subplot(2,2,3);
subplot('Position',[0.1 0.1 0.43 0.35]);
plot(floatDate, floatBb, 'bo');
hold on;
plot(time_MODIS,b_bp,'k*');
plot([732910 732910],[-0.002 0.015],'k','LineWidth',2)
plot([732985 732985],[-0.002 0.015],'k','LineWidth',2)
hold off
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
% set(gca,'position',[0.07 0.145 0.51 0.602]);
set(gca,'XTick',[732115 732480 732850 733215]);
datetick(gca,'x','mmmyy','keepticks');
axis([min(floatDate-1) max(floatDate) -0.001 0.015]);
ylabel('b_{bp}(440)');
legend('Float 0005','MODIS');
% title({'Median MODIS and Float Bb','Satellite Data Within 7.5km of
% Float'});