三种方法实现UV分量转换成风速风向(转成气象学惯例)
时间:2022-09-15 12:00:00
C#实现方法:
(26条消息) 关于风向的u、v重量和依据uv计算风向公式_GISlqj的专栏-CSDN博客_风的uv分量含义
torch实现方法(实现torch方法主要是训练 使用网络时,需要输入tensor类型数据:
#定义函数将UV重量转换为风速和风向 def transUV(u, v): #获得符合条件的下标 index_udayu0 = u > 0 index_vdayu0 = v > 0 index_uxiaoyu0 = u < 0 index_vxiaoyu0 = v < 0 index_udengyu0 = u == 0 index_vdengyu0 = v == 0 dir_temp = torch.zeros_like(u) #u > 0 and v > 0 index = index_udayu0 * index_vdayu0 dir_temp = torch.where(index == True,270 - torch.atan(v / u) * 180 / Math.pi,dir_temp) #u < 0 and v > 0 index = index_uxiaoyu0 * index_vdayu0 dir_temp = torch.where(index == True, 90 - torch.atan(v / u) * 180 / Math.pi, dir_temp) #u < 0 and v < 0 index = index_uxiaoyu0*index_vxiaoyu0 dir_temp = torch.where(index == True, 90 - torch.atan(v / u) * 180 / Math.pi, dir_temp) #u > 0 and v < 0 index = index_udayu0*index_vxiaoyu0 dir_temp = torch.where(index == True, 270 - torch.atan(v / u) * 180 / Math.pi, dir_temp) #u == 0 and v > 0 index = index_udengyu0 * index_vdayu0 a_temp = torch.zeros_like(u) dir_temp = torch.where(index == True, torch.full_like(a_temp,180), dir_temp) #u == 0 and v < 0 index = index_udengyu0 * index_vxiaoyu0 a_temp = torch.zeros_like(u) dir_temp = torch.where(index == True, torch.full_like(a_temp,360), dir_temp) #u > 0 and v == 0 index = index_udayu0 * index_vdengyu0 a_temp = torch.zeros_like(u) dir_temp = torch.where(index == True, torch.full_like(a_temp,270), dir_temp) #u < 0 and v == 0 index = index_uxiaoyu0 * index_vdengyu0 a_temp = torch.zeros_like(u) dir_temp = torch.where(index == True, torch.full_like(a_temp,90), dir_temp) #u == 0 and v == 0 index = index_udengyu0 * index_vdengyu0 a_temp = torch.zeros_like(u) dir_temp = torch.where(index == True, torch.full_like(a_temp,0), dir_temp) return dir_temp
库函数实现方法:
from metpy.units import units import metpy.calc as mpcalc def transUV(u,v): data_u = units.Quantity(u,'m/s') data_v = units.Quantity(v,'m/s') data_dir = mpcalc.wind_direction(data_u,data_v) data_speed = mpcalc.wind_speed(data_u,data_v,) return torch.from_numpy(np.array(data_dir))
风向转化为气象学惯例。如果转化为海洋学,则需要添加库函数方法 todata_dir = mpcalc.wind_direction(data_u,data_v,'to')