爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 7993|回复: 8

从wrfout提取指定高度和经纬度的风向和风速到txt文件

[复制链接]

新浪微博达人勋

发表于 2018-11-21 13:21:27 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本贴是参考http://bbs.06climate.com/forum.php?mod=viewthread&tid=54024,在脚本里加上了风向的计算公式,可以提取出指定高度和经纬度的风向和风速到txt文件。
我学习NCL时间不长,非常感谢大家的帮助。
    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
    load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

    ; --------------  BEGINING OF NCL SCRIPT ----------------


    begin
    ;********************************************************
    ; read in netCDF file
    ;********************************************************
      
      in   = addfiles("./wrfout_d01_2016-01-01_00:00:00","r")
      ListSetType (in, "cat")  


    ;********************************************************
    ; Process all the time steps
    ;********************************************************



    times = wrf_user_list_times(in)             ; get all times in the file
    ntimes = dimsizes(times)            ; number of times in the file

  
   ; Wind and Height
    u  = wrf_user_getvar(in,"ua",-1)        ; u averaged to mass points
    v  = wrf_user_getvar(in,"va",-1)        ; v averaged to mass points
    height  = wrf_user_getvar(in, "z",-1) ; height is our vertical coordinate
    ter = wrf_user_getvar(in, "ter",-1) ; model terrain height (HGT_M, HGT_U, HGT_V)


    printVarSummary (u)
    printVarSummary (v)
    printVarSummary (height)
    printVarSummary (ter)


    ;************************************************
    ;  - Select lon & lat of the point of interest -
    ;************************************************
    ; - The function wrf_user_ll_to_ij find the nearest grid point for a specific lat and lon

    Latitude = 36.65
    Longitude = 117   

    res = True      
    res@returnInt = True                       ; False : return real values, True: return interger values
    point = wrf_user_ll_to_ij(in,Longitude,Latitude,res)       ; wrf_user_ll_to_ij(nc_file,lon,lat,opt)
     
     x = point(0)
     y = point(1)

     ;print("X location is: " + x)            ; print the value of X at the screen
     ;print("Y location is: " + y)            ; print the value of Y at the screen



    ;*************************************************************************************
    ;  - extract wind, Temperature, Pressure, relative humidity and height coordinates-  *
    ;*************************************************************************************


    ; Conform data to Terrain Height   
       nheight = conform(height,ter,(/0,2,3/)) ; assuming height is a 3d array and ter is a 2d array
       height = height - nheight
   
    ;*******************************************************************************
    ;     - Interpolate wind speed and wind direction at different heights -          *
    ;*******************************************************************************

                    ; Interpolate U,V to 100 Meters
          u_p100  = wrf_user_intrp3d( u,height,"h", 100,0.,False)
          v_p100  = wrf_user_intrp3d( v,height,"h", 100,0.,False)
     
          ; Calculate Wind Speed from Vectors
          spd100 = sqrt(u_p100^2 + v_p100^2)
          printVarSummary(spd100)
          windspd100=spd100(:,x,y)
          dire=180+atan2(u_p100,v_p100)*180/3.14
          wdir100=dire(:,x,y)
         
          printVarSummary(windspd100)


    ;************************************************************
    ;  - Print the variables at the screen -                    *
    ;************************************************************

    npts=ntimes
    fName = "wind100.txt"
    data  = new( npts, "string")
      
     
    print("  Time      Wind_dir_100m      Wind_speed_100m ")
     

        print ( times   + " " +sprintf("%12.2f", wdir100) +"  " +sprintf("%12.2f", windspd100) )                     



       data = times  +" " +sprintf("%12.2f", wdir100) +"  " +sprintf("%12.2f", windspd100)

asciiwrite (fName , data)

end

template.ncl

3.84 KB, 下载次数: 23, 下载积分: 金钱 -5

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-3-15 10:36:59 | 显示全部楼层
感谢对前人工作的补充和完善。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-7-23 17:25:29 | 显示全部楼层
感谢楼主分享,为什么我运行的时候会在  windspd100=spd100(:,x,y) 这一行报错呢?
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2019-9-29 10:06:39 | 显示全部楼层
官网的 wrf_user_ll_to_ij里面有-1的命令
应该是  point = wrf_user_ll_to_ij(in,Longitude,Latitude,res)       ; wrf_user_ll_to_ij(nc_file,lon,lat,opt)
     
     x = point(0)-1
     y = point(1)-1
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2019-9-29 10:18:36 | 显示全部楼层
风向风速直接有现成函数
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2019-9-29 14:21:56 | 显示全部楼层
huasheng 发表于 2019-9-29 10:18
风向风速直接有现成函数

你好,可以详细说明一下吗?谢谢
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2022-4-8 15:07:27 | 显示全部楼层
羽陌轻寒 发表于 2019-7-23 17:25
感谢楼主分享,为什么我运行的时候会在  windspd100=spd100(:,x,y) 这一行报错呢?

请问解决了吗
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2024-1-24 10:01:04 | 显示全部楼层
本帖最后由 九十 于 2024-1-24 10:02 编辑
huasheng 发表于 2019-9-29 10:18
风向风速直接有现成函数

请问为什么我现在使用wind_speed函数会被提示这个函数未被定义呢?请问您有遇到过这种问题吗,我的ncl版本是6.6.2,我看官网上说这个函数6.4.0之后版本都能用,所以应该不是版本的问题,且wind_direction函数也不会报错。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2024-4-22 10:28:31 | 显示全部楼层
九十 发表于 2024-1-24 10:01
请问为什么我现在使用wind_speed函数会被提示这个函数未被定义呢?请问您有遇到过这种问题吗,我的ncl版 ...

您好 请问您是如何提取风速文件的?
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表