[ncl-talk] Suspected bug in calculate_daily_values

Dennis Shea shea at ucar.edu
Mon Oct 2 18:50:46 MDT 2017


Hi Dave,

I have fixed NCL-2656: calculate monthly/daily_values. The updates will be
part of the 6.5.0 release.
You can test if you want.

load "./calculate_monday_values.ncl"

[... your code ...]

=====
Cheers
Dennis


P.S. We are having a nice 'British Isle' day: 3.5C and heavy rain.  :-(


On Tue, Sep 12, 2017 at 9:38 AM, Adam Phillips <asphilli at ucar.edu> wrote:

> Hi Dave,
> Thanks for reporting this and for investigating the root cause. I have
> filed a JIRA ticket: NCL-2656.
> Thanks again,
> Adam
>
>
> On Tue, Sep 12, 2017 at 7:43 AM, Dave Macleod <
> David.Macleod at physics.ox.ac.uk> wrote:
>
>> Hi,
>>
>> Long time user, first time emailer ... thanks for all the hard work on
>> NCL! FYI, I believe I have found a bug in calculate_daily_values.
>>
>> The argument "nDim" is meant to identify the time dimension, but in fact
>> the function only works correctly when nDim=0 (in the case of
>> 2,3,4-dimensional data), and nDim=1 (in the case of 5D data).
>>
>> I have copied a MWE below to demonstrate. But I have traced the problem
>> to point of the statistical operation in the function (e.g. line 18402 in
>> /contributed.ncl, NCL v 6.4.0):
>>
>> > xStat(:,nt,:,:,:)  = dim_avg_n( x(:,it,:,:,:), nDim)
>>
>> Here "nDim" specifies the dimension on which to carry out the averaging
>> and "it" is the index corresponding to day "nt" . Since "it" is hard-coded
>> on dimension #1, any value of nDim not equal to 1 will not produce the
>> correct result.
>>
>> Similarly for the 2,3,4D case,
>> > xStat(nt,:,:,:)  = dim_avg_n( x(it,:,:,:), nDim)
>>
>> ...requires nDim=0.
>>
>> A quick fix would be to modify the 5D case such that it require nDim=0,
>> then add a error condition that nDim=0. Or something more clever to
>> preserve the functionality of nDim! (I think there is also an issue where
>> the xStat is defined according to dimx).
>>
>> NB, from the code I think the same error may affect
>> calculate_monthly_values and possibly calculate_segment_values, though I
>> haven't tested this.
>>
>> All the best,
>> Dave MacLeod
>> -------------------------------------
>> Postdoctoral Research Scientist
>> Atmospheric Oceanic and Planetary Physics, University of Oxford
>>
>>
>> MWE demonstrating the problem described above:
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> begin
>>
>> ; 2D, 3D, 4D data: only works if nDim=0
>> x4D=random_uniform(-1.0,1.0,(/4,4,4,4/))        ; dummy data
>> nDim=0                                          ; choose a dimension to
>> be 'time' - CHANGE FROM A VALUE DIFFERENT FROM ZERO TO BREAK
>> x4D!nDim="time"                         ; add metadata; 4 points, over 2
>> days
>> x4D&time=fspan(0.25,1.75,4)
>> x4D&time at units="days since 2017-09-12"
>> printVarSummary(x4D)
>> x4DDay = calculate_daily_values (x4D, "avg",nDim, False)
>> printVarSummary(x4DDay)
>>
>>
>> ; 5D data: only works if nDim=1
>> x5D=random_uniform(-1.0,1.0,(/4,4,4,4,4/))      ; dummy data
>> nDim=1                                          ; choose a dimension to
>> be 'time' - CHANGE TO A VALUE DIFFERENT FROM ONE TO BREAK
>> x5D!nDim="time"                         ; add metadata; 4 points, over 2
>> days
>> x5D&time=fspan(0.25,1.75,4)
>> x5D&time at units="days since 2017-09-12"
>> printVarSummary(x5D)
>> x5DDay = calculate_daily_values (x5D, "avg",nDim, False)
>> printVarSummary(x5DDay)
>> end
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
>
> --
> Adam Phillips
> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
> www.cgd.ucar.edu/staff/asphilli/   303-497-1726 <(303)%20497-1726>
>
> <http://www.cgd.ucar.edu/staff/asphilli>
>
> _______________________________________________
> 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/20171002/ebea7fe7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: calculate_monday_values.ncl
Type: application/octet-stream
Size: 43635 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171002/ebea7fe7/attachment.obj>


More information about the ncl-talk mailing list