Re: Interpolation of WRF data from pressure levels to height levels

From: Kv Gopalkrishnan <kvgopalkrishnan1_at_nyahnyahspammersnyahnyah>
Date: Wed Nov 28 2012 - 13:13:08 MST

Hi Eric
          Thanks for the links. I think I managed to explain the real
problem in a terrible manner. In short i messed up while i tried to explain
the real problem with the code. So here goes another try.

So I have the staggered data from WRF i.e. the u,v,w velocity components
from the WRF output files.
Now I want to interpolate them to certain new height levels example:new_ht
= (/10.0,20.0,30.,40.,50.,60.,70.,80.,90.,100.,110./) )

So as first step i got the height with this code :

***********************************************************************************************************
;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

So this is in mass points.

then i try to interpolate the staggered velocity using
the wrf_user_intrp3d function

do it = 0,dim_new_ht-1 ; do loop for the array of new_ht levels

  u(:,it,:,:) =
wrf_user_intrp3d(u,height,"h",new_ht(it),0.0,False);interpolating the u
component to the new ht levels

end do

But this gives an error.

So in short my question would be:

How to interpolate the staggered velocity components to different height
levels?

Sorry that my previous mail was lousy :)

Kind Regards
KV

On Wed, Nov 28, 2012 at 8:39 PM, Noble, Erik U. (GISS)[COLUMBIA UNIVERSITY]
<erik.noble@nasa.gov> wrote:

> Dear K.V.
> As a fellow lover of NCL and user of WRF, I have found these links to be
> helpful
>
> First, Here is a tinyURL to the WRF-NCL page that is not a link on their
> main site. click "example scripts"
> *http://tinyurl.com/cpp9f6y*
>
> Second, refer to this wonderful script that NCL has a link to, which
> helped me a lot of times
> http://www.mmm.ucar.edu/wrf/src/utils/wrfout_to_cf.ncl
>
> Lastly, If I understand your goal, just using the standard
> a = addfile("WRF_FILE.nc","r")
> u = a->U will give you the original unstaggered data
>
> Erik
>
> On Nov 27, 2012, at 11:14 AM, Kv Gopalkrishnan wrote:
>
> 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
>
>
>

-- 
K.V.

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Nov 28 13:13:21 2012

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