Re: ttest warning message and code efficiency

From: Hobbs, Will R (3244-CalTech) <william.r.hobbs_at_nyahnyahspammersnyahnyah>
Date: Wed, 23 Sep 2009 09:18:14 -0700

Gina

Because of the way NCL deals with arrays (http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclExpressions.shtml#Multi-dimensionalArraysAndExpressions). In this case you don't need any of those loops at all, as long as time is the rightmost dimension (as it is with your input array):

  aveX = dim_avg(FSNS_hi_new2)
  aveY = dim_avg(FSNS_lo_new2)
  varX = dim_variance(FSNS_hi_new2)
  varY = dim_variance(FSNS_lo_new2)

  sX = dim_num(.not.ismissing(FSNS_hi_new2)) ;note that this step looks for the number of actual data points,and doesn't assume that all elements contain data
  sY = dim_num(.not.ismissing(FSNS_lo_new2) )

  iflag = True
  FSNSprob = 100.*(1. - ttest(aveX,varX,sX,aveY,varY,sY,iflag,False))

>warning:ttest: encountered 1 cases where var1 and/or var2 were less than or equal to 0. Output set to missing values in these cases

This message just indicates that you have spatial locations in your input arrays which have no non-missing values, and the 'ttest' function will set the output to missing as well.

Hope that helps

Will

From: ncl-talk-bounces_at_ucar.edu [mailto:ncl-talk-bounces_at_ucar.edu] On Behalf Of Gina Henderson
Sent: Wednesday, September 23, 2009 6:39 AM
To: ncl-talk_at_ucar.edu
Subject: ttest warning message and code efficiency

Hi there,

I am using the ttest function on a global data. My arrays are of shape (12, 64, 128, 40) and correspond to month, lat, lon, time. I am currently running this in a nested do loop which is not very efficient as I have cases where a warning is written to the screen:

warning:ttest: encountered 1 cases where var1 and/or var2 were less than or equal to 0. Output set to missing values in these cases

Would someone have a suggestion of how to do this outside of a do loop that would improve the runtime of the script? My code looks as follows:

do mon=0,11
 do i=0,63
  do j=0,127
  aveX = dim_avg(FSNS_hi_new2(mon,i,j,:))
  aveY = dim_avg(FSNS_lo_new2(mon,i,j,:))
  varX = dim_variance(FSNS_hi_new2(mon,i,j,:))
  varY = dim_variance(FSNS_lo_new2(mon,i,j,:))
  sX = dimsizes(FSNS_hi_new2(mon,i,j,:))
  sY = dimsizes(FSNS_lo_new2(mon,i,j,:))
  iflag = True
  prob = 100.*(1. - ttest(aveX,varX,sX,aveY,varY,sY,iflag,False))
; printVarSummary(prob)
; print(prob)
  FSNSprob(mon,i,j) = prob
  end do
 end do
end do

Any suggestions would be greatly appreciated.
Thanks, Gina.

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Sep 23 2009 - 10:18:14 MDT

This archive was generated by hypermail 2.2.0 : Thu Sep 24 2009 - 13:55:09 MDT