Calculating u and v components from wind direction and speed

Hi,
I would like to plot a wind filed on a map.
I have lat vector, lon vector, wind speed vector and wind direction vector.
As far as I understand the simplest way is to use quiverm or quiver (but quiver can't plot over a map).
To use both function I need the u and v components, and I don't have them, and I don't have the angle for the cos and sin functions in these formulas.
How can calculate them? converting wind direction to math degrees (in a formula) isn't straight forward.
Appricate your help for the easiest way.
Thank you!

 Accepted Answer

Actually, it is straightforward.
v (North (y) component) and u (East (x) component) can be calculated from S (wind speed) and D (direction) as follows
S = 10; % example - replace with your data
D = 30; % example, wind coming from the North-northeast
D = 270 - D; % convert wind direction to Matlab graphics coordinate convention
u = S*cosd(D);
v = S*sind(D);
quiver(0,0,u,v)
axis equal
xlim([-10 10])
ylim([-10 10])
grid on

9 Comments

Hi Les,
Thank you for your answer.
This formula (D = 270 - D;) works for any wind direction?
This is my code:
md = 270 - wind_direction_00Z_november19;
for i = 1:length(md)
u(i)= (wind_speed_00Z_november19(i) * (cos(md(i)))) ;
v(i)= (wind_speed_00Z_november19(i) * (sin(md(i)))) ;
end
u=transpose(u);
v=transpose(v);
load coastlines
axesm('eqaconic','MapLatLimit',[30 35],'MapLonLimit',[32 36])
framem;
plotm(coastlat,coastlon)
quiverm(lat_00Z_november19,lon_00Z_november19,u,v,'r')
The problem is that on the figure (map) the wind arrows aren't as they should be in the wind_direction_00Z_november19 vector.
The wind_direction_00Z_november19 vector is:
90 70 80 80 120 77 100 90 100 70 100 80
And the wind_speed_00Z_november19 vector is:
3.0000 12.0000 7.5000 3.5000 5.0000 13.1000 4.0000 6.5000 9.5000 5.5000 9.5000 9.5000
The 270 - D correction is based on the assumption that your wind direction is specified as the heading that the wind is blowing from, so zero would be wind from the North, 90 is wind from the East, etc.
If your wind direction is specified differently, just change that correction so you get what you expect.
It's specified as you mention, and yet the wind arrows aren't as they should be.
Can I maybe send you my lat and lon vectors?
Maybe you will know somthing that I did wrong?
I already sent in the last message the wind speed and direction vectors.
Thanks.
Sure. Post the data and I'll take a look. I don't have the mapping toolbox, which I assume is required for quiverm, but I can try it with quiver.
Is it the direction or the magnitude of the wind arrows that doesn't look like you expect?
These are the lon and lat vectors:
lon_00Z_november19 =
35.1123 35.0964 34.9594 34.8815 35.0548 35.0208 35.2217 35.1973 34.9616 35.1784 35.1233 34.9546
lat_00Z_november19 =
32.8466 32.6028 32.6808 32.4732 32.8034 32.7611 31.7806 31.7704 31.8341 32.7078 31.6644 32.5724
The wind speed and direction vectors are already sent in last messages.
The wind direction arrows don't look like I expect. You can see that the wind drection data vector should be in the same direction as the wind direction arrows.
Sorry for the delayed response. I got busy with real life.
It appears that this is working as expected.
lon_00Z_november19 = [35.1123 35.0964 34.9594 34.8815 35.0548 35.0208 35.2217 35.1973 34.9616 35.1784 35.1233 34.9546];
lat_00Z_november19 = [32.8466 32.6028 32.6808 32.4732 32.8034 32.7611 31.7806 31.7704 31.8341 32.7078 31.6644 32.5724];
wind_direction_00Z_november19 = [90 70 80 80 120 77 100 90 100 70 100 80];
wind_speed_00Z_november19 = [3.0000 12.0000 7.5000 3.5000 5.0000 13.1000 4.0000 6.5000 9.5000 5.5000 9.5000 9.5000];
S = wind_speed_00Z_november19;
D = 270 - wind_direction_00Z_november19;
u = S.*cosd(D);
v = S.*sind(D);
quiver(lat_00Z_november19, lon_00Z_november19, u, v)
axis equal % perhaps you were missing this? Without it the angles won't look right
grid on
text(lat_00Z_november19, lon_00Z_november19, split(num2str(wind_direction_00Z_november19)))
Here is what it looks like if you don't have the axis equal command. The angles don't look right at all.
I'm not sure how this translates to the quiverm command since I can't experiment with that.
figure
quiver(lat_00Z_november19, lon_00Z_november19, u, v)
grid on
text(lat_00Z_november19, lon_00Z_november19, split(num2str(wind_direction_00Z_november19)))
Thank you very much for you help, it works!
Do you know how can I plot them on geographic map? no just on a blank grid? I guess and need somehow to use the quiverm function..
You are welcome.
Would you mind accepting the answer then?
Unfortunately, I don't have the mapping toolbox so I'm not going to be much help with that. Looking at the online doc, though, it looks pretty similar to quiver. You will probably need to play around with the scale argument to quiverm (using this syntax: h = quiverm(lat,lon,deltalat,deltalon,scale)) to use your u and v speed components as the deltalat and deltalon arguments.
Good luck.

Sign in to comment.

More Answers (3)

I have done similar tasks before. If you have experimental data, your sensor should generate two time histories; velocity (Mag) and direction (Dir) with identical length, depending on your smapling frequency. To th ebest of knowledge, no sensor can read in 3D, you need to rotate your sensor if you want Z direction measurments.
You are right, direction could be tricky because small changes in wind direction could cause significant changes in the probe's reading. In other words, your probe could read between 350 and 10 degrees but in reallity these are all similar values. You need to be strategic about placing your probe at the right angle. If you avarage it out you get 180, completely opposite angle! The graph below shoes the issue:
I could not find the code that I used before, but I did something like this:
% truncating the first and last few data points
%nn= number of points you wanna truncate from the beginning
%mm= number of points you wanna truncate from the end
Vx=sum((Mag(nn:mm)).*cosd((Dir(nn:mm))))/(mm-nn+1); %V(i).cos(theta(i))/n
Vy=sum((Mag(nn:mm)).*sind((Dir(nn:mm))))/(mm-nn+1);
angle=atand(Vy/Vx);
% now you need to create a x y z domain (in your case lat lon height)
% Vz=0 in this case
quiver3(x,y,z,Vx,Vy,0);
Below is the plot I got from my experiments back in the day. I measured the wiind speed around buildings at 3 different heights.
i have matrix V(lat,lon,level,time) how to do dV/dZ, can i use gradient (V)/gradient (Z) ?
i am need to ccalculate the dV/dZ from era5, below code is okay?
clear all
close all
fclose all
load era5_all_level_parametrs_2015_04_04.mat
%%%%%%%% Hlecity %%%%%%%%%55
u_wind_avg=0.5*(u1(1,1,26,1)-u1(1,1,37,1));%u(lon,lat,level,time)
v_wind_avg=0.5*(v1(1,1,26,1)-v1(1,1,37,1));%v(lon,lat,level,time)
for i=1:37
p0=1000;
ht(i)=8*log(level1(i)/p0);
end
ht1=-ht;
ht2=ht1*1000;
% du_dz=gradient(u1(:,:,26:end,:))/(ht2(26)-ht2(end));
% dv_dz=gradient(v1(:,:,26:end,:))/(ht2(26)-ht2(end));
du_dz=gradient(u1(1,1:2,26:end,1));
dv_dz=gradient(v1(1,1,26:end,1));

Categories

Tags

Asked:

on 19 Apr 2022

Edited:

on 11 Jul 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!