[ncl-talk] Question about the output of 1-2-1 average

Adam Phillips asphilli at ucar.edu
Thu Oct 5 10:59:02 MDT 2017


Hi Lyndz,
The wgt_runave documentation describes how the function works:
https://www.ncl.ucar.edu/Document/Functions/Built-in/wgt_runave.shtml

As you are specifying an odd number of weights, the centered value is where
the smoothed 3yr value will be placed. I find that doing a simple test in
interactive NCL is a quick way to check how many NCL functions work:
ncl
a = (/2.3,1.2,5,-1.2/)
a at _FillValue = -9999.
b = wgt_runave(a,(/0.25,0.5,0.25/),0)
print(b)
;---- output-----
Variable: b
Type: float
Total Size: 16 bytes
            4 values
Number of Dimensions: 1
Dimensions and sizes: [4]
Coordinates:
Number Of Attributes: 1
  _FillValue : -9999
(0) -9999
(1) 2.425
(2) 2.5
(3) -9999

The average of 2.3, 1.2 and 5 are placed in the (1) slot (=the middle).
Values at the beginning and end are missing as there are no values at (-1)
or (4). As the documentation states, you can set the option to 1 to get
values at the end points:
c = wgt_runave(a,(/0.25,0.5,0.25/),1)
print(c)
;---output-----
Variable: c
Type: float
Total Size: 16 bytes
            4 values
Number of Dimensions: 1
Dimensions and sizes: [4]
Coordinates:
Number Of Attributes: 1
  _FillValue : -9999
(0) 1.75
(1) 2.425
(2) 2.5
(3) 1.9

Hope that helps. If you have any further questions please reply to the
ncl-talk email list.
Adam






On Thu, Oct 5, 2017 at 1:22 AM, Lyndon Mark Olaguera <
olagueralyndonmark429 at gmail.com> wrote:

> Dear ncl-experts,
>
> I am just confused about the output of the 1-2-1 average in NCL.
>
> I have a csv file containing 30 years of data (1979-2008). I attached the
> raw file (P28-P31.csv) and the smoothed file (P28-P31_filt.csv). After
> applying the 3 point 1-2-1 average, I got 29 points with -9999 (missing at
> both ends) after applying the script.
>
> Question:
>
> [1] I'm confused now which output point corresponds to a particular year
> (which point in the smoothed file corresponds to 1979, 1980,etc).
> [2[ Is there a way to add a "filler" value to the points without data
> after smoothing automatically?
>
>
> begin
>    diri     = "./"
>    files     = systemfunc("ls *.csv")
>    numfiles = dimsizes(files)
>    do ifil  = 0,numfiles-1
>      lines    = asciiread(files(ifil),-1,"string")
>      data = lines(1:)
>      rain = tofloat(str_get_field(data,1,","))
> ;;***************************************************
> ;;Apply 1-2-1 running average (three pentads)
> ;;****************************************************
>   x = wgt_runave(rain, (/0.25, 0.50, 0.25/), 0)
>   x at _FillValue = -9999
> ;;****************************************************
> ;;Save output to a csv file
> ;;****************************************************
>   flname = str_get_cols(files(ifil),0,6)+"_filt.csv"
>   asciiwrite(flname,x)
>   end do
> end
>
> Thank you in advance for the help.
>
> Sincerely,
>
> Lyndz
>
>
> _______________________________________________
> 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

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171005/9b11ef70/attachment.html>


More information about the ncl-talk mailing list