[ncl-talk] Q about wind_stats function
Li-Hao Young
lhy at umich.edu
Mon Jun 7 13:49:57 MDT 2021
Hi Rick,
Yes, it indeed makes much more sense to post the questions to the group.
My neglect; those data are numerical values, not text strings. I used
tofloat() and the wind_stats worked perfectly.
Many thanks!
Best,
Li-Hao
On Tue, Jun 8, 2021 at 2:32 AM Rick Brownrigg <brownrig at ucar.edu> wrote:
> I don't mind, but it really is best to post to the group, as there are
> many more eyes/expertise that can potentially provide an answer. I
> mistakenly did not cc the group in my original reply, and thus Dennis spent
> time working on an answer because he hadn't seen mine.
>
> To your specific question, I speculate that wspd and wdir are string
> variables. You might try something like:
>
> wspd = string2float(str_get_field(data,1,delim))
> wdir = string2float(str_get_field(data,2,delim))
>
> or stringtodouble() if you think that is warranted for your data.
>
> Hope that helps...
> Rick
>
>
>
> On Mon, Jun 7, 2021 at 11:57 AM Li-Hao Young <lhy at umich.edu> wrote:
>
>> Hi Rick,
>>
>> I hope you don’t mind that I’m taking the liberty to ask a follow-up
>> question.
>>
>> I was able to successfully run the Example codes of wind_stats, and
>> managed to read my wind speed and wind direction data (i.e., two columns in
>> csv file) into NCL, using the following codes:
>>
>> diri = "./“
>> fili = "2020Aug2021Apr.csv"
>> delim = ","
>> data = asciiread(diri+fili, -1, "string”)
>> wspd = str_get_field(data,1,delim)
>> wdir = str_get_field(data,2,delim)
>>
>> Using print(), I was able to see my data are correctly stored in “wspd”
>> and “wdir".
>> However, I could not figure out how to get the wind_stats to work on my
>> data, as did the Example codes.
>> The "x := wind_stats(wspd, wdir, 0, False)" does not work here, and
>> showed another error message:
>>
>> fatal: Argument type mismatch on argument (0) of (wind_stats) can not
>> coerce
>> fatal: ["Execute.c":8635]
>>
>> Your assistance is much appreciated.
>>
>> Best,
>> Li-Hao
>>
>>
>> >
>> > Hi Rick,
>> >
>> > Thanks for your prompt response.
>> >
>> > Your approach did solve the problem. Awesome, finally…:-)
>> >
>> > Best,
>> > Li-Hao
>> >
>> >> On Jun 7, 2021, at 22:35, Rick Brownrigg <brownrig at ucar.edu> wrote:
>> >>
>> >> Hi,
>> >>
>> >> Yes, I see the same behavior too, and it is a bug. NCL requires
>> functions/procedures to be defined before they are referenced, and in the
>> file $NCLROOT/lib/ncarg/nclscripts/csm/contributed.ncl, that function
>> "wind_stats" references "dim_avg_n_Wrap", which is not defined until later
>> in the file.
>> >> A solution that I verified works is to move the definition of
>> "wind_stats" to the end of the contributed.ncl file. Kinda heavy handed,
>> but it does solve the problem for your particular script.
>> >>
>> >> Hope that helps...
>> >> Rick
>> >>
>> >>
>> >> On Mon, Jun 7, 2021 at 7:39 AM Li-Hao Young via ncl-talk <
>> ncl-talk at mailman.ucar.edu> wrote:
>> >> Hi All at NCL-talk:
>> >>
>> >> My research requires me to obtain the standard deviation of wind
>> direction. And this has led me to NCL's wind_stats function. Therefore, I
>> have installed NCL 6.6.2 on my Mac Mojave (which took me many many
>> hours...). However, while running the Example 1 codes of wind_stats from
>> https://www.ncl.ucar.edu/Document/Functions/Contributed/wind_stats.shtml,
>> I was stopped by a fatal error message and could not continue on with that
>> example. The example codes are given at the bottom; the error occurred
>> while executing "x := wind_stats(wspd, wdir, 0, False)" as follow:
>> >>
>> >> ncl 6> x := wind_stats(wspd, wdir, 0, False) ; variable of type
>> 'list'
>> >> fatal:Undefined identifier: (dim_avg_n_Wrap) is undefined, can't
>> continue
>> >> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 1442
>> in file /usr/local/ncl-6.6.2/lib/ncarg/nclscripts/csm/contributed.ncl
>> >>
>> >> fatal:["Execute.c":8635]:Execute: Error occurred at or near line 6
>> >>
>> >> I have tried the Getting Started, documentation, archieves, etc., but
>> could not resolve the problem as I have no experiences with NCL coding. I
>> will very much appreciate it if someone could give me some pointers.
>> >>
>> >> Thanks,
>> >> Young
>> >>
>> >> Example 1
>> >>
>> >> N = 10
>> >> u :=
>> >> random_normal
>> >> ( 0, 2, N) ; zonal wind 'noise'
>> >> v :=
>> >> random_normal
>> >> (-10, 2, N) ; winds from the north
>> >> wspd :=
>> >> wind_speed
>> >> (u,v)
>> >> wdir :=
>> >> wind_direction
>> >> (u,v,0)
>> >>
>> >> print(sprintf("%7.2f", u)+sprintf("%7.2f", v)+sprintf("%7.2f",
>> wspd)+sprintf
>> >> ("%7.2f", wdir))
>> >>
>> >> x :=
>> >> wind_stats
>> >> (wspd, wdir, 0, False) ; variable of type 'list'
>> >> ; extract variables from list for clarity
>> >> wspd_avg = x[0] ; average of 'wspd'
>> >> wspd_std = x[1] ; standard deviation of 'wspd'
>> >> wdir_avg = x[2] ; mean vector wind direction
>> >> wdir_std = x[3] ; standard deviation of the wind direction
>> >> avgU = x[4] ; average zonal component
>> >> avgV = x[5] ; average medidional wind component
>> >>
>> >> delete
>> >> (x) ; no longer needed
>> >>
>> >>
>> >> print(sprintf("%7.2f", wspd_avg)+sprintf
>> >> ("%7.2f", wspd_std) \
>> >> +
>> >> sprintf("%7.2f", wdir_avg)+sprintf("%7.2f", wdir_std) \
>> >> +sprintf("%7.2f", avgU )+sprintf("%7.2f", avgV ) )
>> >>
>> >> _______________________________________________
>> >> ncl-talk mailing list
>> >> ncl-talk at mailman.ucar.edu
>> >> List instructions, subscriber options, unsubscribe:
>> >> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>> >
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210608/991d17de/attachment.html>
More information about the ncl-talk
mailing list