[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Avoiding a for cicle
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:
> "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.
Alright, now that Craig has oriented me a little bit,
I find that I, uh..., have a *need* for this sort of thing. :-)
I presume you gentlemen are testing these little theories of yours
on a test data set. Could you supply such a data set for the
rest of us to fool around with? And if you gave us just a little
hint about how such a thing might be useful to *you*, that might
help too. I might even take a stab at writing an article about
it all, especially if I feel like it has been a day or two since
I really embarrassed myself.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155