Interpolation of WRF data from pressure levels to height levels

From: Kv Gopalkrishnan <kvgopalkrishnan1_at_nyahnyahspammersnyahnyah>
Date: Tue Nov 27 2012 - 09:14:21 MST

Hi
   I am trying to interpolate u,v,w velocity components to some specific
height levels (this is an array like new_ht =
(/10.0,20.0,30.,40.,50.,60.,70.,80.,90.,100.,110./) ). Now if I am using
the data at mass points (for instance get ua,uv,uw) then everything goes
smoothly since they r unstaggered grid points. However, I need to keep the
velocity u,v,w in the nodes as the original data (in short i want the data
staggered). This is mainly because i use a advection code that makes use of
the staggered velocity components. I tried to write an ncl code for this
but i manage to get errors while doing so. The code is as follows:

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/wrf/WRFUserARW.ncl"

begin
   a = addfile("wrfout_d02_2010-07-11_00:00:00.nc","r")

  ; getting wind components

    u = wrf_user_getvar(a,"U",-1)
    dim_u = dimsizes(u)
    print(dim_u)

    v = wrf_user_getvar(a,"V",-1)
    dim_v = dimsizes(v)
    print(dim_v)

    w = wrf_user_getvar(a,"W",-1)
    dim_w = dimsizes(w)
    print(dim_w)

   ; creating new varaibles
   va = new((/dim_v(0),dim_v(1),dim_v(2),dim_v(3)/),float)
   dim_va = dimsizes(va)
   print(dim_va)

   ua = new((/dim_u(0),dim_u(1),dim_u(2),dim_u(3)/),float)
   dim_ua = dimsizes(ua)
   print(dim_ua)

   wa = new((/dim_w(0),dim_w(1),dim_w(2),dim_w(3)/),float)

; new height levels to be interpolated
 new_ht = (/10.0,20.0,30.,40.,50.,60.,70.,80.,90.,100.,110./) ; new height
levels to be interpoalted
 dim_new_ht = dimsizes(new_ht) ; size of the
height levels

;getting height levels and terrian height levels from the file

 z = wrf_user_getvar(a, "z",-1) ; grid point height
 dimz = dimsizes(z) ; get the dimensions
 ter = wrf_user_getvar(a,"ter",-1) ; get terrian height
 dimter = dimsizes(ter) ; get the dimensions

;*************************************************
;Print dimensions of height and terrian height to
;the screen
;*************************************************
 print(dimz)
 print(dimter)
;*************************************************
 nheight = conform(z,ter,(/0,2,3/)) ; the 0,2,3 of termatches that of z and
then is expanded
 nheight_size = dimsizes(nheight) ; Defines the height of the nheight
 print(nheight_size) ; prints out in the screen

 height = z-nheight ; subracting the height from the
terrian height
 dim_height = dimsizes(height) ; getting the dimsizes
 print(dim_height) ; printing the dimsizes to the screen
;*************************************************

 ; print(dimsizes(ua))
 ; print(dimsizes(u))

 va = wrf_user_intrp3d( v,height,"h", 10.,0.0,False) ; interpolating the
values in diff height levels
 print(dimsizes(va))
 print(dimsizes(v))

 ;do it = 0,dim_new_ht-1 ; do loop for the array of new_ht
levels
;getting height levels and terrian height levels from the file

 z = wrf_user_getvar(a, "z",-1) ; grid point height
 dimz = dimsizes(z) ; get the dimensions
 ter = wrf_user_getvar(a,"ter",-1) ; get terrian height
 dimter = dimsizes(ter) ; get the dimensions

;*************************************************
;Print dimensions of height and terrian height to
;the screen
;*************************************************
 print(dimz)
 print(dimter)
;*************************************************
 nheight = conform(z,ter,(/0,2,3/)) ; the 0,2,3 of termatches that of z and
then is expanded
 nheight_size = dimsizes(nheight) ; Defines the height of the nheight
 print(nheight_size) ; prints out in the screen

 height = z-nheight ; subracting the height from the
terrian height
 dim_height = dimsizes(height) ; getting the dimsizes
 print(dim_height) ; printing the dimsizes to the screen
;*************************************************

 ; print(dimsizes(ua))
 ; print(dimsizes(u))

 do it = 0,dim_new_ht-1 ; do loop for the array of new_ht levels
; do dim3 = 0,dim_u(3)-1
    ua(:,it,:,:) = wrf_user_intrp3d( u,height,"h", new_ht(it),0.0,False) ;
interpolating the values in diff height levels
 ; end do
 end do
   dim_ua = dimsizes(ua)
   print(dim_ua)

end

This does not work probably because the dimensions are not equal.

More precisely (may be) because
The size of 'height' is

Variable: dim_height
Type: integer
Total Size: 16 bytes
            4 values
Number of Dimensions: 1
Dimensions and sizes: [4]
Coordinates:
(0) 4
(1) 62
(2) 220
(3) 200

and that of u and uv is
Variable: dim_u
Type: integer
Total Size: 16 bytes
            4 values
Number of Dimensions: 1
Dimensions and sizes: [4]
Coordinates:
(0) 4
(1) 62
(2) 220
(3) 201

The dimension(3) in the case of u component gives the main problem.

So how do i solve this problem? The error that i get is as follows:

fatal:Dimension size mismatch, dimension (3) of left hand side reference
does not have the same size as the right hand side reference after
subscripting.

Any help greatly appreciated.

Kind Regards
KV

-- 
K.V.

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Nov 27 09:14:38 2012

This archive was generated by hypermail 2.1.8 : Fri Dec 07 2012 - 13:30:06 MST