如何根据R中的U和V风分量计算风向 [英] How to calculate wind direction from U and V wind components in R

查看:250
本文介绍了如何根据R中的U和V风分量计算风向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有U和V风分量数据,我想根据R中的这些值来计算风向.

I have U and V wind component data and I would like to calculate wind direction from these values in R.

我想得出的风向数据范围为0-360度,其中0°或360°表示向北吹来的风,90°表示向东吹来的风,180°表示向东吹来的风风向南吹,并且270°指示风向西吹.

I would like to end up with wind direction data on a scale of 0-360 degrees, with 0° or 360° indicating a wind blowing to the north, 90° indicating a wind blowing to the east, 180° indicating a wind blowing to the south and 270° indicating a wind blowing to the west.

下面是一些示例数据:

> dput(wind)
structure(list(u_ms = c(-3.711, -2.2417, -1.8188, -1.6164, -1.3941, 
-1.0682, -0.57611, -1.5698, -1.4976, -1.3537, -1.0901, -0.60403, 
-0.70812, -0.49045, -0.39849, 0.17875, 0.48356, 1.5082, 1.4219, 
2.5881), v_ms = c(-1.471, -1.6118, -1.6613, -1.7037, -1.7388, 
-1.8748, -1.8359, -1.6766, -1.6994, -1.7505, -1.4947, -0.96283, 
-1.1194, -0.6849, -0.7847, -0.80349, -0.19352, -0.97815, -1.0835, 
-0.81666), u_rad = c(-0.064769155, -0.039125038, -0.031744042, 
-0.028211496, -0.02433163, -0.018643603, -0.010055014, -0.027398173, 
-0.026138045, -0.023626517, -0.01902583, -0.01054231, -0.012359023, 
-0.008559966, -0.006954961, 0.003119775, 0.008439712, 0.02632305, 
0.024816831, 0.045170857), v_rad = c(-0.025673788, -0.028131211, 
-0.028995149, -0.029735168, -0.030347779, -0.032721426, -0.032042493, 
-0.029262184, -0.029660119, -0.030551982, -0.026087431, -0.01680455, 
-0.019537212, -0.011953758, -0.013695596, -0.014023543, -0.00337756, 
-0.017071935, -0.018910639, -0.014253403)), .Names = c("u_ms", 
"v_ms", "u_rad", "v_rad"), class = "data.frame", row.names = c(NA, 
-20L))

我已经使用以下代码尝试获取风向(列td),但是我不相信返回的角度就是我想要的角度(即0°/360°表示向北吹的风) ,90°表示向东吹来的风等).

I have used the following code to try and obtain wind direction (column td), but I am not convinced that the returned angles are those that I want (i.e. 0°/360° indicating a wind blowing to the north, 90° indicating a wind blowing to the east etc…).

u = wind$u_rad # u component in radians
v = wind$v_rad # v component in radians

d = (180/pi)*(atan2(u,v))
td = as.matrix(d + 180)
df = cbind(wind, d, td)

> df
       u_ms     v_ms        u_rad       v_rad         d        td
1  -3.71100 -1.47100 -0.064769155 -0.02567379 -111.6228  68.37716
2  -2.24170 -1.61180 -0.039125038 -0.02813121 -125.7164  54.28357
3  -1.81880 -1.66130 -0.031744042 -0.02899515 -132.4087  47.59129
4  -1.61640 -1.70370 -0.028211496 -0.02973517 -136.5062  43.49379
5  -1.39410 -1.73880 -0.024331630 -0.03034778 -141.2788  38.72124
6  -1.06820 -1.87480 -0.018643603 -0.03272143 -150.3269  29.67308
7  -0.57611 -1.83590 -0.010055014 -0.03204249 -162.5780  17.42199
8  -1.56980 -1.67660 -0.027398173 -0.02926218 -136.8842  43.11576
9  -1.49760 -1.69940 -0.026138045 -0.02966012 -138.6118  41.38819
10 -1.35370 -1.75050 -0.023626517 -0.03055198 -142.2844  37.71557
11 -1.09010 -1.49470 -0.019025830 -0.02608743 -143.8963  36.10365
12 -0.60403 -0.96283 -0.010542310 -0.01680455 -147.8980  32.10204
13 -0.70812 -1.11940 -0.012359023 -0.01953721 -147.6830  32.31699
14 -0.49045 -0.68490 -0.008559966 -0.01195376 -144.3939  35.60607
15 -0.39849 -0.78470 -0.006954961 -0.01369560 -153.0774  26.92258
16  0.17875 -0.80349  0.003119775 -0.01402354  167.4578 347.45783
17  0.48356 -0.19352  0.008439712 -0.00337756  111.8112 291.81121
18  1.50820 -0.97815  0.026323050 -0.01707193  122.9656 302.96561
19  1.42190 -1.08350  0.024816831 -0.01891064  127.3077 307.30771
20  2.58810 -0.81666  0.045170857 -0.01425340  107.5128 287.51279

对于我的方法是否正确以及如何正确获得所需的风向值的任何建议,我将不胜感激.而计算使用lapply或ifelse 从风的U和V分量获得风向很有帮助,该代码确实与我的数据配合使用,并且我相信可以更容易地获得风向.非常感谢!

I would appreciate any advice on whether my method is correct, and if not how I could correctly obtain the desired wind direction values. While Calculating wind direction from U and V components of the wind using lapply or ifelse was helpful, the code did work with my data, and I am sure that there is an easier away to obtain wind direction. Many thanks!

推荐答案

这有三个问题:

  1. 您无法将m/s转换为弧度.为了将风成分输入到atan2中,必须对其进行归一化,但是不要通过将m/s乘以pi/180(这样做是为了获得u_radv_rad)来做到这一点.您应该以一列绝对风速()并取atan2(u_ms/wind_abs, v_ms/wind_abs). (还请注意,atan2首先使用y分量-确保这就是您想要的)
  2. atan2将以单位圆坐标为您提供答案,单位圆坐标沿逆时针方向增加,并且在x轴上为零.您想要一个基数坐标的答案,该基数顺时针增加并且在y轴上为零.要将单位圆转换为基数坐标,必须从90减去单位圆角.
  3. 您必须知道风信息是指风的方向(基坐标的标准)还是风的方向(trig/vector操作的标准)
  1. You cannot convert m/s to radians. In order to input wind components into atan2, you must normalize them, but you don't do this by multiplying m/s by pi/180 (which you did to get u_rad and v_rad). You should make a column of absolute windspeed (sqrt(u_ms^2 + v_ms^2)) and take atan2(u_ms/wind_abs, v_ms/wind_abs). (also note that atan2 takes y component first - make sure that's what you want)
  2. atan2 will give you an answer in the unit circle coordinates, which increase counterclockwise and have a zero on the x-axis. You want an answer in cardinal coordinates which increase clockwise and have a zero on the y-axis. To convert unit circle to cardinal coordinates, you must subtract the unit circle angle from 90.
  3. You must know whether the wind info refers to the direction the wind is coming from (standard for cardinal coordinates) or the direction the wind is blowing (standard for trig/vector operations)

如果给出u_ms = = -3.711v_ms = -1.471(在单位圆上,它正在向下吹并稍微向左吹,所以它是从东北来的),则:

If you are given u_ms = = -3.711 and v_ms = -1.471 (on the unit circle it is blowing down and slightly to the left, so it is coming from the northeast), then:

wind_abs = sqrt(u_ms^2 + v_ms^2)
wind_dir_trig_to = atan2(u_ms/wind_abs, v_ms/wind_abs) 
wind_dir_trig_to_degrees = wind_dir_trig_to * 180/pi ## -111.6 degrees

然后,您必须将此风向矢量转换为风向的气象惯例:

Then you must convert this wind vector to the meteorological convention of the direction the wind is coming from:

wind_dir_trig_from_degrees = wind_dir_trig_to_degrees + 180 ## 68.38 degrees

然后,您必须将该角度从触发"坐标转换为基数坐标:

Then you must convert that angle from "trig" coordinates to cardinal coordinates:

wind_dir_cardinal = 90 - wind_dir_trig_from_degrees
[1] 21.62284 #From the northeast.

这篇关于如何根据R中的U和V风分量计算风向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆