VMT_SmoothVar

PURPOSE ^

This routine smooths all processed variables in V struct. By default is

SYNOPSIS ^

function [V] = VMT_SmoothVar(V,hwin,vwin)

DESCRIPTION ^

 This routine smooths all processed variables in V struct. By default is
 uses smooth2a (FEX), but can also use nanmoving_average2 (FEX).
 
 Updated 9-30-10 to include the smooth2a routine with user selection.
 Updated 12-21-2012 to smooth all variables. This is necessary to separate
 plotting from computations. FLE

 P.R. Jackson, USGS, 8/31/09
 Last modified: F.L. Engel, USGS, 12/21/2012

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [V] = VMT_SmoothVar(V,hwin,vwin)
0002 % This routine smooths all processed variables in V struct. By default is
0003 % uses smooth2a (FEX), but can also use nanmoving_average2 (FEX).
0004 %
0005 % Updated 9-30-10 to include the smooth2a routine with user selection.
0006 % Updated 12-21-2012 to smooth all variables. This is necessary to separate
0007 % plotting from computations. FLE
0008 %
0009 % P.R. Jackson, USGS, 8/31/09
0010 % Last modified: F.L. Engel, USGS, 12/21/2012
0011 
0012 %disp(['Smoothing Data '])
0013 warning off
0014 %% Smooth
0015 use_smooth2a = 1; %Set to 1 to use smooth2a.m for smoothing else set to 0 to use nanmoving_average2.m
0016 % Set default to smooth2a 8-7-12 to overcome issues
0017 % with corner values not getting averaged in
0018 % nanmoving_average2 (really affected backscatter)
0019 if V.probeType == 'RG'
0020     var ={...
0021         'streamwise';...
0022         'transverse';...
0023         'mag';...
0024         'primary_zsd';...
0025         'secondary_zsd';...
0026         'primary_roz';...
0027         'secondary_roz';...
0028         'primary_roz_x';...
0029         'primary_roz_y';...
0030         'secondary_roz_x';...
0031         'secondary_roz_y';...
0032         'backscatter';...
0033         'flowangle';...
0034         };
0035 elseif V.probeType == 'M9'
0036     var ={...
0037         'streamwise';...
0038         'transverse';...
0039         'mag';...
0040         'primary_zsd';...
0041         'secondary_zsd';...
0042         'primary_roz';...
0043         'secondary_roz';...
0044         'primary_roz_x';...
0045         'primary_roz_y';...
0046         'secondary_roz_x';...
0047         'secondary_roz_y';...
0048         ...'backscatter';...
0049         'flowangle';...
0050         };
0051 elseif V.probeType == 'RR'
0052     var ={...
0053         'streamwise';...
0054         'transverse';...
0055         'mag';...
0056         'primary_zsd';...
0057         'secondary_zsd';...
0058         'primary_roz';...
0059         'secondary_roz';...
0060         'primary_roz_x';...
0061         'primary_roz_y';...
0062         'secondary_roz_x';...
0063         'secondary_roz_y';...
0064         'backscatter';...
0065         'flowangle';...
0066         };
0067 end
0068 % Fr  - Window semi-length in the rows.
0069 Fr = vwin; %
0070 % Fc  - Window semi-length in the columns.
0071 Fc = hwin; %
0072 
0073 if Fr == 0 & Fc ~= 0
0074     errordlg('Both Vertical Smoothing Window and Horizontal Smoothing Window must be set to zero to turn off smoothing. Smoothing cannot be turned off in one direction only.' );
0075 elseif Fr ~= 0 & Fc == 0
0076     errordlg('Both Vertical Smoothing Window and Horizontal Smoothing Window must be set to zero to turn off smoothing. Smoothing cannot be turned off in one direction only.');
0077 end
0078 
0079 for i = 1:numel(var)
0080     switch var{i}
0081         case{'streamwise'}  %Smooths the streamwise velocity
0082             if Fr == 0 & Fc == 0
0083                 V.uSmooth = V.u;
0084             else
0085                 if use_smooth2a
0086                     [V.uSmooth] = smooth2a(V.u,Fr,Fc);
0087                 else
0088                     [V.uSmooth] = nanmoving_average2(V.u,Fr,Fc);
0089                 end
0090             end
0091             
0092         case{'transverse'} %Smooths the transverse velocity
0093             if Fr == 0 & Fc == 0
0094                 V.vSmooth = V.v;
0095             else
0096                 if use_smooth2a
0097                     [V.vSmooth] = smooth2a(V.v,Fr,Fc);
0098                 else
0099                     [V.vSmooth] = nanmoving_average2(V.v,Fr,Fc);
0100                 end
0101             end
0102         case{'mag'} %Smooths the velocity magnitude
0103             if Fr == 0 & Fc == 0
0104                 V.mcsMagSmooth = V.mcsMag;
0105             else
0106                 if use_smooth2a
0107                     %[V.mcsMagSmooth] = smooth2a(V.mcsMag,Fr,Fc);  %Changed to
0108                     %use the components to smooths and then recompute. (PRJ,
0109                     %3-21-11)
0110                     V.mcsEastSmooth  = smooth2a(V.mcsEast,Fr,Fc);
0111                     V.mcsNorthSmooth = smooth2a(V.mcsNorth,Fr,Fc);
0112                 else
0113                     %[V.mcsMagSmooth] = nanmoving_average2(V.mcsMag,Fr,Fc);
0114                     V.mcsEastSmooth  = nanmoving_average2(V.mcsEast,Fr,Fc);
0115                     V.mcsNorthSmooth = nanmoving_average2(V.mcsNorth,Fr,Fc);
0116                 end
0117                 [V.mcsMagSmooth] = sqrt(V.mcsEastSmooth .^2 + V.mcsNorthSmooth.^2);
0118             end
0119         case{'primary_zsd'}  %Smooths the primary velocity with zero secondary discharge definition
0120             if Fr == 0 & Fc == 0
0121                 V.vpSmooth = V.vp;
0122             else
0123                 if use_smooth2a
0124                     [V.vpSmooth] = smooth2a(V.vp,Fr,Fc);
0125                 else
0126                     [V.vpSmooth] = nanmoving_average2(V.vp,Fr,Fc);
0127                 end
0128             end
0129         case{'secondary_zsd'} %Smooths the secondary velocity with zero secondary discharge definition
0130             if Fr == 0 & Fc == 0
0131                 V.vsSmooth = V.vs;
0132             else
0133                 if use_smooth2a
0134                     [V.vsSmooth] = smooth2a(V.vs,Fr,Fc);
0135                 else
0136                     [V.vsSmooth] = nanmoving_average2(V.vs,Fr,Fc);
0137                 end
0138             end
0139         case{'primary_roz'}  %Smooths the primary velocity with Rozovskii definition
0140             if Fr == 0 & Fc == 0
0141                 V.Roz.upSmooth = V.Roz.up;
0142             else
0143                 if use_smooth2a
0144                     [V.Roz.upSmooth] = smooth2a(V.Roz.up,Fr,Fc);
0145                 else
0146                     [V.Roz.upSmooth] = nanmoving_average2(V.Roz.up,Fr,Fc);
0147                 end
0148             end
0149         case{'secondary_roz'} %Smooths the secondary velocity with Rozovskii definition
0150             if Fr == 0 & Fc == 0
0151                 V.Roz.usSmooth = V.Roz.us;
0152             else
0153                 if use_smooth2a
0154                     [V.Roz.usSmooth] = smooth2a(V.Roz.us,Fr,Fc);
0155                 else
0156                     [V.Roz.usSmooth] = nanmoving_average2(V.Roz.us,Fr,Fc);
0157                 end
0158             end
0159         case{'primary_roz_x'}  %Smooths the primary velocity with Rozovskii definition (downstream component)
0160             if Fr == 0 & Fc == 0
0161                 V.Roz.upxSmooth = V.Roz.upx;
0162             else
0163                 if use_smooth2a
0164                     [V.Roz.upxSmooth] = smooth2a(V.Roz.upx,Fr,Fc);
0165                 else
0166                     [V.Roz.upxSmooth] = nanmoving_average2(V.Roz.upx,Fr,Fc);
0167                 end
0168             end
0169         case{'primary_roz_y'}  %Smooths the primary velocity with Rozovskii definition (cross-stream component)
0170             if Fr == 0 & Fc == 0
0171                 V.Roz.upySmooth = V.Roz.upy;
0172             else
0173                 if use_smooth2a
0174                     [V.Roz.upySmooth] = smooth2a(V.Roz.upy,Fr,Fc);
0175                 else
0176                     [V.Roz.upySmooth] = nanmoving_average2(V.Roz.upy,Fr,Fc);
0177                 end
0178             end
0179         case{'secondary_roz_x'} %Smooths the secondary velocity with Rozovskii definition (downstream component)
0180             if Fr == 0 & Fc == 0
0181                 V.Roz.usxSmooth = V.Roz.usx;
0182             else
0183                 if use_smooth2a
0184                     [V.Roz.usxSmooth] = smooth2a(V.Roz.usx,Fr,Fc);
0185                 else
0186                     [V.Roz.usxSmooth] = nanmoving_average2(V.Roz.usx,Fr,Fc);
0187                 end
0188             end
0189         case{'secondary_roz_y'} %Smooths the secondary velocity with Rozovskii definition (cross-stream component)
0190             if Fr == 0 & Fc == 0
0191                 V.Roz.usySmooth = V.Roz.usy;
0192             else
0193                 if use_smooth2a
0194                     [V.Roz.usySmooth] = smooth2a(V.Roz.usy,Fr,Fc);
0195                 else
0196                     [V.Roz.usySmooth] = nanmoving_average2(V.Roz.usy,Fr,Fc);
0197                 end
0198             end
0199         case{'backscatter'} %Smooths the backscatter
0200             if Fr == 0 & Fc == 0
0201                 V.mcsBackSmooth = V.mcsBack;
0202             else
0203                 if use_smooth2a
0204                     [V.mcsBackSmooth] = smooth2a(V.mcsBack,Fr,Fc);
0205                 else
0206                     [V.mcsBackSmooth] = nanmoving_average2(V.mcsBack,Fr,Fc);
0207                 end
0208                 
0209             end
0210         case{'flowangle'} %Smooths the flow direction
0211             if Fr == 0 & Fc == 0
0212                 V.mcsDirSmooth = V.mcsDir;
0213             else
0214                 %Must smooth velocity components and then compute flow direction
0215                 if use_smooth2a
0216                     V.mcsNorthSmooth  = smooth2a(V.mcsNorth,Fr,Fc);
0217                     V.mcsEastSmooth   = smooth2a(V.mcsEast,Fr,Fc);
0218                 else
0219                     V.mcsNorthSmooth  = nanmoving_average2(V.mcsNorth,Fr,Fc);
0220                     V.mcsEastSmooth   = nanmoving_average2(V.mcsEast,Fr,Fc);
0221                 end
0222                 V.mcsDirSmooth    = 90 - (atan2(V.mcsNorthSmooth, V.mcsEastSmooth))*180/pi; %Compute the atan from the velocity componentes, convert to radians, and rotate to north axis
0223                 qindx = find(V.mcsDirSmooth < 0);
0224                 if ~isempty(qindx)
0225                     V.mcsDirSmooth(qindx) = V.mcsDirSmooth(qindx) + 360;  %Must add 360 deg to Quadrant 4 values as they are negative angles from the +y axis
0226                 end
0227             end
0228             %     case{'vorticity_vw'} %Smooths the vorticity using U,V
0229             %         if Fr == 0 & Fc == 0
0230             %             V.vort_uv_smooth = V.vorticity_vw;
0231             %         else
0232             %             if use_smooth2a
0233             %                 [V.vort_uv_smooth] = smooth2a(V.vorticity_vw,Fr,Fc);
0234             %             else
0235             %                 [V.vort_uv_smooth] = nanmoving_average2(V.vorticity_vw,Fr,Fc);
0236             %             end
0237             %         end
0238             %     case{'vorticity_zsd'} %Smooths the vorticity using Zero Secondary Discharge definition
0239             %         if Fr == 0 & Fc == 0
0240             %             V.vort_zsd_smooth = V.vorticity_zsd;
0241             %         else
0242             %             if use_smooth2a
0243             %                 [V.vort_zsd_smooth] = smooth2a(V.vorticity_zsd,Fr,Fc);
0244             %             else
0245             %                 [V.vort_zsd_smooth] = nanmoving_average2(V.vorticity_zsd,Fr,Fc);
0246             %             end
0247             %         end
0248             %     case{'vorticity_roz'} %Smooths the vorticity using Zero Secondary Discharge definition
0249             %         if Fr == 0 & Fc == 0
0250             %             V.vort_roz_smooth = V.vorticity_roz;
0251             %         else
0252             %             if use_smooth2a
0253             %                 [V.vort_roz_smooth] = smooth2a(V.vorticity_roz,Fr,Fc);
0254             %             else
0255             %                 [V.vort_roz_smooth] = nanmoving_average2(V.vorticity_roz,Fr,Fc);
0256             %             end
0257             %         end
0258     end
0259 end
0260 
0261 %Smooths the vertical velocity (Must always do it for inclusion into
0262 %secondary vectors)
0263 if Fr == 0 & Fc == 0
0264     V.wSmooth = V.w;
0265 else
0266     if use_smooth2a
0267         [V.wSmooth] = smooth2a(V.w,Fr,Fc);
0268     else
0269         [V.wSmooth] = nanmoving_average2(V.w,Fr,Fc);
0270     end
0271 end
0272 
0273 % Smooth error velocity also
0274 if Fr == 0 & Fc == 0
0275     V.mcsErrorSmooth = V.mcsError;
0276 else
0277     if use_smooth2a
0278         [V.mcsErrorSmooth] = smooth2a(V.mcsError,Fr,Fc);
0279     else
0280         [V.mcsErrorSmooth] = nanmoving_average2(V.mcsError,Fr,Fc);
0281     end
0282 end
0283 
0284 %% Close
0285 warning on
0286 %disp('Smoothing Completed')

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