Home > utilities > do_volume_change2.m

do_volume_change2

PURPOSE ^

Calculate the volume exposed to a given change in pH.

SYNOPSIS ^

function [summedVolume]=do_volume_change2(plotOPTS,FVCOM,startIdx)

DESCRIPTION ^

 Calculate the volume exposed to a given change in pH.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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