Commit d6c968e6 authored by Ricardo Torres's avatar Ricardo Torres 💬

Addition of scripts to do surface plots of velocity using Matlab mapping tool....

Addition of scripts to do surface plots of velocity using Matlab mapping tool. Added similar script for tracer variables (on nodes) to use Matlab Mapping toolbox. Idem for vector plots.
parent c1d99d56
function [Plots]=do_surface_plotMatlabMap(plotOPTS,FVCOM)
%
% Function to display color maps of FVCOM variables (i.e. temperature)
%
% [Plots]=do_surface_plot(plotOPTS,FVCOM)
%
% DESCRIPTION:
% Generates maps of variables using m_map toolbox (patch
%
% INPUT:
% plotOPTS = structure array with predefined options for generating the
% maps
% FVCOM = data extracted from FVCOM NC file. See read_netCDF_FVCOM for
% details
%
% plotOPTS.range_lat: [50.1000 50.4000]
% plotOPTS.range_lon: [-4.5000 -3.8500]
% plotOPTS.fig_name: 'co2_S5_slowleak'
% plotOPTS.mesh: [1x1 struct]
% plotOPTS.coastline_file: '../mat/tamar3_0coast.mat'
% plotOPTS.zone: 30
% plotOPTS.ell: 'grs80'
% plotOPTS.var_plot: 'PH'
% plotOPTS.clims: [6 8]
% plotOPTS.do_mesh: 0
% plotOPTS.nz_plot: 1
% plotOPTS.figure: 1
% plotOPTS.Time_record: 7.3271e+05
% plotOPTS.nz_plot_vec: 1
% plotOPTS.data_dec: 5
% plotOPTS.vel_sca: 5
% plotOPTS.pause: 0.5000
%
% OUTPUT:
% Plots = structure array with figure handles
%
% EXAMPLE USAGE
% [Plots]=do_surface_plot(plotOPTS,FVCOM)
%
% Author(s):
% Ricardo Torres and Pierre Cazenave (Plymouth Marine Laboratory)
%
% Revision history
%
%==============================================================================
%
% adds m_map to matlab paths. file is in utilities directory.
% amend according to your m_map installation paths
figure(plotOPTS.figure);clf
% generate figure with correct projection lat and lon range ellipsoid and
% zone.
axesm('mercator','MapLatLimit',plotOPTS.range_lat,'MapLonLimit',[plotOPTS.range_lon],'MeridianLabel','on',...
'ParallelLabel','on','MLineLocation',[0.1],'PLineLocation',[0.1],'LabelUnits','dm')
% add coastline if present
if (isfield(plotOPTS,'coastline_file') && ~isempty(plotOPTS.coastline_file) )
coast=load(plotOPTS.coastline_file);
geoshow([coast.ncst(:,2)],[coast.ncst(:,1)],'Color','black')
end
%------------------------------------------------------------------------------
% Generate maps at a give level
%------------------------------------------------------------------------------
mstruct = gcm;
[X, Y] = mfwdtran(mstruct,plotOPTS.mesh.lat, plotOPTS.mesh.lon);
aa=plotOPTS.Time_record;
fprintf('Time step %i of %i\n',aa,length(FVCOM.Time_record));
%plot map
hold on
ND=ndims(FVCOM.(plotOPTS.var_plot))
switch ND
case 2
Plots(plotOPTS.figure).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
'Cdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,aa)),'edgecolor','interp','facecolor','interp');
case 3
Plots(plotOPTS.figure).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
'Cdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,aa)),'edgecolor','interp','facecolor','interp');
end
caxis(plotOPTS.clims)
colorbar h
% check if mesh elements are required
if plotOPTS.do_mesh
%plot vertices
Plots(plotOPTS.figure).mesh=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
'EdgeColor',[0.6 0.6 0.6],'FaceColor','none');hold on
end
% setm(gca,'MapLatLimit',plotOPTS.range_lat,'MapLonLimit',[plotOPTS.range_lon])
tightmap
%-----------------------------------------------------------------------
% Only in my case it needs adding 6 because proj automatically determines a
% reference long in strides of 6deg while m_map doesn't
%------------------------------------------------------------------------
pause(plotOPTS.pause)
% if aa~=length(plotOPTS.Time_record)
% delete(Plots(plotOPTS.figure).handles(:))
% end
% end
% fprintf('Time step %i of %i\n',aa,length(plotOPTS.Time_record));
% %plot map
% hold on
% Plots(plotOPTS.figure).handles=patch('Vertices',[lat,lon],'Faces',plotOPTS.mesh.tri,...
% 'Cdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,aa)),'edgecolor','interp','facecolor','interp');
%
% caxis(plotOPTS.clims)
% colorbar
% % check if mesh elements are required
% if plotOPTS.do_mesh
% %plot vertices
% Plots(plotOPTS.figure).mesh=patch('Vertices',[lon,lat],'Faces',plotOPTS.mesh.tri,...
% 'EdgeColor',[0.6 0.6 0.6],'FaceColor','none');hold on
%
% end
% setm(gca,'MapLatLimit',plotOPTS.range_lat,'MapLonLimit',[plotOPTS.range_lon])
% %-----------------------------------------------------------------------
% % Only in my case it needs adding 6 because proj automatically determines a
% % reference long in strides of 6deg while m_map doesn't
% %------------------------------------------------------------------------
% pause(.2)
% if aa~=length(plotOPTS.Time_record)
% delete(Plots(plotOPTS.figure).handles(:))
% end
%
% end
%
return
function [Plots]=do_surface_plotVel(plotOPTS,FVCOM)
% reads image and plots tracks or stations
m_mappath;
figure(plotOPTS.figure)
% set(gcf,'units','normalized','outerposition',[0 0 0.5 0.5])
clf
m_proj('UTM','lon',[plotOPTS.range_lon],'lat',[plotOPTS.range_lat],'zon',plotOPTS.zone,'ell','grs80')
m_grid('box','fancy')
set(gca,'FontSize',18)
m_usercoast(plotOPTS.coastline_file,'Color','k','LineWidth',3);
[X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
if isfield(plotOPTS,'Time_record') & isfield(FVCOM,'mattime')
if length(plotOPTS.Time_record)==1
[dump,igoodT] = min(abs(plotOPTS.Time_record(1)-FVCOM.mattime));
else
igoodT = find( plotOPTS.Time_record(1) <= FVCOM.mattime & FVCOM.mattime <= plotOPTS.Time_record(end) );
end
else
igoodT=(1:length(FVCOM.(plotOPTS.var_plot)));
end
for aa=igoodT
% plot map with plotOPTS.var_plot
hold on
try
% 3D data (i.e. DYE, pH etc.)
Plots(1).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
'FaceVertexCdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,aa)),...
'CDataMapping','scaled','edgecolor','none','FaceColor','flat');
% Plots(1).handles=scatter(plotOPTS.mesh.xc,plotOPTS.mesh.yc,20,squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,aa)),'filled')
catch
% 2D data only (i.e. zeta etc.)
Plots(1).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
'FaceVertexCdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,aa)),...
'CDataMapping','scaled','edgecolor','none','FaceColor','flat');
% Plots(1).handles=scatter(plotOPTS.mesh.xc,plotOPTS.mesh.yc,20,squeeze(FVCOM.(plotOPTS.var_plot)(:,aa)),'filled')
end
fprintf('Time step %i of %i\n',aa,length(plotOPTS.Time_record))
display(['Time ',datestr(FVCOM.mattime(aa))])
caxis(plotOPTS.clims)
colorbar
set(get(colorbar,'YLabel'),'String',plotOPTS.var_plot,'FontSize',14)
% check if mesh elements are required
if plotOPTS.do_mesh
% plot vertices
[X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
'EdgeColor',[0.6 0.6 0.6],'FaceColor','none'); hold on
end
%----------------------------------------------------------------------
% Only in my case it needs adding 6 because proj automatically
% determines a reference long in strides of 6deg while m_map doesn't
%----------------------------------------------------------------------
m_usercoast(plotOPTS.coastline_file,'patch',[0.6, 0.6, 0.6]);
pause(plotOPTS.pause)
% if aa~=length(plotOPTS.Time_record)
% delete(Plots(1).handles)
% end
end
return
function [Plots]=do_surface_plotVelMatlabMap(plotOPTS,FVCOM)
% reads image and plots tracks or stations
figure(plotOPTS.figure)
% set(gcf,'units','normalized','outerposition',[0 0 0.5 0.5])
clf
axesm('mercator','MapLatLimit',plotOPTS.range_lat,'MapLonLimit',[plotOPTS.range_lon],'MeridianLabel','on',...
'ParallelLabel','on','MLineLocation',[0.1],'PLineLocation',[0.1],'LabelUnits','dm')
% add coastline if present
if (isfield(plotOPTS,'coastline_file') && ~isempty(plotOPTS.coastline_file) )
coast=load(plotOPTS.coastline_file);
geoshow([coast.ncst(:,2)],[coast.ncst(:,1)],'Color','black')
end
mstruct = gcm;
[X, Y] = mfwdtran(mstruct,plotOPTS.mesh.lat, plotOPTS.mesh.lon);
if isfield(plotOPTS,'Time_record') & isfield(FVCOM,'mattime')
if length(plotOPTS.Time_record)==1
[dump,igoodT] = min(abs(plotOPTS.Time_record(1)-FVCOM.mattime));
else
igoodT = find( plotOPTS.Time_record(1) <= FVCOM.mattime & FVCOM.mattime <= plotOPTS.Time_record(end) );
end
else
igoodT=(1:length(FVCOM.(plotOPTS.var_plot)));
end
for aa=igoodT
% plot map with plotOPTS.var_plot
hold on
try
% 3D data (i.e. DYE, pH etc.)
Plots(1).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
'FaceVertexCdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,aa)),...
'CDataMapping','scaled','edgecolor','none','FaceColor','flat');
% Plots(1).handles=scatter(plotOPTS.mesh.xc,plotOPTS.mesh.yc,20,squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,aa)),'filled')
catch
% 2D data only (i.e. zeta etc.)
Plots(1).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
'FaceVertexCdata',squeeze(FVCOM.(plotOPTS.var_plot)(:,aa)),...
'CDataMapping','scaled','edgecolor','none','FaceColor','flat');
% Plots(1).handles=scatter(plotOPTS.mesh.xc,plotOPTS.mesh.yc,20,squeeze(FVCOM.(plotOPTS.var_plot)(:,aa)),'filled')
end
fprintf('Time step %i of %i\n',aa,length(plotOPTS.Time_record))
display(['Time ',datestr(FVCOM.mattime(aa))])
caxis(plotOPTS.clims)
colorbar
set(get(colorbar,'YLabel'),'String',plotOPTS.var_plot,'FontSize',14)
% check if mesh elements are required
if plotOPTS.do_mesh
%plot vertices
Plots(plotOPTS.figure).mesh=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
'EdgeColor',[0.6 0.6 0.6],'FaceColor','none');hold on
end
tightmap
%----------------------------------------------------------------------
% Only in my case it needs adding 6 because proj automatically
% determines a reference long in strides of 6deg while m_map doesn't
%----------------------------------------------------------------------
% m_usercoast(plotOPTS.coastline_file,'patch',[0.6, 0.6, 0.6]);
pause(plotOPTS.pause)
% if aa~=length(plotOPTS.Time_record)
% delete(Plots(1).handles)
% end
end
return
function [Plots]=do_vector_plot_MatlabMap(plotOPTS,FVCOM)
%
% Function to display vector maps of FVCOM currents (i.e. U,V)
%
% [Plots]=do_vector_plot(plotOPTS,FVCOM)
%
% DESCRIPTION:
% Generates vector maps of currents using m_map toolbox
%
% INPUT:
% plotOPTS = structure array with predefined options for generating the
% maps
% FVCOM = data extracted from FVCOM NC file. See read_netCDF_FVCOM for
% details
%
% plotOPTS.range_lat: [50.1000 50.4000]
% plotOPTS.range_lon: [-4.5000 -3.8500]
% plotOPTS.fig_name: 'co2_S5_slowleak'
% plotOPTS.mesh: [1x1 struct]
% plotOPTS.coastline_file: '../mat/tamar3_0coast.mat'
% plotOPTS.zone: 30
% plotOPTS.ell: 'grs80'
% plotOPTS.var_plot: 'PH'
% plotOPTS.clims: [6 8]
% plotOPTS.do_mesh: 0
% plotOPTS.nz_plot: 1
% plotOPTS.figure: 1
% plotOPTS.Time_record: 7.3271e+05
% plotOPTS.nz_plot_vec: 1
% plotOPTS.data_dec: 5
% plotOPTS.vel_sca: 5
% plotOPTS.pause: 0.5000
%
% OUTPUT:
% Plots = structure array with figure handles
%
% EXAMPLE USAGE
% [Plots]=do_vector_plot(plotOPTS,FVCOM)
%
% Author(s):
% Ricardo Torres and Pierre Cazenave (Plymouth Marine Laboratory)
%
% Revision history
%
%==============================================================================
% adds m_map to matlab paths. file is in utilities directory.
% ammend according to your m_map installation paths
figure(plotOPTS.figure);
% generate figure with correct projection lat and lon range ellipsoid and
% zone.
axesm('mercator','MapLatLimit',plotOPTS.range_lat,'MapLonLimit',[plotOPTS.range_lon],'MeridianLabel','on',...
'ParallelLabel','on','MLineLocation',[0.1],'PLineLocation',[0.1],'LabelUnits','dm')
% add coastline if present
if (isfield(plotOPTS,'coastline_file') && ~isempty(plotOPTS.coastline_file) )
coast=load(plotOPTS.coastline_file);
geoshow([coast.ncst(:,2)],[coast.ncst(:,1)],'Color','black')
end
%-----------------------------------------------------------------------
% Convert element positions from FVCOM to lat and lon using m_ll2ll.m from
% utilities directory. This accesses m_map functions.
% In my case it needs adding 6 because of discrepancies between proj and m_map.
% Proj automatically determines a
% reference long in strides of 6deg while m_map doesn't
%------------------------------------------------------------------------
% only plot vectors inside lat and lon range and ...
if ~isfield(plotOPTS.mesh,'latc')
try
plotOPTS.mesh.latc = nodes2elems(plotOPTS.mesh.lat,plotOPTS.mesh);
plotOPTS.mesh.lonc = nodes2elems(plotOPTS.mesh.lon,plotOPTS.mesh);
catch
disp(['We have no access to nodes2elems in the fvcom_prepro directory'])
end
end
igood = find ( plotOPTS.mesh.lonc < plotOPTS.range_lon(2) & plotOPTS.mesh.lonc > plotOPTS.range_lon(1) &...
plotOPTS.mesh.latc < plotOPTS.range_lat(2) & plotOPTS.mesh.latc > plotOPTS.range_lat(1));
% decimate positions. Plot every plotOPTS.data_dec position.
igood=igood(1:plotOPTS.data_dec:end);
%------------------------------------------------------------------------
% Select how many layers to plot
%------------------------------------------------------------------------
ND=ndims(FVCOM.(plotOPTS.var_plotu))
switch ND
case 2
nLayers=1;
colourSpec=[0 0 0];
case 3
if isfield(plotOPTS,'nz_plot_vec')
nLayers=size(plotOPTS.nz_plot_vec,2);
nLayersRange=plotOPTS.nz_plot_vec;
else
nLayers=size(plotOPTS.nz_plot,2);
nLayersRange=plotOPTS.nz_plot;
end
% choose colors for vectors
if nLayers==1
colourSpec=[0 0 0];
else
colourSpec=colormap(hsv(nLayers));
end
end
% Preallocate outputs
u=nan(size(igood,1),nLayers,length(plotOPTS.Time_record));
v=nan(size(igood,1),nLayers,length(plotOPTS.Time_record));
% Check if we're running
% for aa=1:length(plotOPTS.Time_record)
aa=plotOPTS.Time_record;
fprintf('Time step %i of %i\n',aa,length(plotOPTS.Time_record))
% Mesh goes underneath vectors.
% if plotOPTS.do_mesh
% % plot vertices
% Plots(plotOPTS.figure).mesh=patch('Vertices',[double(plotOPTS.mesh.lat),double(plotOPTS.mesh.lon)],'Faces',plotOPTS.mesh.tri,...
% 'EdgeColor',[0.6 0.6 0.6],'FaceColor','none');hold on
% end
switch ND
case 2
u(:,1)=squeeze(FVCOM.(plotOPTS.var_plotu)(igood,(aa)));
v(:,1)=squeeze(FVCOM.(plotOPTS.var_plotv)(igood,(aa)));
case 3
for ii=1:nLayers
u(:,ii)=squeeze(FVCOM.(plotOPTS.var_plotu)(igood,nLayersRange(ii),(aa)));
v(:,ii)=squeeze(FVCOM.(plotOPTS.var_plotv)(igood,nLayersRange(ii),(aa)));
end
end
for jj=1:nLayers
[Plots(plotOPTS.figure).handles{jj}]=quiverm(double(plotOPTS.mesh.latc(igood)),double(plotOPTS.mesh.lonc(igood)),u,v,'k',plotOPTS.vel_sca,'filled'),
% [Plots(plotOPTS.figure).handles{jj}]=quiverm(double(FVCOM.latc(igood)),double(FVCOM.lonc(igood)),u./100,v./100,'k',0,'filled'),
% [Plots(plotOPTS.figure).handles(jj),~]=m_vec(plotOPTS.vel_sca,x(igood),y(igood),...
% u(:,jj),v(:,jj),colourSpec(jj,:),...
% 'shaftwidth',1,'headwidth',2);
% hold on
end
pause(plotOPTS.pause)
% if aa~=length(plotOPTS.Time_record)
% delete(Plots(plotOPTS.figure).handles(:))
% end
% end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment