[Wrf-users] Data analysis using NCL

Sara Fenech sarafenech at gmail.com
Sat Jun 28 12:28:57 MDT 2014


Hi all

I am very new to NCL and I've been trying to write a simple script but I'm
having some problems. Well I have done 7 runs using wrf having hourly data
for 3 months. Now I would like to extract the wind speed for each time step:
1) at a particular Lat and Lon (I managed this)
2) at a predefined height (in m)

Now I have managed to plot the wind speed for all my domain at a particular
and I have managed to get wind speeds for a particular lat and lon but I
cannot manage to obtain both at once.

Thus to sum it up I would like one value for wind speed for each time step
(where lat lon and lev are predefined.)

The last thing I would like to ask is how I can save the extracted data
into a file.

Thanks a lot for all you help. I'm attaching the script which is not
working maybe you can spot what's wrong (Something to do with dimensions)
together with the error message at the bottom.

Thanks Again

Sara

;******************************************************************************
;*NCL script to generate netCDF file containing wind speed at specific
location    *
;* Example for wrfout_d01_2010-12-01.nc                                    *
;*                                        *
;************************************************************************************


; --------------  LOAD FUNCTIONS AND PROCEDURES ----------------

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 and make a loop for all time steps
;********************************************************

  a = addfile("/home/wrf/OUTPUT/run_PBL2winter/wrfout_d01_2010-12-01.nc
","r")


times = wrf_user_list_times(a)            ; get times in the file
ntimes = dimsizes(times)            ; number of times in the file
wind_speed = new(ntimes,float) ; creation of a windspeed vector at each
time step
;print(ntimes)

do it = 0,ntimes-1                  ;Loop for the time: it= starting time
print("Working on time " + it )
time = it


;************************************************
;  - Select lon & lat of the point of interest -
;************************************************


 res = True
 res at returnInt = True  ; False : return real values, True: return interger
values
 lat = 42.47                  ; Latitude of the point of interest
 lon = 12.98                  ; Longitude of the point of interest
 point = wrf_user_ll_to_ij(a,lon,lat,res)       ;
wrf_user_ll_to_ij(nc_file,lon,lat,opt)

 x = point(1)
 y = point(0)

 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The specific height levels that we want the data interpolated to.
  height_levels = (/ 1039./)   ; height levels to plot - in meter
  nlevels       = 1     ; number of height levels

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;************************************************
;  - extract wind components and unstagger them -
;************************************************


; ----- Hence U and V are staggered, we need to  average them to get the
point on the mass grid using wrf_user_unstagger

  U     = wrf_user_getvar(a, "U", time)
  ua_in = wrf_user_unstagger(U,U at stagger)
  ua    = ua_in(0:0,y,x)             ;ua(bottom_up,grid_lon,grid_lat)
  V     = wrf_user_getvar(a, "V", time)
  va_in = wrf_user_unstagger(V,V at stagger)
  va    = va_in(0:0,y,x)            ;va(bottom_up,grid_lon,grid_lat)
  W     = wrf_user_getvar(a, "W", time)
  z_in = wrf_user_unstagger(W,W at stagger)
  z    = z_in(0:0,x,y)             ;z(bottom_up,grid_lon,grid_lat)

  wind_speed(it) = sqrt(ua^2+va^2)
  ;copy_VarCoords(ua,wind_speed(it))     ; copy coord vars to speed
  ;print(wind_speed(it))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Interpolating to the requested height
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      u_plane  = wrf_user_intrp4d( ua,z,"h",height_levels,0.,False)
      v_plane  = wrf_user_intrp3d( va,z,"h",height_Levels,0.,False)
      spd_plane =wrf_user_intrp3d
(wind_speed(it),z,"h",height_Levels,0.,False) ; speed in m/sec

  print(spd_plane(it))

end do                     ; end of time loop
;************************************************
;  - Write wind speed in ascii file -
;************************************************




 ; XLAT = lat              ; (nlat)
 ; YLON = lon              ; (mlon)
  ;windspeed   = wind_speed             ; (ntim,nlat,mlon)

  ;dimwindspeed  = dimsizes(windspeed)
  ;ntim  = dimwindspeed(0)
  ;nXLAT  = dimwindspeed(1)
  ;mYLON  = dimwindspeed(2)

  ;npts  = nXLAT*mYLON        ; total number of grid points

  ;fName = "foo.txt"
  ;data  = new( npts, "string")

  ;npt   = -1

  ;do nl=0,nXLAT-1
   ; do ml=0,mYLON-1

    ;   npt  = npt + 1
     ;  data(npt) = sprinti("%0.5i", (npt+1) )
      ; data(npt) = data(npt) + sprintf("%7.1f ",XLAT(nl))
       ;data(npt) = data(npt) + sprintf("%7.1f ",YLON(ml))

      ;do nt=0,ntim-1
       ;  data(npt) = data(npt) + sprintf("%10.3f ", windspeed(nt,nl,ml))
      ;end do
    ;end do
  ;end do

  ;asciiwrite (fName , data)


; --------------  END OF NCL SCRIPT ----------------

end

*Error Message*

fatal:Subscript out of range, error in subscript #0
fatal:An error occurred reading dims
fatal:["Execute.c":8567]:Execute: Error occurred at or near line 223 in
file $NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl

fatal:["Execute.c":8567]:Execute: Error occurred at or near line 84 in file
SpLev.ncl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/wrf-users/attachments/20140628/9bd9335e/attachment.html 


More information about the Wrf-users mailing list