% plots float and modis data (chl, bbp) vs time
% plots correlation of float and modis data (chl, bbp)

% loads:
  % loads float0005Surface.mat (generated by applyCalSurface.m)  
  % modis_chl, containing satellite chl data (downloaded 01/17/08 by Peter Brickley)
  % apexModis_bb, containing satellite bb data (downloaded 01/11/08 by Peter Brickley)

% no mat files are saved

% written by E. Boss and L. Taylor, UMaine, 2006
% email: emmanuel.boss@maine.edu

close all
clear all

load float0005Surface
% float0005Surface contains date, lat, lon, P, Chl_b_corr, B_LSS_b_corr, stat

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

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

%%% get mean and median modis values within within 7.5km of float
[uu vv]=size(modis_chl_ts); % 2641x2601
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 zeros for plots
I7k_modis=find(dist_7km_mean_modis>0); % size: 301
I7kk_modis=find(dist_7km_median_modis>0); % size: 301

% correlation calculation
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 now .8435

size(float_sat_median_chl(I)); % 219

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

h=figure('Units','inches','Resize','off','position',[0 0 7.25 5.25],'paperposition',[0.5 3 7.25 5.25]); %upper right
subplot('Position',[0.65 0.58 0.25 0.35]);
loglog(float_sat_median_chl, chl_surf,'ko','markersize',5);
hold on;
% plot([0 3.5],[0 3.5],'k','LineWidth',1); %line for non log plots
plot([0.1 10],[0.1 10],'k','LineWidth',2);
hold off;
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
set(gca,'yMinorTick','off');
set(gca,'xMinorTick','off');
% set(gca,'position',[0.653 0.145 0.301 0.602]);
% xlim([0 3.5]); %for non log plots
% ylim([0 3.5]); %for non log plots
xlim([0.1 10]);
ylim([0.1 10]);
box on;
xlabel('Chlorophyll, MODIS');

%create y-axis label
annotation('textbox',[0.57 0.545 0.08 0.07587],'String',{'Chlorophyll, APEX'},'rotation',[90],'EdgeColor','none','FontName','Times New Roman','FitHeightToText','on');

figure(h); % upper left
subplot('Position',[0.1 0.58 0.43 0.35]);
plot(time_surf, chl_surf, 'ko','markersize',8,'markerfacecolor',[0.8 0.8 0.8]);
hold on;
plot(modis_date(I7kk_modis),dist_7km_median_modis(I7kk_modis),'ks','markersize',5);
plot([732910 732910],[-0.002 4],'k','LineWidth',2);
plot([732985 732985],[-0.002 4],'k','LineWidth',2);
plot(732265,3.18,'Marker','o','MarkerSize',[8],'MarkerFaceColor',[0.8 0.8 0.8],'MarkerEdgeColor','k'); % legend marker
plot(732265,2.85,'Marker','s','MarkerSize',[5],'MarkerFaceColor',[1 1 1],'MarkerEdgeColor','k'); % legend marker
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');
% xlim([732090 733250]);
tick = [732099 732464 732829 733194 733560];
set(gca,'XTick',tick);
set(gca, 'XTickLabels', datestr(tick,'dd mmm yy'));
% set(gca,'XTick',[]);
axis([732090 733250 -0.001 3.5]);
% ylabel('Chlorophyll (mg ^{-3})');

% draw legend
annotation('textbox',[0.17 0.825 0.1 0.1],'String','float samples','EdgeColor','none','FontName','Times New Roman','FitHeightToText','on');
annotation('textbox',[0.17 0.795 0.1 0.1],'String','satellite samples','EdgeColor','none','FontName','Times New Roman','FitHeightToText','on');

%write y-axis label
annotation('textbox',[0.0001 0.545 0.08 0.07587],'String',{'Chlorophyll (mg m^{-3})'},'rotation',[90],'EdgeColor','none','FontName','Times New Roman','FitHeightToText','on');

figure(h); % lower right
% subplot(2,2,4);
subplot('Position',[0.65 0.1 0.25 0.35]);
loglog(apexModis_A1_sat, apexModis_B1_float,'ko','markersize',5);
hold on;
% plot([0 0.015],[0 0.015],'k','LineWidth',1); % line for non log plots
plot([0.0005 0.05],[0.0005 0.05],'k','LineWidth',2);
hold off;
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
set(gca,'yMinorTick','off');
set(gca,'xMinorTick','off');
% set(gca,'YTick',[0 0.01]);
% set(gca,'position',[0.653 0.145 0.301 0.602]);
% xlim([0 0.015]); % for non log plots
% ylim([0 0.015]); % for non log plots
xlim([0.0005 0.05]);
ylim([0.0005 0.05]);
tick = [0.001 0.01 0.1];
set(gca,'XTick',tick);
box on;
xlabel('b_{bp}(440), MODIS');
% ylabel('b_{bp}(440), APEX');
annotation('textbox',[0.57 0.14 0.08 0.07587],'String',{'b_{bp}(440), APEX'},'rotation',[90],'EdgeColor','none','FontName','Times New Roman','FitHeightToText','on');

figure(h); % lower left
subplot('Position',[0.1 0.1 0.43 0.35]);
plot(floatDate, floatBb, 'ko','markersize',8,'markerfacecolor',[0.8 0.8 0.8]);
hold on;
plot(time_MODIS,b_bp,'ks','markersize',5);
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');
% xlim([732090 733250]);
tick = [732099 732464 732829 733194 733560];
set(gca,'XTick',tick);
set(gca, 'XTickLabels', datestr(tick,'dd mmm yy'));
axis([732090 733250 -0.00009 0.015]);
ticky = [0 0.005 0.010 0.015];
set(gca,'YTick',ticky);
set(gca, 'YTickLabels', ticky);
% ylabel('b_{bp}(440)(m^{-1})');
xlabel('Date');
% title({'Median MODIS and Float Bb','Satellite Data Within 7.5km of Float'});
annotation('textbox',[0.0001 0.14 0.08 0.07587],'String',{'b_{bp}(440) (m^{-1})'},'rotation',[90],'EdgeColor','none','FontName','Times New Roman','FitHeightToText','on');

