Home > utilities > do_ph_change_points_plot.m

do_ph_change_points_plot

PURPOSE ^

Calculate the change in the given parameter (plotOPTS.var_plot) and plot

SYNOPSIS ^

function [Plots]=do_ph_change_points_plot(plotOPTS,FVCOM,startIdx)

DESCRIPTION ^

 Calculate the change in the given parameter (plotOPTS.var_plot) and plot
 accordingly.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Plots]=do_ph_change_points_plot(plotOPTS,FVCOM,startIdx)
0002 % Calculate the change in the given parameter (plotOPTS.var_plot) and plot
0003 % accordingly.
0004 m_mappath;
0005 
0006 plotOPTS.figure=1;
0007 plotOPTS.var_plot='ph';
0008 plotOPTS.do_mesh=1; % Add the mesh?
0009 startIdx=1; %:size(FVCOM.zeta,2);
0010 
0011 plotOPTS.threshold_change=-0.2;
0012 % near bottom, but not actually the bottom since it doesn't change at all
0013 plotOPTS.nz_plot=1; 
0014 
0015 [nx,nz,ttot]=size(FVCOM.(plotOPTS.var_plot));
0016 
0017 % Check we have some of the required fields.
0018 if ~isfield(FVCOM,plotOPTS.var_plot)
0019     error('Need %s input to calculate change in %s.',plotOPTS.var_plot,plotOPTS.var_plot)
0020 end
0021 
0022 % Get the relevant time intervals
0023 if isfield(plotOPTS,'save_intervals') && isempty(plotOPTS.save_intervals)
0024     plotOPTS.save_intervals=1:length(plotOPTS.Time_record);
0025     dontSave=1;
0026 else
0027     dontSave=0;
0028 end
0029 
0030 % Get the time step (in seconds)
0031 dt=round((plotOPTS.Time_record(2)-plotOPTS.Time_record(1))*24*60*60);
0032 
0033 % Sigma layer fraction (nz*nz)
0034 sigThickness=roundn(abs(diff(FVCOM.siglev,1,2)),-5); % roundn to even values out.
0035 % Total depth (nz*ttot)
0036 totalDepth=repmat(FVCOM.h,1,size(FVCOM.zeta,2))+FVCOM.zeta;
0037 % Volume for every element for each time step
0038 cellVolume=nan(nx,nz,ttot);
0039 for ii=1:nz
0040     for jj=1:ttot
0041         % I'm pretty certain this needs to integrate for the time between
0042         % time steps, otherwise halving the output time step would halve
0043         % the exposed volume, which can't be right...
0044         % However, if we know that the threshold has been triggered n
0045         % times, we just need n times the volume, irrespective of time.
0046         % Right?
0047         cellVolume(:,ii,jj)=totalDepth(:,jj).*sigThickness(:,ii).*FVCOM.art1; %*dt;
0048     end
0049 end
0050 
0051 % Calculate the difference between the current step and the previous step.
0052 % phChange=diff(squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,:)),[],2);
0053 % Nope, get the background condition and compare against that. Depth
0054 % average if necessary.
0055 if isfield(plotOPTS,'depth_average') && plotOPTS.depth_average
0056     bgPH=squeeze(mean(FVCOM.(plotOPTS.var_plot)(:,:,startIdx),2));
0057 else
0058     bgPH=squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,startIdx));
0059 end
0060 
0061 if isfield(plotOPTS,'depth_average') && plotOPTS.depth_average
0062     % Now, for each successive time step, calculate the difference between the
0063     % current time step and the background level.
0064     phMean=squeeze(mean(FVCOM.(plotOPTS.var_plot),2));
0065     phDiff=phMean-repmat(bgPH,1,size(phMean,2));
0066 else
0067     phDiff=squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,:))-repmat(bgPH,1,size(FVCOM.(plotOPTS.var_plot),3));
0068 end
0069 
0070 % Try a cumulative difference
0071 phDiffCumulative=zeros(nx,ttot,'single');
0072 for tt=1:ttot
0073     if tt>1 && tt<ttot
0074         currpH=FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,tt);
0075         nextpH=FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,tt+1);
0076         phDiffCumulative(:,tt)=phDiffCumulative(:,tt)+(currpH-nextpH);
0077     elseif tt==1
0078         currpH=FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,tt);
0079         nextpH=FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,tt+1);
0080         phDiffCumulative(:,tt)=currpH-nextpH;
0081     end
0082 end
0083 
0084 [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
0085 
0086 foundXY=cell(1,length(plotOPTS.nz_plot));
0087 countSites=zeros(nx,1);
0088 
0089 for tt=1:ttot
0090     % Find drops greater than the threshold
0091     idx=find(phDiff(:,tt)<plotOPTS.threshold_change);
0092     if ~isempty(idx)
0093         countSites(idx)=countSites(idx)+1;
0094         foundXY{tt}.xy=[X(idx),Y(idx)];
0095     end
0096 end
0097 
0098 % Now we can use countSites to calculate the volume exposed to the change,
0099 % although this ignores the effect of the tide (because we don't know which
0100 % time step triggered the threshold condition test)
0101 totalVolume=squeeze(cellVolume(:,plotOPTS.nz_plot,1)).*countSites;
0102 
0103 % Visualise the count threshold
0104 Plots(1).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
0105     'Cdata',countSites,...
0106     'edgecolor','interp','facecolor','interp');
0107 if plotOPTS.do_mesh
0108     % plot vertices
0109     [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
0110     patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
0111         'EdgeColor',[0.6 0.6 0.6],'FaceColor','none'); hold on
0112 end
0113 colorbar
0114     
0115 figure;
0116 patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
0117     'Cdata',totalVolume/1e9,...
0118     'edgecolor','interp','facecolor','interp');
0119 if plotOPTS.do_mesh
0120     % plot vertices
0121     [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
0122     patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
0123         'EdgeColor',[0.6 0.6 0.6],'FaceColor','none'); hold on
0124 end
0125 colorbar
0126     
0127 figure;
0128 patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
0129     'Cdata',squeeze(FVCOM.ph(:,1,2)),...
0130     'edgecolor','interp','facecolor','interp');
0131 colorbar
0132 
0133 % figure(1)
0134 % subplot(2,1,1)
0135 % plot(Time_record-min(Time_record),squeeze(FVCOM.ph(1316,plotOPTS.nz_plot,:)))
0136 % subplot(2,1,2)
0137 % plot(Time_record(1:end-1)-min(Time_record),phChange(1316,:),'r')
0138 % hold on
0139 % plot(Time_record(idxAtLeak)-min(Time_record),phChange(1316,idxAtLeak),'g.')
0140 % % Add the threshold
0141 % plot([min(Time_record)-min(Time_record),max(Time_record)-min(Time_record)],[plotOPTS.threshold_change,plotOPTS.threshold_change],'k--')

Generated on Thu 19-Mar-2015 12:20:56 by m2html © 2005