% plotting script for Dave Bowling
close all
clear all

load('PCAPS_deficit.mat'); 

%{
PCAPS_deficit.mat should contain:
defplot= potential temperature deficit at 10 m increments as a function of
time. This is taken as the difference between the pot. temp at 2500 m and
that at every level for each time step (3 hrs). The data comes from a
combiniation of NWS and PCAPS soundings, interpolated to a regular 3 hr
interval... the actual data sampling varies from 3-12 hours. 

datevec= matlab serial time date vector. Use as a reference for the data in
defplot

hgtvec= 10 m height increments that correspond to the data in defplot

PM= PM2.5 data for the PCAPS period. Mostly from Hawthorne elementary, but
also rose park and cottonwood for a couple of dates (see the code
below).Note that the value must be divided by 10 to get ug/m^-3

PMdates= time series that corresponds to PM data... one measurment (mean)
per MST day. -> times have been adjusted to GMT periods




%}



%% plot the whole PCAPS period deficit



f=figure(1);
clf
scrsz = get(0,'ScreenSize');

colormap((gray(10)));
set(f,'position',[scrsz(1) scrsz(2) scrsz(3) .7*scrsz(4)],'color','white')
sb=subplot(5,1,1:4);
hgtidx=find(data(:,1)==2500);
contourf(datevec,hgtvec,defplot,-50:1:50,'linestyle','none');%shading flat;
hold on;
contour(datevec,hgtvec,defplot,[-7 -7],'-k','linewidth',2); %contour around events
caxis([-25 0]);
ylim([1320 2500])
datetick('x','mm/dd');
sdate=datenum(2010,11,28,12,00,00);
edate=datenum(2011,02,08,00,00,00);
spandate=edate-sdate;
hold on
xlim([sdate edate]);
tics=get(gca,'xtick');


%create IOP demarcations
for IOP=1:10
    if IOP ==1
        starter=datenum(2010,11,29,20,00,00);
        ender=datenum(2010,12,07,02,00,00);
        hv=vline(starter,'k',['IOP ' num2str(IOP)]);
        plot([starter ender],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',2,'color','w')
        set(hv,'linestyle','none')
        plot([starter-.1 starter-.1],[2220 2180],'k','linewidth',4);
        plot([ender+.1 ender+.1],[2220 2180],'k','linewidth',4);

    elseif IOP==2
        starter=datenum(2010,12,7,18,00,00);
        ender=datenum(2010,12,10,15,00,00);
        hv= vline(starter,'k',['IOP ' num2str(IOP)]);   
        plot([starter ender],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',2,'color','w')
        set(hv,'linestyle','none')
        plot([starter-.1 starter-.1],[2220 2180],'k','linewidth',4);
        plot([ender+.1 ender+.1],[2220 2180],'k','linewidth',4);


    elseif IOP==3
        starter=datenum(2010,12,12,12,00,00);
        ender=datenum(2010,12,14,21,00,00);
        hv=vline(starter,'k',['IOP ' num2str(IOP)]);
        plot([starter ender],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',2,'color','w')
        set(hv,'linestyle','none')
        plot([starter-.1 starter-.1],[2220 2180],'k','linewidth',4);
        plot([ender+.1 ender+.1],[2220 2180],'k','linewidth',4);


    elseif IOP==4
        starter=datenum(2010,12,24,00,00,00);
        ender=datenum(2010,12,27,00,00,00);
        hv=vline(starter,'k',['IOP ' num2str(IOP)]);
        plot([starter ender],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',2,'color','w')
        set(hv,'linestyle','none')
        plot([starter-.1 starter-.1],[2220 2180],'k','linewidth',4);
        plot([ender+.1 ender+.1],[2220 2180],'k','linewidth',4);


    elseif IOP==5
        starter=datenum(2011,1,1,00,00,00);
        ender=datenum(2011,1,9,12,00,00);
        hv=vline(starter,'k',['IOP ' num2str(IOP)]);
        plot([starter-.1 ender+.1],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',2,'color','w')
        set(hv,'linestyle','none')
        plot([starter-.1 starter-.1],[2220 2180],'k','linewidth',4);
        plot([ender+.1 ender+.1],[2220 2180],'k','linewidth',4);

    elseif IOP==6
        starter=datenum(2011,1,11,06,00,00);
        ender=datenum(2011,1,17,20,00,00);
        hv=     vline(starter,'k',['IOP ' num2str(IOP)]);
        plot([starter ender],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',2,'color','w')
        set(hv,'linestyle','none')
        plot([starter-.1 starter-.1],[2220 2180],'k','linewidth',4);
        plot([ender+.1 ender+.1],[2220 2180],'k','linewidth',4);

    elseif IOP==7
        starter=datenum(2011,1,20,06,00,00);
        ender=datenum(2011,1,22,12,00,00);
        hv=       vline(starter,'k',['IOP ' num2str(IOP)]);
        plot([starter ender],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',2,'color','w')
        set(hv,'linestyle','none')
        plot([starter-.1 starter-.1],[2220 2180],'k','linewidth',4);
        plot([ender+.1 ender+.1],[2220 2180],'k','linewidth',4);

    elseif IOP==8
        starter=datenum(2011,1,23,12,00,00);
        ender=datenum(2011,1,26,06,00,00);
        hv=       vline(starter,'k',['IOP ' num2str(IOP)]);
        plot([starter ender],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',2,'color','w')
        set(hv,'linestyle','none')
        plot([starter-.1 starter-.1],[2220 2180],'k','linewidth',4);
        plot([ender+.1 ender+.1],[2220 2180],'k','linewidth',4);

        %hv=vline(ender,'k--');
    elseif IOP==9
        starter=datenum(2011,1,26,12,00,00);
        ender=datenum(2011,1,31,06,00,00);
        hv=       vline((2*starter+ender)./3,'k',['IOP ' num2str(IOP)]);
        plot([starter ender],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',2,'color','w')
                set(hv,'linestyle','none')
        plot([starter-.1 starter-.1],[2220 2180],'k','linewidth',4);
        plot([ender+.1 ender+.1],[2220 2180],'k','linewidth',4);
    elseif IOP==10
        starter=datenum(2011,2,2,18,00,00);
        ender=datenum(2011,2,5,18,00,00);
        hv=vline(starter,'k',['IOP ' num2str(IOP)]);
        plot([starter ender],[2200 2200],'linewidth',8,'color','k')
        plot([starter ender],[2200 2200],'linewidth',2,'color','w')
                set(hv,'linestyle','none')
        plot([starter-.1 starter-.1],[2220 2180],'k','linewidth',4);
        plot([ender+.1 ender+.1],[2220 2180],'k','linewidth',4);
    end

end

cbh1=colorbar;
set(cbh1,'visible','off');
cbh2=colorbar;%('horizontal');
cpos=get(cbh2,'pos');
set(cbh2,'pos',[cpos(1) cpos(2)+.2 cpos(3) .4*cpos(4)]);
ylabel(cbh2,'Kelvin','Fontsize',10,'fontweight','bold');
cbh3=colorbar;
set(cbh3,'visible','off');
yticker=get(gca,'ytick');
yticker=cat(1,1320,yticker');
set(gca,'ytick',yticker);
ylabel('Altitude (m)','fontsize',15,'fontweight','bold');
set(gca,'fontsize',15,'fontweight','bold');
annotation('textbox',[sbpos(1)+.01 sbpos(2)+.8*sbpos(4) .1 .1],'string','a)','fontsize',20,'fontweight','bold','backgroundcolor','none','edgecolor','none');


bot=sbpos(2);
h2=subplot(5,1,5);
poser2=get(h2,'pos');
poser2(4)=1.4*poser2(4);
poser2(2)=bot-poser2(4);
set(h2,'pos',poser2);

% add pm data

bar(PMdates,PM./10); %units are buggered, so divided by 10 for ug/m^-3
hold on;
%subset of proxy data for days with missing data at Hawthorne
tidx=find((PMdates-(7./24)) >= datenum(2011,1,11) & (PMdates-7./24) <= datenum(2011,1,17))
hb=bar(PMdates(tidx),PM(tidx)./10);
set(hb,'facecolor',[.6 .6 .6]);
%second subset
tidx=find((PMdates-(7./24)) >= datenum(2011,2,3) & (PMdates-(7./24)) <= datenum(2011,2,4))
hb=bar(PMdates(tidx),PM(tidx)./10);
set(hb,'facecolor',[1 1 1]);



ylabel('\mug m^-3','fontsize',15,'fontweight','bold')
xlim([sdate edate]);
ticker=get(gca,'xtick');

hl=hline(35,'--k','                               NAAQS');
set(hl,'color',[.8 .8 .8],'linewidth',3);
set(gca,'yaxis','right');


set(gca,'xtick',tics,'xticklabel',datestr(tics,'mm/dd'));
cbh=colorbar;
set(cbh,'visible','off');
set(gca,'xgrid','on');
xlabel('Month/Day (UTC)','fontsize',15,'fontweight','bold')
set(gca,'fontsize',15,'fontweight','bold');
poser=get(gca,'pos');
annotation('textbox',[poser(1)+.01 poser(2)+.4*poser(4) .1 .1],'string','b)','fontsize',20,'fontweight','bold','backgroundcolor','none','edgecolor','none');

%export_fig defecit_PCAPS.png -m2.5