[ncl-talk] Percentage outputs for pie charts

Brian Squitieri brianjs at iastate.edu
Tue Mar 1 21:21:08 MST 2016


Hello Dennis,

I tested ​the script and it worked well! Loading the script within the code
I included in the email, I got this plot (see below). Thank you for your
assistance!

Brian Squitieri
Graduate Research Assistant
Iowa State University



On Mon, Feb 29, 2016 at 5:23 PM, Dennis Shea <shea at ucar.edu> wrote:

> There was a bug in the 'fspan' function that allowed something it should
> not have.
>
> Some considered that a "feature"    :-)
>
> ---
>
> See: http://ncl.ucar.edu/prev_releases.shtml#6.2.1
>         Specifically, the 'Bugs Fixed' note of 'fspan
> ---
> The 'pie-chart' code inadvertently took advantage of that "feature".
>
> You can be a tester of a fix which will be released with 6.4.0.
>
>
> load  "./pie_chart.ncl"
>
> See attached.
>
> Cheers
>
> On Mon, Feb 29, 2016 at 3:57 PM, Brian Squitieri <brianjs at iastate.edu>
> wrote:
>
>> Good Afternoon,
>>
>> I have been attempting to plot percentages within a pie chart, but I
>> receive the following output and associated error for my NCL script:
>>
>> (0)     Percent of peak wind times at 0000 UTC: 0%
>> (0)     Percent of peak wind times at 0300 UTC: 6.45161%
>> (0)     Percent of peak wind times at 0600 UTC: 51.6129%
>> (0)     Percent of peak wind times at 0900 UTC: 35.4839%
>> (0)     Percent of peak wind times at 1200 UTC: 6.45161%
>> (0)     Percent Total: 100%
>> fatal:fspan: number of elements parameter is less-than-or-equal-to one,
>> can't continue
>> fatal:["Execute.c":8575]:Execute: Error occurred at or near line 4026 in
>> file $NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl
>>
>> fatal:["Execute.c":8575]:Execute: Error occurred at or near line 44 in
>> file pie_chart_example.ncl
>>
>> Reviewing past NCL help requests in 2010 and 2015 have shown that an
>> adjustment was necessary for the pie_chart function; specifically
>> npts = round( pcPie(n), 3)
>> changes to
>> npts = max( (/round( pcPie(n), 3), 1/) )
>>
>> I run NCL version 6.3.0 and this adjustment is already made in the base
>> code, and all variables in my script are converted to floats. Output shows
>> that the sum of all percentages equates to one hundred, so I am unsure what
>> is wrong here. I had attempted to round both with and without truncation,
>> but nothing was helpful. Any assistance would be greatly appreciated. Below
>> is the code and attached is the .txt file which contains the data set used.
>>
>>
>> ;Load vital libraries and begin program
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>> begin
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ;Retrieve data from .txt file
>>         ruc  =
>> asciiread("/tera0/brianjs/observations/ruc_analysis/LLJ_stats/LLJ_stats_all.txt",-1,"string")
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ;First, retrieve time data as a string
>>         ruc_time  = str_get_field(ruc,4,",")
>>
>> ;Convert data into floats
>>         ruc_times  = stringtofloat(ruc_time)
>>         dimall = new(1,float)
>>         dimall = dimsizes(ruc_times)
>>
>> ;Calculate time percentages statistics
>>         count = new(5,float)
>>         count = (/1,3,6,9,12/)          ;Corresponds to 0000 UTC, 0300
>> UTC, 0600 UTC, 0900 UTC, and 1200 UTC, respectively
>>
>>         time_percents = new(5,float)
>> do i = 0,4
>>         time_percents(i) = (num(ruc_times.eq.count(i))/dimall)*100
>> end do
>> print("Percent of peak wind times at 0000 UTC: "+time_percents(0)+"%")
>> print("Percent of peak wind times at 0300 UTC: "+time_percents(1)+"%")
>> print("Percent of peak wind times at 0600 UTC: "+time_percents(2)+"%")
>> print("Percent of peak wind times at 0900 UTC: "+time_percents(3)+"%")
>> print("Percent of peak wind times at 1200 UTC: "+time_percents(4)+"%")
>> print("Percent Total: "+sum(time_percents)+"%")
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ;Pie chart resources
>>         wks = gsn_open_wks("x11","LLJ_time_stats")
>>         color = (/"red","dark green","blue","purple","sienna3"/)
>>         name = (/"0000 UTC","0300 UTC","0600 UTC","0900 UTC","1200 UTC"/)
>>
>>         pres = True
>>         pres at gsnDraw  = False
>>         pres at gsnFrame = False
>>
>> ;Pie Chart
>>         pie = pie_chart(wks,time_percents,name,color,pres)
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> end
>>
>>
>>
>>
>> _______________________________________________
>> 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/20160301/fcfdb9f5/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LLJ_time_stats.png
Type: image/png
Size: 43351 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160301/fcfdb9f5/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LLJ_time_stats.png
Type: image/png
Size: 43351 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160301/fcfdb9f5/attachment-0001.png 


More information about the ncl-talk mailing list