Re: save calculated 2D array as 3D array

From: Joseph Zambon <jbzambon_at_nyahnyahspammersnyahnyah>
Date: Mon Nov 21 2011 - 15:22:45 MST

Kelly,

wrf_user_getvar only calculates over 1 time period. So when you're issuing the command...
> SLP = wrf_user_getvar(data,"slp",0)

You're telling NCL to calculate SLP the data at t=0. As a result, you're getting data in west_east X south_north dimensions. You would probably want to create a new array over the 109 timesteps in your data. Snippets from a script I had written to do this...

; define dimensions
   T = a->T(1,:,:,:) ;load 3 dims of 4-d variable to get dimension sizes (lev, sn, we)
   b=dimsizes(T) ;
   bottom_top = b(0) ;lev
   south_north = b(1) ;s_n
   west_east = b(2) ;w_e
   DateStrLen = 19 ;
   time = -1 ;time = unlimited

;find max time
   maxtime=wrf_user_list_times(a);
   ntimes = dimsizes(maxtime);

do time = 0,ntimes-1,1
  ncf->slp(time,:,:) = (/wrf_user_getvar(a,"slp",time)/) ;SLP
  print(time)
end do

Also, a best practice to follow... Don't load 4-D variables, they take up a lot of memory and take forever to load! In my code above I find bottom_up, south_north, west_east from the WRF variable T and then find time dimension using wrf_user_list_times.

Hopefully this helps.

-Joe

On Nov 21, 2011, at 4:11 PM, kelly lombardo wrote:

> I am trying to calculate SLP using NCL and save it in a separate NCL file with similar attributes to the 2D variables in the original file. I am having some problems having the dimensions and sizes match up. For the original 2D data, there are 3 coordinates for time, latitude and longitude but for the calculated 2D SLP data, I can only seem to get 2 coordinates latitude and longitude. I have tried 2 ways to solve this:
>
> The first way I tried to calculate SLP and define the variable as having 3 dimensions, time, latitude, and longitude, but that didn't work:
> --------------------------------------------------
> begin
>
> system("/bin/rm -f /R0/kelly/WRF/1985/slp.nc")
> out = addfile("/R0/kelly/WRF/1985/slp.nc","c")
>
> fileAtt = True
> fileAtt@creation_date = systemfunc("date")
> fileattdef(out,fileAtt)
>
> data = addfile("/R0/kelly/WRF/1985/wrfout_d01_1985-10-16_00:00:00.nc", "r")
>
> T2 = wrf_user_getvar(data,"T2",0)
> SLP = wrf_user_getvar(data,"slp",0)
> U10 = wrf_user_getvar(data,"U10",0)
>
> dims = dimsizes(data->T2)
> print (dims)
>
> SLP = new((/dims(0),dims(1),dims(2)/),"float")
>
> dimNames = (/"time", "south_north", "west_east"/) ; coordinate variables
> dimSizes = (/ -1, dims(1), dims(2) /) ; coordinate dimensions
> dimUnlim = (/ True , False, False/) ; define unlimited t
> filedimdef(out, dimNames , dimSizes, dimUnlim )
>
> out->SLP=SLP
>
> end
> ----------------------------------------------------------------------
> For the second, I tried to conform the already calculated 2D SLP data to the coordinates of U10 of the original file, but that didn't work either and I still get only 2 coordinates:
>
> begin
>
> system("/bin/rm -f /R0/kelly/WRF/1985/slp.nc")
> out = addfile("/R0/kelly/WRF/1985/slp.nc","c")
>
> fileAtt = True
> fileAtt@creation_date = systemfunc("date")
> fileattdef(out,fileAtt)
>
> data = addfile("/R0/kelly/WRF/1985/wrfout_d01_1985-10-16_00:00:00.nc", "r")
>
> T2 = wrf_user_getvar(data,"T2",0)
> SLP = wrf_user_getvar(data,"slp",0)
> U10 = wrf_user_getvar(data,"U10",0)
>
> dims = dimsizes(data->T2)
> print (dims)
>
> filedimdef(out, "time", -1, True)
>
> out->SLP=SLP
> SLP2=conform(U10,SLP,(/0,1/))
> out->SLP2=SLP2
>
> end
> ----------------------------------------
>
> Does anyone know how to fix this?
> Thanks so much
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Nov 21 15:22:57 2011

This archive was generated by hypermail 2.1.8 : Tue Nov 22 2011 - 14:17:52 MST