[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Avoiding a for cicle




"J.D. Smith" <jdsmith@astro.cornell.edu> writes:

> > Alright code slingers... new challenge... find location of all peaks in a region
> > of n points (n odd), monotonically decreasing away from the peak.  I.e. find
> > peaks of width n.
> > 
> 
> Since noone will take my challenge I'm forced to claim the prize for myself:
> 
> wh=where(d gt ((m=median(d,3))) and smooth((d eq m)*(n-2),n-2) eq n-3)

Slow down there whipper-snapper!  Gotta let these things stew for a
while.  Though multiline, this is my best effort:

dd = d(1:*)-d
nh = (n-1)/2
wh = where(convol((dd GT 0) AND (dd(nh:*) LT 0), bytarr(nh)+1, nh) EQ 1, ct)+1

For the goobledy-gook impaired (aka DF :-),
  dd is the first difference of the data 
  nh is the half-width of the peak
  (dd GT 0) AND (dd(nh:*) LT 0) locates up-going followed by down-going points
  convol(...) locates runs of length nh

This one does exactly what was requested, which I'm not sure of about
your solution, J.D.  On the other hand, your solution may be more
physically meaningful since it involves smoothing.

Craig


-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------