VMT_PlotPlanViewQuivers

PURPOSE ^

This function plots a plan view of the measurement region with a vector

SYNOPSIS ^

function [PVdata,fig_planview_handle,log_text] = VMT_PlotPlanViewQuivers(z,A,V,Map,drng,ascale,QuiverSpacing,pvsmwin,pshore,plot_english,varargin)

DESCRIPTION ^

 This function plots a plan view of the measurement region with a vector
 field of depth averaged velocity for each processed mean cross section.

 ASC version is for plotting ASCII loaded data. 9/2/09 (also has new
 pvsmwin input for the filter window)

 Added DOQQ plotting capabilities (PRJ, 6-23-10)
 Added english units option
 Added vector data output option in GUI

 User Notes:

 1. Supply z, A, V, and Map for plotting a single mean cross section
 2. Leave z, A, V, and Map blank (i.e. [],[],[],[]) to load multiple,
   (preprocessed and saved) cross sections. In this case, user must supply
   a cell array of filenames, and a path
 3. Leave drng blank (i.e. []) for full depth means or specify
   the a 2 component vector of depths in meters (drng = [ dupper dlower])
   of the depth range to average and plot

 (adapted from code by J. Czuba)

 P.R. Jackson, USGS, 12-10-08 
 Last modified: F.L. Engel, USGS, 2/20/2013

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [PVdata,fig_planview_handle,log_text] = VMT_PlotPlanViewQuivers(z,A,V,Map,drng,ascale,QuiverSpacing,pvsmwin,pshore,plot_english,varargin)
0002 % This function plots a plan view of the measurement region with a vector
0003 % field of depth averaged velocity for each processed mean cross section.
0004 %
0005 % ASC version is for plotting ASCII loaded data. 9/2/09 (also has new
0006 % pvsmwin input for the filter window)
0007 %
0008 % Added DOQQ plotting capabilities (PRJ, 6-23-10)
0009 % Added english units option
0010 % Added vector data output option in GUI
0011 %
0012 % User Notes:
0013 %
0014 % 1. Supply z, A, V, and Map for plotting a single mean cross section
0015 % 2. Leave z, A, V, and Map blank (i.e. [],[],[],[]) to load multiple,
0016 %   (preprocessed and saved) cross sections. In this case, user must supply
0017 %   a cell array of filenames, and a path
0018 % 3. Leave drng blank (i.e. []) for full depth means or specify
0019 %   the a 2 component vector of depths in meters (drng = [ dupper dlower])
0020 %   of the depth range to average and plot
0021 %
0022 % (adapted from code by J. Czuba)
0023 %
0024 % P.R. Jackson, USGS, 12-10-08
0025 % Last modified: F.L. Engel, USGS, 2/20/2013
0026 
0027 
0028 warning off
0029 % disp('Plotting Plan View with Depth-Averaged Velocity Vectors...')
0030 
0031 %% User Input
0032 
0033 %QuiverSpacing   = 15;  %Plots a quiver every X emsembles
0034 %ascale          = 1.5; %Set to 1 for autoscaling and other values for increased or decreased arrow lengths
0035 if exist('plot_english')==0
0036     plot_english  = 0;
0037     disp('No units specified, plotting in metric units by default')
0038 end
0039 
0040 %% Plot Quivers on Area Map
0041 
0042 if isnan(drng)
0043     drng = [];
0044 end
0045 
0046 windowSize      = pvsmwin; %Size of window for running average in smoothing of mean vel vectors (set in GUI)
0047 
0048 % See if PLOT 1 exists already, if so clear the figure
0049 fig_planview_handle = findobj(0,'name','Plan View Map');
0050 
0051 if ~isempty(fig_planview_handle) &&  ishandle(fig_planview_handle)
0052     figure(fig_planview_handle); clf
0053 else
0054     fig_planview_handle = figure('name','Plan View Map'); clf
0055     %set(gca,'DataAspectRatio',[1 1 1],'PlotBoxAspectRatio',[1 1 1])
0056 end
0057 
0058 % Turn off the menu bar, and keep only specified tools
0059 disableMenuBar(fig_planview_handle)
0060 
0061 % Parse optional arguements
0062 minrng       = [];
0063 maxrng       = [];
0064 usecolormap  = [];
0065 cptfullfile  = [];
0066 if ~isempty(varargin)
0067     if iscell(varargin{1})
0068         mapmult = true;
0069         zf = length(varargin{1});
0070     else
0071         mapmult = false;
0072         zf = 1;
0073     end
0074     zPathName = varargin{2};
0075     zFileName = varargin{1};
0076     
0077     
0078     % Parse VMT_GraphicsControl arguements
0079     if size(varargin,2) > 2 % min and max specified at least
0080         minrng       = varargin{3};
0081         maxrng       = varargin{4};
0082         usecolormap  = varargin{5};
0083         cptfullfile  = varargin{6};
0084     end
0085 else
0086     mapmult = false;
0087     zf = 1;
0088 end
0089 
0090 if mapmult
0091     hwait = waitbar(0,'Plotting multiple input files, please be patient...');
0092 end
0093 for n=1:zf
0094     if mapmult
0095         eval(['load (' sprintf( '\''' ) fullfile(zPathName,zFileName{n}) sprintf( '\''' ) ')']);
0096         waitbar(n/(zf+1),hwait)
0097     end
0098     
0099     if ~isempty(drng)
0100         indx = find(V.mcsDepth(:,1) < drng(1) | V.mcsDepth(:,1) > drng(2));
0101         
0102         %Set all data outside depth range to nan
0103         V.mcsX(indx,:) = nan;
0104         V.mcsY(indx,:) = nan;
0105         V.mcsEast(indx,:) = nan;
0106         V.mcsNorth(indx,:) = nan;
0107         
0108 %         if n == 1
0109 %             if plot_english
0110 %                 disp(['Plotting Depth Range ' num2str(drng(1)*3.281) 'ft to ' num2str(drng(2)*3.281) 'ft'])
0111 %             else
0112 %                 disp(['Plotting Depth Range ' num2str(drng(1)) 'm to ' num2str(drng(2)) 'm'])
0113 %             end
0114 %         end
0115         
0116         clear indx
0117     end
0118     
0119    %Compute mean positions
0120    V.mcsX1 = nanmean(V.mcsX,1);
0121    V.mcsY1 = nanmean(V.mcsY,1);
0122     
0123    if 0; %Compute the depth averaged velocity (straight arithmetic mean--old method)
0124         V.mcsEast1 = nanmean(V.mcsEast,1);
0125         V.mcsNorth1 = nanmean(V.mcsNorth,1);
0126     
0127    else %Compute the depth (or layer) averaged velocity (new method)
0128         V.mcsEast1  = VMT_LayerAveMean(V.mcsDepth,V.mcsEast);
0129         V.mcsNorth1 = VMT_LayerAveMean(V.mcsDepth,V.mcsNorth);
0130    end
0131     
0132 
0133     %Smooth using a running mean defined by WindowSize (averages
0134     %'2*windowsize+1' ensembles together (centered on node (boxcar filter))
0135     if windowSize == 0
0136         V.mcsX1sm     = V.mcsX1;
0137         V.mcsY1sm     = V.mcsY1;
0138         V.mcsEast1sm  = V.mcsEast1;
0139         V.mcsNorth1sm = V.mcsNorth1;
0140     else
0141 %         V.mcsX1sm     = filter(ones(1,windowSize)/windowSize,1,V.mcsX1);
0142 %         V.mcsY1sm     = filter(ones(1,windowSize)/windowSize,1,V.mcsY1);
0143 %         V.mcsEast1sm  = filter(ones(1,windowSize)/windowSize,1,V.mcsEast1);
0144 %         V.mcsNorth1sm = filter(ones(1,windowSize)/windowSize,1,V.mcsNorth1);
0145         
0146         V.mcsEast1sm  = nanmoving_average(V.mcsEast1,windowSize);  %added 1-7-10, prj
0147         V.mcsNorth1sm = nanmoving_average(V.mcsNorth1,windowSize);
0148         V.mcsX1sm     = V.mcsX1;
0149         V.mcsY1sm     = V.mcsY1;
0150     end
0151     
0152     for zi = 1 : z
0153         Mag(:,:,zi) = A(zi).Comp.mcsMag(:,:);
0154         %Mag(:,:,zi) = A(zi).Clean.vMag(:,:);
0155     end
0156     numavg = nansum(~isnan(Mag),3);
0157     numavg(numavg==0) = NaN;
0158     enscnt = nanmean(numavg,1);
0159     [I,J] = ind2sub(size(enscnt),find(enscnt>=1));  %Changed to 1 from 2 (PRJ, 12-12-08)
0160 
0161     et = windowSize+J(1):QuiverSpacing:J(end);  
0162     
0163     % M(2*n-1,1)=V.mcsX(1,1);
0164     % M(2*n,1)=V.mcsX(1,end);
0165     % M(2*n-1,2)=V.mcsY(1,1);
0166     % M(2*n,2)=V.mcsY(1,end);
0167     %
0168     % idx=strfind(zFileName{n},'.');
0169     % namecut=zFileName{1,n}(2:idx(1)-1);
0170     %
0171     % pwr_kml(namecut,latlon);
0172     
0173     if n == 1
0174         toquiv(1:493,1:4)=NaN;
0175         lenp = 0;
0176     end
0177     
0178     len = length(V.mcsX1sm(1,et));
0179 
0180     toquiv(lenp+1:len+lenp,1)=V.mcsX1sm(1,et);
0181     toquiv(lenp+1:len+lenp,2)=V.mcsY1sm(1,et);
0182     toquiv(lenp+1:len+lenp,3)=nanmean(V.mcsEast1sm(:,et),1);
0183     toquiv(lenp+1:len+lenp,4)=nanmean(V.mcsNorth1sm(:,et),1);
0184 
0185     lenp = length(V.mcsX1sm(1,et))+lenp;
0186 
0187     % quiverc2wcmap(V.mcsX1sm(1,et),V.mcsY1sm(1,et),nanmean(V.mcsEast1sm(:,et),1),nanmean(V.mcsNorth1sm(:,et),1),0);
0188     %quiverc(V.mcsX1sm(1,et),V.mcsY1sm(1,et),nanmean(V.mcsEast1sm(:,et),1),nanmean(V.mcsNorth1sm(:,et),1),0)
0189     %     quiver(V.mcsX1sm(1,et),V.mcsY1sm(1,et),nanmean(V.mcsEast1sm(:,et),1),nanmean(V.mcsNorth1sm(:,et),1),0)
0190     
0191     if mapmult
0192         clear A V z Mag numavg enscnt I J latlon idx namecut
0193     end
0194 end
0195 vr = sqrt(toquiv(:,3).^2+toquiv(:,4).^2);
0196 
0197 % Save only the good data  %Added 3-28-12 PRJ
0198 gdindx = find(~isnan(vr));
0199 toquiv = toquiv(gdindx,:);
0200 
0201 % Take care of waitbar if used
0202 if exist('hwait','var') && ishandle(hwait)
0203     waitbar(1,hwait)
0204     delete(hwait)
0205 end
0206 
0207 figure(fig_planview_handle); hold on
0208 % if pdoqq
0209 %     VMT_OverlayDOQQ
0210 % end
0211 % if pshore
0212 %     if ~isempty(Map)
0213 %         VMT_PlotShoreline(Map)
0214 %     end
0215 % end
0216 %quiverc2wcmap(toquiv(:,1),toquiv(:,2),toquiv(:,3),toquiv(:,4),0,vr,1);
0217 if plot_english
0218     %quiverc(toquiv(:,1),toquiv(:,2),toquiv(:,3)*0.03281,toquiv(:,4)*0.03281,ascale);  %*0.03281 to go from cm/s to ft/s
0219     quiverc(toquiv(:,1),toquiv(:,2),toquiv(:,3)*0.03281,toquiv(:,4)*0.03281,ascale,...
0220         minrng,...
0221         maxrng,...
0222         usecolormap,...
0223         cptfullfile);
0224     colorbar%('FontSize',16,'XColor','w','YColor','w');
0225     if sum(~isnan(vr)) == 0
0226         errordlg('No Data in Specified Depth Range','Plotting Error');
0227     end
0228     log_text = {sprintf('   DAV range: %6.3f to %6.3f ft/s', nanmin(vr)*0.03281,nanmax(vr)*0.03281)};
0229     %caxis([nanmin(vr*0.03281) nanmax(vr*0.03281)])  %resets the color bar axis from 0 to 64 to span the velocity mag range
0230     % Reset the color bar axis from 0 to 64 to span the velocity mag range
0231     if ~isempty(minrng)
0232         caxis([minrng maxrng])  
0233     else
0234         caxis([nanmin(vr*0.03281) nanmax(vr*0.03281)])
0235     end
0236     if ~isempty(drng)
0237         title({'Depth-Averaged Velocities (ft/s)'; ['Averaged over depths ' num2str(drng(1)*3.281) 'ft to ' num2str(drng(2)*3.281) 'ft']})%,'Color','w');
0238     else
0239         title('Depth-Averaged Velocities (ft/s)')%,'Color','w');
0240     end
0241 else  %plot in metric units
0242     %quiverc(toquiv(:,1),toquiv(:,2),toquiv(:,3),toquiv(:,4),ascale);
0243     quiverc(toquiv(:,1),toquiv(:,2),toquiv(:,3),toquiv(:,4),ascale,...
0244         minrng,...
0245         maxrng,...
0246         usecolormap,...
0247         cptfullfile);
0248     colorbar%('FontSize',16,'XColor','w','YColor','w');
0249     if sum(~isnan(vr)) == 0
0250         errordlg('No Data in Specified Depth Range','Plotting Error');
0251     end
0252     log_text = {sprintf('   DAV range: %6.3f to %6.3f m/s', nanmin(vr),nanmax(vr))};
0253     
0254     % Reset the color bar axis from 0 to 64 to span the velocity mag range
0255     if ~isempty(minrng)
0256         caxis([minrng maxrng])  
0257     else
0258         caxis([nanmin(vr) nanmax(vr)])
0259     end
0260     
0261     if ~isempty(drng)
0262         title({'Depth-Averaged Velocities (cm/s)'; ['Averaged over depths ' num2str(drng(1)) 'm to ' num2str(drng(2)) 'm']})%,'Color','w');
0263     else
0264         title('Depth-Averaged Velocities (cm/s)')%,'Color','w');
0265     end
0266 end
0267 
0268 xlabel('UTM Easting (m)')
0269 ylabel('UTM Northing (m)')
0270 figure(fig_planview_handle); box on
0271 %set(gcf,'Color',[0 0 0]) %[0.2 0.2 0.2]
0272 %set(gca,'Color',[0.8,0.733,0.533]) %[0.3 0.3 0.3]
0273 set(gca,'DataAspectRatio',[1 1 1],'PlotBoxAspectRatio',[1 1 1])
0274 set(gca,'TickDir','out')
0275 
0276 % Format the ticks for UTM and allow zooming and panning
0277 ticks_format('%6.0f','%8.0f'); %formats the ticks for UTM
0278 hdlzm = zoom;
0279 set(hdlzm,'ActionPostCallback',@mypostcallback_zoom);
0280 set(hdlzm,'Enable','on');
0281 hdlpn = pan;
0282 set(hdlpn,'ActionPostCallback',@mypostcallback_pan);
0283 set(hdlpn,'Enable','on');
0284 
0285 % Display the figure
0286 % Hide the figure until the end (this makes the rendering look better)
0287 %set(fig_planview_handle,'visible','on')
0288 
0289 %% Save the planview data as output and to an *.anv file with spacing and smoothing (for iRiC)
0290 outmat = zeros(size(toquiv,1),5);
0291 outmat(:,1:2) = toquiv(:,1:2);  % In metric units
0292 outmat(:,4:5) = toquiv(:,3:4)./100;  %Converts cm/s to m/s
0293 
0294 %Screen to ID missing data
0295 goodrows = [];
0296 for i = 1:length(outmat)
0297     rowsum = sum(isnan(outmat(i,:)));
0298     if rowsum == 0
0299         goodrows = [goodrows; i];
0300     end
0301 end
0302 
0303 PVdata.outmat = outmat(goodrows,:)';
0304 
0305 function mypostcallback_zoom(obj,evd)
0306 ticks_format('%6.0f','%8.0f'); %formats the ticks for UTM (when zooming)
0307 
0308 function mypostcallback_pan(obj,evd)
0309 ticks_format('%6.0f','%8.0f'); %formats the ticks for UTM (when panning)
0310 
0311

Generated on Thu 21-Aug-2014 10:40:31 by m2html © 2005