Using getvar with multiple time steps

879 views
Skip to first unread message

DHenderson

unread,
Aug 21, 2018, 6:00:07 PM8/21/18
to wrfpython-talk
Hello,

I just started using the wrf-python package and it has been very useful. I am currently using getvar (like in the example plots) just to get the hang of everything.  My wrfout file (single file) contains 24 file dumps (every 30 mins for 12 hours) and 39 height levels (24,39,215,215).  How would I use the getvar routine to extract a given time step and level?

Further, when experimenting with cloud top temperture (ctt) it also only returned a single time step. Can I select a specific time for this as well?

Any help would be great!

Thanks,
Dave

Bill Ladwig

unread,
Aug 21, 2018, 6:33:49 PM8/21/18
to dsh...@gmail.com, wrfpython-talk
Hi Dave,

Given that your total array size for a product like cloud top temperate (ctt) is on the order of hundreds of megabytes, you should be ok crunching the entire dataset if you wanted. Also, there is a timeidx parameter you can give to getvar to pick a specific time index. So, to get a specific time, you can do this in one of 2 ways:

1) Figure out the desired time index, and supply that to getvar.

desired_time_index = 3
ctt = getvar(my_data_set, "ctt", timeidx=desired_time_index)

2) Crunch the entire dataset using wrf.ALL_TIMES as the time index. Then you can use xarray's utilities to extract by a time object instead of time index.

from wrf import getvar, ALL_TIMES
...
# Compute ctt for all times
ctt = getvar(my_data_set, "ctt", ALL_TIMES)
# Select the desired time via xarray
desired_ctt = ctt.sel(time='2008-01-01_12:00:00')

To extract a specific height level, you'll need to be more specific. WRF does not use typical vertical levels like 850 MB, 700MB, 500 MB, etc. WRF uses terrain following ETA coordinates. So in order to get specific levels, you need to use either the interplevel or vinterp interpolation routines.



In the future, an xarray front end will be developed to make this a little easier, but it's not there yet.

Please let me know if you have any questions.

Bill


--
You received this message because you are subscribed to the Google Groups "wrfpython-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wrfpython-tal...@ucar.edu.
To post to this group, send email to wrfpyth...@ucar.edu.
Visit this group at https://groups.google.com/a/ucar.edu/group/wrfpython-talk/.

DHenderson

unread,
Aug 21, 2018, 7:22:06 PM8/21/18
to wrfpyth...@ucar.edu, dsh...@gmail.com
Thanks for the reply.  Your suggestion is what I thought I should have done to start. The issue is when I define timeidx I get a bound error.
"IndexError: index exceeds dimension bounds"

Perhaps there is something else wrong on my end? In the netdcf file (using ncdump), the time dimension is listed as " Time = UNLIMITED ; // (1 currently)" , which is common in model output as it stacks time on each other. Could this be the issue? Just looking at this I assume the "1 currently" should have 24.  

Edit: Yes this seems to be the issue. Tested with another set of simulations and your suggestions work fine. File debugging needed on my end now for my current runs.

-Dave


Bill Ladwig

unread,
Aug 22, 2018, 11:46:32 AM8/22/18
to dsh...@gmail.com, wrfpython-talk
Hi Dave,

According to that printout, you only have 1 time step in the file that you're using (as indicated by the '1 currently'). If you have 24 time steps in that file, it should say '24 currently'. Something isn't making sense to me. Is your data layout really one file with 24 time steps in it? If so, it doesn't look like the file is being created correctly. For example, here is a 'ncdump' for one of my WRF files with 4 time steps in it:

netcdf wrfout_d02_2005-08-28_00\:00\:00 {

dimensions:

Time = UNLIMITED ; // (4 currently)

DateStrLen = 19 ;

west_east = 96 ;

south_north = 96 ;

bottom_top = 29 ;

bottom_top_stag = 30 ;

soil_layers_stag = 4 ;

west_east_stag = 97 ;

south_north_stag = 97 ;


WRF-Python can handle one time per file, multiple times in a file, or multiple times in multiple files. So, if your data is arranged one time per file, then you want to make a list of the Dataset objects and pass this list to the getvar function.

If you're still having problems, can you give me a description of your data output layout? If it is just a single file, can you send me the result of 'ncdump -h your_file'.

Regards,

Bill





On Tue, Aug 21, 2018 at 5:22 PM DHenderson <dsh...@gmail.com> wrote:
Thanks for the reply.  Your suggestion is what I thought I should have done to start. The issue is when I define timeidx I get a bound error.
"IndexError: index exceeds dimension bounds"

Perhaps there is something else wrong on my end? In the netdcf file (using ncdump), the time dimension is listed as " Time = UNLIMITED ; // (1 currently)" , which is common in model output as it stacks time on each other. Could this be the issue?

-Dave

DHenderson

unread,
Aug 22, 2018, 11:50:50 AM8/22/18
to wrfpython-talk, dsh...@gmail.com
Bill,

I had edited my last response, but that probably did not go through. Yes this seems to be the issue. Tested with another set of simulations and your suggestions work fine. File debugging needed on my end now for my current runs.

Thanks for all your help,
Dave
Reply all
Reply to author
Forward
0 new messages