Re: automatic bin range and width and corresponding average

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Sep 01 2010 - 03:22:53 MDT

Hi Mark,

What about using "ind" instead of "if-else-if"? This will reduce the number of statements inside the do loop, which

bin_ranges = ispan(295,299,1)*1.
nbins = dimsizes(bin_ranges)-1
val1=new(nbins,float)
cnt1=new(nbins,float)
cnt1=0
val1=0

do i=0,nbins-1
  ii = ind(tab1(:,0).ge.bin_ranges(i).and.tab1(:,0).lt.bin_ranges(i+1))
  val1(i) = val1(i) + sum(tab1(ii,1))
  cnt1(i) = cnt1(i) + dimsizes(ii)
  delete(ii)
end do
val1=val1/cnt1

I only did the first loop. The second loop could be done the same way. Note that I'm not checking that "ii" might be missing. If it's possible that you won't have any values in a particular bin range, then you can do the loop like this:

do i=0,nbins-1
  ii = ind(tab1(:,0).ge.bin_ranges(i).and.tab1(:,0).lt.bin_ranges(i+1))
  if(.not.any(ismissing(ii))) then
    val1(i) = val1(i) + sum(tab1(ii,1))
    cnt1(i) = cnt1(i) + dimsizes(ii)
  end if
  delete(ii)
end do

Also, to help get rid of those "warning:Argument 2 of the current function or procedure was coerced to the appropriate type and thus will not change if the function or procedure modifies its value" errors, I changed your gsn_text_ndc calls to prepend a "" in front of the "cnt" integer:

 gsn_text(wks,plot1,""+cnt(n,0),x1(n)-0.4,val(n,0),txres) ; add labels

--Mary

On Sep 1, 2010, at 4:39 AM, mark collier wrote:

> Hi,
> I would like to try and automate bin range and automatic range for a x,y series. The bin range and width would be chosen for x and the y value for each would be added into the corresponding bin. At the moment I am doing this using control flow which is ok for a small number of bins but otherwise awkward. Is there some way of automating this binning and selection process?
>
> I have tried uploaded the following files to the standard anonymous ftp but I "Could not create file". As the files are relatively small I've attached them.
>
> bar.ps
> hist.ncl
> Nino34stsu.AUSENE143srnd.81to225.son.C12
> Nino34stsu.AUSENE143srnd.81to225.son.C25
> which describes the problem. I would like to replace the code b/w the comment lines
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> with something general.
> <bar.jpg><hist.ncl><Nino34stsu.AUSENE143srnd.81to225.son.C12><Nino34stsu.AUSENE143srnd.81to225.son.C25>
> Regards,
> Mark._______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Sep 1 03:23:02 2010

This archive was generated by hypermail 2.1.8 : Thu Sep 09 2010 - 05:56:39 MDT