[ncl-talk] total number of times in files opened with addfiles

Zilore Mumba zmumba at gmail.com
Mon Apr 4 13:53:35 MDT 2022


Thanks again Dave for your help. I did note that you gave me two ways of
getting ntimes. I kept both ( just for my learning) but commented out one.
My understanding is that   tc = wrf_user_getvar (files_all, "tc", it) is to
get tc in all the files, in other words, the same as tc = wrf_user_getvar
(files_all[:], "tc", it) is that correct?
Now my problem is on contour_tc = wrf_contour(files_all,wks,tc_plane,opts).
I think this has to take one file to plot at time it, out of
files_all.contour_tc = wrf_contour(files_all,wks,tc_plane,opts)
Whether I put contour_tc = wrf_contour(files_all,wks,tc_plane,opts),
contour_tc = wrf_contour(files_all(0),wks,tc_plane,opts) or contour_tc =
wrf_contour(files_all[0],wks,tc_plane,opts) I get "fatal:Argument type
mismatch on argument (0) of (wrf_contour) can not coerce".
So my problem is how do I specify the file from which to plot on that line?
I am trying to go through the documentation on subscripting, but ncl is
such a vast library that I need time.

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Mon, Apr 4, 2022 at 8:11 PM Dave Allured - NOAA Affiliate <
dave.allured at noaa.gov> wrote:

> Zilore, I showed you two different ways to get ntimes.  Please choose only
> one or the other.  Do not put both in your program, it makes it hard to
> understand.  Also ntimes is a nice scalar, not an array.  So only use
> ntimes, not ntimes(0) or dims(0).
>
> I think you want times_to_use, not times, to display time strings:
>
>     print ("Working on time: " + times_to_use(it) )
>     res at TimeLabel = times_to_use(it)
>
> There are two different ways to do time indexing with wrf_user_getvar.
> See the function documentation, and the examples at the end of that page.
> The way you have it now looks like one of the correct ways.
>
>     tc = wrf_user_getvar (files_all, "tc", it)
>
>
> On Sat, Apr 2, 2022 at 2:24 PM Zilore Mumba <zmumba at gmail.com> wrote:
>
>> Thanks Dave for the assistance. I have made some progress. While I know
>> that I need time to learn ncl subscripting, perhaps I could be helped to
>> make the script work. This script is an adaptation of one of the provided
>> wrf-ncl scripts. The script plots several variables at different levels. I
>> have reproduced below, parts of the script which plot temperature. I have
>> marked in
>> 1. yellow, some guidance I got from Dave
>> 2. blue some changes I made to getting the times
>> 3. purple, getting the variables, with files_all (I assume it is
>> equivalent to files_all[:] and gets variables from all files)
>> 4. red I have to specify from which file to plot. This is where I have a
>> problem, how to index files_all.
>> I hope I can be assisted.
>>
>>   files_all = addfiles(FILES+".nc","r")
>>
>> ; get time information
>>   times_in_file = files_all[:]->Times
>>
>> * dims = dimsizes (times)  ntimes = dimsizes (times(:,0))*
>>
>> ; strip out the day and hour
>>   times_to_use = new(dims(0),string)
>>
>>   do i=0,dims(0)-1
>>     times_to_use(i) = chartostring(times_in_file(i,8:12))
>>   end do
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>   do it = 0,ntimes(0)-1,2             ; TIME LOOP
>>
>>     print("Working on time: " + times(it,0) )
>>     res at TimeLabel = times(it,0)   ; Set Valid time to use on plots
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ; First get the variables we will need
>>     tc = wrf_user_getvar(*files_all**,*"tc",it)        ; T in C
>>     u  = wrf_user_getvar(files_all,"ua",it)        ; u averaged to mass
>> points
>>     v  = wrf_user_getvar(files_all,"va",it)        ; v averaged to mass
>> points
>>     p  = wrf_user_getvar(files_all, "pressure",it) ; pressure is our
>> vertical coordinate
>>     z  = wrf_user_getvar(files_all, "z",it)        ; grid point height
>>     rh = wrf_user_getvar(files_all,"rh",it)        ; relative humidity
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>     do level = 0,nlevels-1                 ; LOOP OVER LEVELS
>>
>>       pressure = pressure_levels(level)
>>       tc_plane = wrf_user_intrp3d(tc,p,"h",pressure,0.,False)
>>       z_plane  = wrf_user_intrp3d( z,p,"h",pressure,0.,False)
>>       rh_plane = wrf_user_intrp3d(rh,p,"h",pressure,0.,False)
>>       u_plane  = wrf_user_intrp3d( u,p,"h",pressure,0.,False)
>>       v_plane  = wrf_user_intrp3d( v,p,"h",pressure,0.,False)
>>
>>       spd     = (u_plane*u_plane + v_plane*v_plane)^(0.5) ; m/sec
>>       spd at description = "Wind Speed"
>>       spd at units = "m/s"
>>       u_plane = u_plane*1.94386     ; kts
>>       v_plane = v_plane*1.94386     ; kts
>>       u_plane at units = "kts"
>>       v_plane at units = "kts"
>>
>>       wks = gsn_open_wks(type,"Plots00-" + "P" + pressure_levels(level) +
>> "_" + times_to_use(it) + "Z")
>>
>>       ; Plotting options for T
>>         opts = res
>>         opts at cnLineColor = "Red"
>>         opts at ContourParameters = (/ 5.0 /)
>>         opts at cnInfoLabelOrthogonalPosF = 0.07  ; offset second label
>> information
>>         opts at gsnContourLineThicknessesScale = 2.0
>>         contour_tc = wrf_contour(*files_all*,wks,tc_plane,opts)
>>         delete(opts)
>>
>>     end do      ; END OF LEVEL LOOP
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>   end do        ; END OF TIME LOOP
>>
>>
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Virus-free.
>> www.avast.com
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
>> <#m_-2706776208549386084_m_-355677814135215976_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> On Sat, Apr 2, 2022 at 5:06 PM Dave Allured - NOAA Affiliate <
>> dave.allured at noaa.gov> wrote:
>>
>>> Here are two different ways to get the size of the time dimension.  The
>>> second method uses dimension reduction to find the size of only one slice
>>> of the 2-D character array.
>>>
>>> dims = dimsizes (times)
>>> ntimes = dims(0)
>>>
>>> ntimes = dimsizes (times(:,0))
>>>
>>>
>>> On Fri, Apr 1, 2022 at 11:04 PM Zilore Mumba <zmumba at gmail.com> wrote:
>>>
>>>> I have 13 files, i.e. analysis plus 12 hourly files of forecasts.
>>>> print (files_all[0]->Times) and printVarSummary(times) give the following
>>>> output:
>>>> Variable: Times (file variable)
>>>> Type: character
>>>> Total Size: 19 bytes
>>>>             19 values
>>>> Number of Dimensions: 2
>>>> Dimensions and sizes: [Time | 1] x [DateStrLen | 19]
>>>> Coordinates:
>>>> (0,0) 2
>>>> (0,1) 0
>>>> (0,2) 2
>>>> (0,3) 2
>>>> (0,4) -
>>>> (0,5) 0
>>>> (0,6) 3
>>>> (0,7) -
>>>> (0,8) 2
>>>> (0,9) 8
>>>> (0,10) _
>>>> (0,11) 0
>>>> (0,12) 0
>>>> (0,13) :
>>>> (0,14) 0
>>>> (0,15) 0
>>>> (0,16) :
>>>> (0,17) 0
>>>> (0,18) 0
>>>>
>>>> Variable: times
>>>> Type: character
>>>> Total Size: 247 bytes
>>>>             247 values
>>>> Number of Dimensions: 2
>>>> Dimensions and sizes: [Time | 13] x [DateStrLen | 19]
>>>> Coordinates:
>>>>
>>>>
>>>> On Fri, Apr 1, 2022 at 11:53 PM Dave Allured - NOAA Affiliate <
>>>> dave.allured at noaa.gov> wrote:
>>>>
>>>>> Please show print (files_all[0]->Times) and printVarSummary(times).
>>>>>
>>>>>
>>>>> On Fri, Apr 1, 2022 at 3:42 PM Zilore Mumba via ncl-talk <
>>>>> ncl-talk at mailman.ucar.edu> wrote:
>>>>>
>>>>>> I have a number of WRF output files, one file per hour, which I open
>>>>>> with
>>>>>> files_all = addfiles(FILES+".nc","r")
>>>>>>
>>>>>> I then get the times and the total number with.
>>>>>>   times = files_all[:]->Times      ; get all times in the file
>>>>>>   ntimes = dimsizes(times)         ; number of times in the file
>>>>>>
>>>>>> I think I am missing something here because  with print(ntimes) I see
>>>>>> two numbers.
>>>>>> I want to use ntimes in a loop: do it = 0,ntimes-1,2
>>>>>>
>>>>>> This gives me the error: fatal:Loop end must be scalar, can't execute
>>>>>> loop.
>>>>>> How do I get the times from files opened with addfiles. I will
>>>>>> appreciate any assistance.
>>>>>>
>>>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220404/a45a4d8e/attachment.html>


More information about the ncl-talk mailing list