Re: two fold problem with runave_n and regline_stats

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu Jul 10 2014 - 11:14:18 MDT

A running average of 'nave' requires that the series have 'nave'
consecutive non-missing values. So nave=7 requires 7 consecutive
non-missing values before a running average value can be calculated.
You can test yourself

     N = 25
     x = fspan(1,1,N)
     x@_FillValue = -999.0

     nave = 7
     xa = runave_n(x, nave, 0, 0)
     print(x+" "+xa)

     x(N/2) = x@_FillValue ; insert in mid series
     xb = runave_n(x, nave, 0, 0)
     print(x+" "+xb)

     x(4*N/5) = x@_FillValue
     xc = runave_n(x, nave, 0, 0)
     print(x+" "+xc)

===
Your code has the following comment and assignment:

  ;; if this is 30 or 7 the program doesn't crash

  runningAverageNum = 90 ; seasonal running averages

Hence ... the series must have 90 *consecutive* non-missing values
before a value will be calculated. Your series does not have this.

---
The underlying code actually tests the overall size of the input series to
make
sure it is > 2 in length. However, it did not count the number of non
missing
(good) values to make sure it is > 2.
---

You do not have to use loops to count the # of missing values

   nmsg = num(ismissing(x)) ; # of _FillValue
   ngood = num(.not.ismissing(x)) ; # of 'good' values

Read documentation of 'num'



On Thu, Jul 10, 2014 at 10:55 AM, Adam Phillips <asphilli@ucar.edu> wrote:

> (Sorry all for the second email but I can answer Michael's 2nd question.)
>
> Hi Michael,
> Running your script the full error message is this:
>
>
> fatal:Subscript out of range, error in subscript #0
> fatal:An error occurred reading y
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 14183 in
> file /contrib/ncl/lib/ncarg/nclscripts/csm/contributed.ncl
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 34 in
> file runave_regline_stats_MStone_7-9-2014.ncl
>
> So NCL points to the line in your script that things fail (= line 34, the
> call to regline_stats) along with the line number in contributed.ncl where
> things fail (=14183). (Remember that you can look at the functions inside
> contributed.ncl.) Looking at lines 14181-14183:
>
> if (any(ismissing(x)) .or. any(ismissing(y))) then
> ii = ind(.not.ismissing(x) .and. .not.ismissing(y))
> RC = reg_multlin_stats(y(ii),x(ii),False)
>
> Line 14182 is returning a missing value as y is all missing thanks to
> runave not calculating running means on missing data as described in my
> last email. ii = a _FillValue and that is causing the third line to crash.
>
> So, I think if you start using a dim_avg* function your second issue will
> be resolved.
> Adam
>
>
>
>
> On Wed, Jul 9, 2014 at 3:45 PM, Michael Stone <mrstone@colorado.edu>
> wrote:
>
>> Hi all,
>>
>> I have a time series of data with some missing values that I'm using
>> runave_n to smooth and then fitting a regline to the smoothed data. I'm not
>> sure I understand how runave_n handles missing values but when I use
>> runave_n with increasing nave, the number of missing values in the data set
>> continually increases, this seems odd to me. I know my _FillValues are set
>> correctly as well. Is this intended behavior? If so, could someone maybe
>> explain why?
>>
>> Finally, a part two to this question, when I feed the smoothed time
>> series into regline_stats after doing the running average, I found out that
>> when run_ave_n has filled the entire time series with missing values
>> regline_stats throws a very cryptic error. It says:
>>
>> fatal:Subscript out of range, error in subscript #0
>> fatal:An error occurred reading
>>
>> This is an odd way for the function to error handle that particular case
>> and thought I should mention it.
>>
>> Relevant information:
>>
>> NCL version: 6.2.0
>> Linux version: Linux 2.6.32-431.11.2.el6.i686 #1 SMP Mon Mar 3 13:33:00
>> EST 2014 i686 i686 i386 GNU/Linux
>>
>> Attached you'll find my data file and a short script with the issue
>> outlined.
>>
>> Thanks,
>> Michael
>>
>>
>> --------------------------------------------------------------------------------------------------
>> Michael Stone (mrstone@colorado.edu)
>> ATOC PhD Student
>> CIRES Researcher
>> Ekeley/CIRES Room S327
>> University of Colorado <mrstone@colorado.edu>
>>
>> --------------------------------------------------------------------------------------------------
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
>
> --
> Adam Phillips
> Associate Scientist, Climate and Global Dynamics Division, NCAR
> www.cgd.ucar.edu/staff/asphilli/ 303-497-1726
>
> <http://www.cgd.ucar.edu/staff/asphilli>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

Received on Thu Jul 10 05:14:27 2014

This archive was generated by hypermail 2.1.8 : Fri Aug 01 2014 - 15:10:55 MDT