Help with Matlab and grid cell average of horizontal velocity  Coast/Estuary  Delft3D
intro story Coast / Estuary
Coast / EstuaryCoastal systems are among the most dynamic physical systems on earth and are subject to a large variety of forces. The morphodynamic changes occurring to coastlines worldwide are of great interest and importance. These changes occur as a result of the erosion of sediments, its subsequent transport as bed load or suspended load, and eventual deposition. Estuaries are partly enclosed water bodies that have an open connection to the coast. Estuaries generally have one or more branching channels, intertidal mudflats and/or salt marshes. Intertidal areas are of high ecological importance and trap sediments (sands, silts, clays and organic matter). Within the Delft3D modelling package a large variation of coastal and estuarine physical and chemical processes can be simulated. These include waves, tidal propagation, wind or waveinduced water level setup, flow induced by salinity or temperature gradients, sand and mud transport, water quality and changing bathymetry (morphology). Delft3D can also be used operationally e.g. storm, surge and algal bloom forecasting. On this discussion page you can post questions, research discussions or just share your experience about modelling coastal and/or estuarine systems with Delft3D FM. ** PLEASE TAG YOUR POST! **  Sub groups

Message Boards
Help with Matlab and grid cell average of horizontal velocity
GC
Guilherme Cruz, modified 2 Years ago.
Help with Matlab and grid cell average of horizontal velocity
Youngling Posts: 2 Join Date: 9/3/13 Recent Posts 00
Hello
I've made a 3D simulation for an estuary, the final data has 14 layers from 1Jan2015 to 31dec2015.
Following the examples from the manual (Delft3DMATLAB_User_Manual.pdf), I was able to extract depth averaged u/v component for the period I want, from 1Jan to 15Jan, and calculate the mean for this period:
Matlab code:
filemodel = 'FilePath';
trim = vs_use(filemodel);
g = wlgrid('read','D:\filepath\grid.grd');
u_mn = mean(vs_let(trim,'mapseries',{[ 1:744 ]},'UMNLDF',{[ 70:110 ],[ 36:90 ]}));
vmn = mean(vs_let(trim,'mapseries',{[ 1:744 ]},'VMNLDF',{[ 70:110 ],[ 36:90 ]}));
Data:
u_mn <1x41x55 double >
v_mn <1x41x55 double >
*where 1:744 is the timestep and 70:110, 36:90 is the grid extent I want
I would like to know how to plot the mean value of this period into the grid extent(70:110, 36:90). Can't find an example or tutorial to plot the uv grid cell average .
Thank you!
I've made a 3D simulation for an estuary, the final data has 14 layers from 1Jan2015 to 31dec2015.
Following the examples from the manual (Delft3DMATLAB_User_Manual.pdf), I was able to extract depth averaged u/v component for the period I want, from 1Jan to 15Jan, and calculate the mean for this period:
Matlab code:
filemodel = 'FilePath';
trim = vs_use(filemodel);
g = wlgrid('read','D:\filepath\grid.grd');
u_mn = mean(vs_let(trim,'mapseries',{[ 1:744 ]},'UMNLDF',{[ 70:110 ],[ 36:90 ]}));
vmn = mean(vs_let(trim,'mapseries',{[ 1:744 ]},'VMNLDF',{[ 70:110 ],[ 36:90 ]}));
Data:
u_mn <1x41x55 double >
v_mn <1x41x55 double >
*where 1:744 is the timestep and 70:110, 36:90 is the grid extent I want
I would like to know how to plot the mean value of this period into the grid extent(70:110, 36:90). Can't find an example or tutorial to plot the uv grid cell average .
Thank you!
Ben Williams, modified 2 Years ago.
RE: Help with Matlab and grid cell average of horizontal velocity (Answer)
Jedi Knight Posts: 114 Join Date: 3/23/11 Recent Posts 00
Hi Guilherme,
If you want to plot the values as a map then you can use either 'pcolor' or 'quiver' as builtin matlab functions, or 'colquiver' found in the quickplot matlab functions (which have to be added to your matlab path).
figure
% Plot U component
subplot(2,1,1)
pcolor(G.X( 70:110, 36:90),G.X( 70:110, 36:90),squeeze(U_mm)); shading flat; clim([0.5,0.5]); daspect([1,1,1]); grid on
ylabel('m N'); xlabel('m E')
colorbar
title('U component (depthaveraged)
subplot(2,1,2)
pcolor(G.X( 70:110, 36:90),G.X( 70:110, 36:90),squeeze(V_mm)); shading flat; clim([0.5,0.5]); daspect([1,1,1]); grid on
ylabel('m N'); xlabel('m E')
colorbar
title('V component (depthaveraged)
% Note that you may have to transpose the U_mm or V_mm on order to match dimensions of the grid. squeeze(U_mm)'; %(note the ')
% quiver plot
figure
quiver(G.X( 70:110, 36:90),G.X( 70:110, 36:90),squeeze(U_mm),squeeze(V_mm))); daspect([1,1,1]); grid on;
ylabel('m N'); xlabel('m E')
title('Quiver plot)
% plot quiver with colours
figure
colquiver(quiver(G.X( 70:110, 36:90),G.X( 70:110, 36:90),squeeze(U_mm),squeeze(V_mm)),sqrt(squeeze(U_mm).^2+squeeze(V_mm))); grid on; daspect([1,1,1])
clim([0.5,0.5])
title('Colour Quiver plot)
If you want to plot the values as a map then you can use either 'pcolor' or 'quiver' as builtin matlab functions, or 'colquiver' found in the quickplot matlab functions (which have to be added to your matlab path).
figure
% Plot U component
subplot(2,1,1)
pcolor(G.X( 70:110, 36:90),G.X( 70:110, 36:90),squeeze(U_mm)); shading flat; clim([0.5,0.5]); daspect([1,1,1]); grid on
ylabel('m N'); xlabel('m E')
colorbar
title('U component (depthaveraged)
subplot(2,1,2)
pcolor(G.X( 70:110, 36:90),G.X( 70:110, 36:90),squeeze(V_mm)); shading flat; clim([0.5,0.5]); daspect([1,1,1]); grid on
ylabel('m N'); xlabel('m E')
colorbar
title('V component (depthaveraged)
% Note that you may have to transpose the U_mm or V_mm on order to match dimensions of the grid. squeeze(U_mm)'; %(note the ')
% quiver plot
figure
quiver(G.X( 70:110, 36:90),G.X( 70:110, 36:90),squeeze(U_mm),squeeze(V_mm))); daspect([1,1,1]); grid on;
ylabel('m N'); xlabel('m E')
title('Quiver plot)
% plot quiver with colours
figure
colquiver(quiver(G.X( 70:110, 36:90),G.X( 70:110, 36:90),squeeze(U_mm),squeeze(V_mm)),sqrt(squeeze(U_mm).^2+squeeze(V_mm))); grid on; daspect([1,1,1])
clim([0.5,0.5])
title('Colour Quiver plot)
GC
Guilherme Cruz, modified 2 Years ago.
RE: Help with Matlab and grid cell average of horizontal velocity
Youngling Posts: 2 Join Date: 9/3/13 Recent Posts 00
Hello Ben!
Thanks for the help! It is working perfectly now, only with a few changes. Don't know why, but vs_use and vs_let wasnâ€™t working, when extracting the data all values were showing as 0.
Matlab Code:
Thanks for the help! It is working perfectly now, only with a few changes. Don't know why, but vs_use and vs_let wasnâ€™t working, when extracting the data all values were showing as 0.
Matlab Code:
clear all  
clc  
% Grid extent:  
%m: 70:110  
%n: 36:90  
%Jan > 1:744  
%Jun > 3625:4344  
%loading files  
filemodel = 'D:\filepthl\trimTimeScales_CEP.dat';  
trim = qpfopen(filemodel);  
umn = qpread(trim, 1, 'depth averaged velocity', 'data', 1:744, 70:110, 36:90);  
G = wlgrid('read','D:\Delft3D_CEP\Mihael\grid.grd');  
U_mn = mean(umn.XComp);  
V_mn = mean(umn.YComp);  
%colquiver(quiver(G.X( 70:110, 36:90),G.Y( 70:110, 36:90),squeeze(U_mn),squeeze(V_mn)),sqrt(squeeze(U_mn).^2+squeeze(V_mn)));  
quiver(G.X( 70:110, 36:90),G.Y( 70:110, 36:90),squeeze(U_mn),squeeze(V_mn));  
daspect([1,1,1]);  
clim([0.5,0.5]);  
ylabel('m N'); xlabel('m E'); 