[ncl-talk] extracting Wrf Varibales and Times

Mary Haley haley at ucar.edu
Tue Dec 8 10:31:57 MST 2015


I believe this code should work on any kind of WRF Times array that looks
like "YYYY-MM-DD_mm:SS:SS".

It parses this string to get the "MM" field, and then uses this to extract
the months that are equal to 3, 4 and 5 (for MAM), or 10, 11, and 12 (for
OND). It doesn't look at the YYYY, DD, mm, or SS fields at all.

I've attached a dummy NCL script that you should be able to run just as it
is.  It creates a dummy array of WRF times and then shows how it extracts
the MAM and OND times.

You should be able to edit this script to have it read in your WRF files
with "addfiles", and then use "wrf_user_list_times" to get the times.  You
can then see by the "print" statement whether it correct extracted the MAM
and OND dates.

--Mary




On Tue, Dec 8, 2015 at 1:35 AM, afwande juliet <afwandej965 at gmail.com>
wrote:

> ok Mary
> thanks. Does this code assume the data is daily since my data (wrfoutput)
> is 3hourly. If that's the case must I convert data to monthly or daily?
> I would appreciate
>
> On Mon, Dec 7, 2015 at 8:17 AM, Mary Haley <haley at ucar.edu> wrote:
>
>> WRF output files store their "times" array as strings, so you probably
>> need to read these off the files and parse them.  You should be able to do
>> this with str_split_csv.
>>
>> For example, let's say you open the files and read the "Times" variable
>> with:
>>
>> [UNTESTED]:
>>
>>   files = systemfunc("ls wrfout_d01*")
>>   files = files + ".nc"
>>
>>   f     = addfiles(files,"r")
>>   times = wrf_user_list_times(f)   ; Read "Times" off the file
>>
>> You can then parse the "times" array using "str_split_csv" to split the
>> fields on the "-" and "_" characters, which is what separates the years,
>> months, and days:
>>
>> ;--Parse the WRF times string to get the months as integers.
>>   str1       = str_split_csv(times,"-",0)     ; first split on "-"
>>   str2       = str_split_csv(str1(:,2),"_",0) ; now split on "_""
>>
>>   wrf_months = toint(str1(:,1))   ; should be integers from 1 to 12
>>
>> Now that you have "wrf_months", you can use the "ind" function to grab
>> the months you want:
>>
>> ;---Get the index locations for MAM and OND
>>   mam_ind = ind(wrf_months.ge. 3.and.wrf_months.le. 5)
>>   ond_ind = ind(wrf_months.ge.10.and.wrf_months.le.12)
>>
>> ;
>> ; You may not have any need for the wrf_times_mam and
>> ; wrf_times_ond arrays, but I'm including them here to
>> ; see what they look like.
>> ;
>>   wrf_times_mam = times(mam_ind)
>>   wrf_times_ond = times(ond_ind)
>>
>>   print("MAM: " + wrf_times_mam)
>>   print("OND: " + wrf_times_ond)
>>
>> These index values can  be used to index any WRF variable that you read
>> with "wrf_user_getvar", or straight off the file:
>>
>> ;---Read all sea level pressures off the files
>>   slp = wrf_user_getvar(f,"slp",-1)   ; sea level pressure
>>
>> ;---Grab only MAM and OND seasons of slp
>>   slp_mam = slp(mam_ind,:,:)     ; this assumes "slp" is 3D
>>   slp_ond = slp(ond_ind,:,:)
>>
>> Let me know if this is not what you needed.
>>
>> --Mary
>>
>>
>>
>> On Sun, Dec 6, 2015 at 12:53 AM, afwande juliet <afwandej965 at gmail.com>
>> wrote:
>>
>>> Dear NCL users
>>> I have many files from wrf output like this etc..
>>>
>>> wrfout_d01_1982-02-01_00:00:00
>>> wrfout_d01_1982-06-06_00:00:00
>>> wrfout_d01_1982-10-09_00:00:00
>>> wrfout_d01_1997-02-01_00:00:00
>>> wrfout_d01_1997-03-03_03:00:00
>>> wrfout_d01_1997-06-04_03:00:00
>>> wrfout_d01_1997-07-04_03:00:00
>>> wrfout_d01_1997-07-29_03:00:00
>>> wrfout_d01_1997-09-29_15:00:00
>>>
>>> I want to extract only 6variables for MAM and OND seasons for all the
>>> files so that whatever files I will finally  have will contain only
>>> 6variables for times march-May and October -Dec
>>>
>>> Is there a way I can do this in NCL, I am trying to check the NCL
>>> documentations script at
>>> http://www2.mmm.ucar.edu/wrf/OnLineTutorial/Graphics/NCL/Examples/BASIC_SFC/wrf_Surface_multi_input_files.htm
>>> but can get way out
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151208/db5af3bd/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wtimes.ncl
Type: application/octet-stream
Size: 1795 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151208/db5af3bd/attachment.obj 


More information about the ncl-talk mailing list