


Plot an FVCOM field. This is somewhat similar to plot_field.m but is for
postprocessing/viewing. It looks for the nv field included in fvcom
output files. This function runs an animation if the field includes more
than one time steps.
plot_fvcom_field(Mobj, PlotField, 'fid', figure_id, 'cli', colour_lims, 'gif',
filename, 'axi', axis_range, 'pll', 'grd', colour);
INPUT
Mobj = matlab mesh object with the following fields:
- lon, lat, x, y = nodal positions (spherical and/or cartesian)
- nv, tri = connectivity table (called either nv or tri)
- [optional] time = Modified Julian Day time series
PlotField = vertex-based field to plot
[optional] fid = the fid of the figure to plot the field in - specify figure id
[optional] cli = the colour limits to use - specify the limits
[optional] gif = make an animated gif - specify filename
[optional] axi = the axis - specify axis range
[optional] pll = the axis
[optional] grd = add gridlines - specify colour
[optional] tit = add title - specify text
[optional] leg = add legend - specify text as a cell array
[optional] qui = add quiver vectors - specify a structure with the quiver information in (see examples)
EXAMPLE USAGE
plot_fvcom_field(Mobj, Mobj.zeta, 'fid', 1, 'cli', [0 100], 'gif', 'animation.gif', 'axi', [60000 70000 40000 50000])
Quiver vecotor example 1 (plot every other depth average velocity vector on unstructured grid):
Q.X = PFOW.lonc(1:15:end);
Q.Y = PFOW.latc(1:15:end);
Q.U = PFOW.ua(1:15:end,:);
Q.V = PFOW.va(1:15:end,:);
plot_fvcom_field(PFOW, PFOW.ua(:,1:13), 'pll', 'qui', Q)
Quiver vecotor example 2 (include vecotrs on an interpolated regular grid):
Q.x = -4:0.01:-2;
Q.y = 58:0.01:59;
[Q.X1, Q.Y1] = meshgrid(Q.x, Q.y);
Q.X = Q.X1(:); Q.Y = Q.Y1(:);
Only use data from within the region of interpolation
I = PFOW.lonc>Q.x(1) & PFOW.lonc<Q.x(end) & PFOW.latc>Q.y(1) & PFOW.latc<Q.y(end);
for tt=1:13
Fx = scatteredInterpolant(double(PFOW.lonc(I)), double(PFOW.latc(I)), double(PFOW.ua(I,tt)));
Fy = scatteredInterpolant(double(PFOW.lonc(I)), double(PFOW.latc(I)), double(PFOW.va(I,tt)));
Q.U(:,tt) = Fx(Q.X, Q.Y);
Q.V(:,tt) = Fy(Q.X, Q.Y);
end
plot_fvcom_field(PFOW, PFOW.ua(:,1:13), 'pll', 'qui', Q)
Author(s)
Rory O'Hara Murray (Marine Scotland Science)
Developments:
2014-05-22: Changed the way fig id is checked, not using 'exist' anymore.
2014-08-15: Added the axis command in

0001 % Plot an FVCOM field. This is somewhat similar to plot_field.m but is for 0002 % postprocessing/viewing. It looks for the nv field included in fvcom 0003 % output files. This function runs an animation if the field includes more 0004 % than one time steps. 0005 % 0006 % plot_fvcom_field(Mobj, PlotField, 'fid', figure_id, 'cli', colour_lims, 'gif', 0007 % filename, 'axi', axis_range, 'pll', 'grd', colour); 0008 % 0009 % INPUT 0010 % Mobj = matlab mesh object with the following fields: 0011 % - lon, lat, x, y = nodal positions (spherical and/or cartesian) 0012 % - nv, tri = connectivity table (called either nv or tri) 0013 % - [optional] time = Modified Julian Day time series 0014 % PlotField = vertex-based field to plot 0015 % [optional] fid = the fid of the figure to plot the field in - specify figure id 0016 % [optional] cli = the colour limits to use - specify the limits 0017 % [optional] gif = make an animated gif - specify filename 0018 % [optional] axi = the axis - specify axis range 0019 % [optional] pll = the axis 0020 % [optional] grd = add gridlines - specify colour 0021 % [optional] tit = add title - specify text 0022 % [optional] leg = add legend - specify text as a cell array 0023 % [optional] qui = add quiver vectors - specify a structure with the quiver information in (see examples) 0024 % 0025 % 0026 % EXAMPLE USAGE 0027 % plot_fvcom_field(Mobj, Mobj.zeta, 'fid', 1, 'cli', [0 100], 'gif', 'animation.gif', 'axi', [60000 70000 40000 50000]) 0028 % 0029 % Quiver vecotor example 1 (plot every other depth average velocity vector on unstructured grid): 0030 % Q.X = PFOW.lonc(1:15:end); 0031 % Q.Y = PFOW.latc(1:15:end); 0032 % Q.U = PFOW.ua(1:15:end,:); 0033 % Q.V = PFOW.va(1:15:end,:); 0034 % plot_fvcom_field(PFOW, PFOW.ua(:,1:13), 'pll', 'qui', Q) 0035 % 0036 % Quiver vecotor example 2 (include vecotrs on an interpolated regular grid): 0037 % Q.x = -4:0.01:-2; 0038 % Q.y = 58:0.01:59; 0039 % 0040 % [Q.X1, Q.Y1] = meshgrid(Q.x, Q.y); 0041 % Q.X = Q.X1(:); Q.Y = Q.Y1(:); 0042 % 0043 % Only use data from within the region of interpolation 0044 % I = PFOW.lonc>Q.x(1) & PFOW.lonc<Q.x(end) & PFOW.latc>Q.y(1) & PFOW.latc<Q.y(end); 0045 % 0046 % for tt=1:13 0047 % Fx = scatteredInterpolant(double(PFOW.lonc(I)), double(PFOW.latc(I)), double(PFOW.ua(I,tt))); 0048 % Fy = scatteredInterpolant(double(PFOW.lonc(I)), double(PFOW.latc(I)), double(PFOW.va(I,tt))); 0049 % Q.U(:,tt) = Fx(Q.X, Q.Y); 0050 % Q.V(:,tt) = Fy(Q.X, Q.Y); 0051 % end 0052 % plot_fvcom_field(PFOW, PFOW.ua(:,1:13), 'pll', 'qui', Q) 0053 % 0054 % Author(s) 0055 % Rory O'Hara Murray (Marine Scotland Science) 0056 % 0057 % Developments: 0058 % 2014-05-22: Changed the way fig id is checked, not using 'exist' anymore. 0059 % 2014-08-15: Added the axis command in 0060 % 0061 function [a] = plot_fvcom_field(M, plot_field, varargin) 0062 MJD_datenum = datenum('1858-11-17 00:00:00'); 0063 0064 % check to see if nv or tri should be used. 0065 if isfield(M, 'nv') 0066 nv = M.nv; 0067 elseif isfield(M, 'tri') 0068 nv = M.tri; 0069 end 0070 0071 % check to see if a time variable is there or not 0072 if isfield(M, 'time') %& size(M.time,1)>1 0073 time_flag = true; 0074 else 0075 time_flag = false; 0076 end 0077 0078 % defaults 0079 clims = [min(plot_field(:)) max(plot_field(:))]; 0080 if clims(1)==clims(2) 0081 clims(1)=clims(1)-0.1; 0082 clims(2)=clims(2)+0.1; 0083 end 0084 gif = false; 0085 grd = false; 0086 plot_ll = false; 0087 fig_flag = false; 0088 axis_flag = false; 0089 title_flag = false; 0090 legend_text_flag = false; 0091 quiver_flag = false; 0092 quiver2_flag = false; 0093 0094 for ii=1:1:length(varargin) 0095 keyword = lower(varargin{ii}); 0096 if length(keyword)~=3 0097 continue 0098 end 0099 switch keyword 0100 case 'fid' % id of a figure 0101 fig = varargin{ii+1}; 0102 fig_flag = true; 0103 case 'cli' % colour limits 0104 clims = varargin{ii+1}; 0105 case 'gif' % make an animated gif 0106 gif = true; 0107 gif_filename = varargin{ii+1}; 0108 case 'axi' % axis 0109 axis_flag = true; 0110 axi = varargin{ii+1}; 0111 case 'grd' % grid lines 0112 grd = true; 0113 edgecolor = varargin{ii+1}; 0114 case 'pll' 0115 plot_ll = true; 0116 case 'tit' 0117 title_flag = true; 0118 fig_title = varargin{ii+1}; 0119 case 'leg' 0120 legend_text_flag = true; 0121 legend_text = varargin{ii+1}; 0122 case 'qui' 0123 quiver_flag = true; 0124 quiverData = varargin{ii+1}; 0125 if isfield(quiverData,'scale')==0 quiverData.scale = 1; end 0126 if isfield(quiverData,'colour')==0 quiverData.colour =0.99*[1 1 1]; end 0127 % case 'qu2' 0128 % quiver2_flag = true; 0129 % quiverData = varargin{ii+1}; 0130 end 0131 end 0132 0133 if plot_ll 0134 x = M.lon; 0135 y = M.lat; 0136 else 0137 x = M.x; 0138 y = M.y; 0139 end 0140 0141 if not(axis_flag) 0142 axi = [min(x) max(x) min(y) max(y)]; 0143 end 0144 0145 xE = x(nv)'; 0146 yE = y(nv)'; 0147 plot_field = squeeze(plot_field); 0148 0149 if size(plot_field,1)==size(nv,1) % plot on elements 0150 if grd 0151 patch_func = @(dummy) patch(xE, yE, dummy', 'edgecolor', edgecolor); 0152 else 0153 patch_func = @(dummy) patch(xE, yE, dummy', 'linestyle', 'none'); 0154 end 0155 elseif size(plot_field,1)==size(x,1) % plot on nodes 0156 if grd 0157 patch_func = @(dummy) patch('Vertices',[x, y], 'Faces',nv, 'Cdata',dummy,'edgecolor', edgecolor,'facecolor','interp'); 0158 else 0159 patch_func = @(dummy) patch('Vertices',[x, y], 'Faces',nv, 'Cdata',dummy,'linestyle','none','facecolor','interp'); 0160 end 0161 end 0162 0163 if fig_flag 0164 if fig.Type(1)=='f' 0165 the_axes = axes; 0166 elseif fig.Type(1)=='a' 0167 the_axes = fig; 0168 end 0169 else 0170 fig = figure; 0171 the_axes = axes; 0172 end 0173 axes(the_axes); 0174 0175 for ii=1:size(plot_field,2) 0176 if ishandle(fig)==0 break; end 0177 a = patch_func(plot_field(:,ii)); 0178 c = colorbar; 0179 if legend_text_flag set(get(c, 'ylabel'), 'string', legend_text); end 0180 set(gca, 'clim', clims); 0181 axis(axi) 0182 if title_flag 0183 title(fig_title) 0184 elseif time_flag 0185 title(['time = ' datestr(double(M.time(ii))+MJD_datenum, 'HH:MM dd/mm/yyyy')]) 0186 end 0187 if quiver_flag 0188 % hold on 0189 % quiver(quiverData.X, quiverData.Y, quiverData.U(:,:,ii), quiverData.V(:,:,ii), 'w'); 0190 % hold off 0191 % elseif quiver2_flag 0192 hold on 0193 quiver(quiverData.X, quiverData.Y, quiverData.U(:,ii), quiverData.V(:,ii), quiverData.scale, 'color', quiverData.colour) 0194 hold off 0195 end 0196 0197 if gif 0198 axis off 0199 set(gcf, 'color', 'w') 0200 frame = getframe(1); 0201 im = frame2im(frame); 0202 [imind,cm] = rgb2ind(im,256); 0203 if ii == 1; 0204 imwrite(imind,cm,gif_filename,'gif', 'Loopcount',inf); 0205 else 0206 imwrite(imind,cm,gif_filename,'gif','WriteMode','append'); 0207 end 0208 else 0209 pause(0.01); 0210 end 0211 end 0212 0213 return