Re: segment vector with missing data [message #63357] |
Tue, 04 November 2008 13:51 |
Chad
Messages: 9 Registered: January 2008
|
Junior Member |
|
|
On Nov 4, 4:47 pm, Brian Larsen <balar...@gmail.com> wrote:
> While David is on the right track this might not be quite what you
> want... This could be a label_regions problem if I understand
> correctly.
>
Yep, LABEL_REGIONS is exactly what I'm looking for (and independently
stumbled into on David's website before checking back here). What a
useful function!
|
|
|
Re: segment vector with missing data [message #63359 is a reply to message #63357] |
Tue, 04 November 2008 13:30  |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
Chad Bender wrote:
> Hi all -
>
> This should be an easy problem, but I'm having a hard time figuring it
> out without using a bunch of loops. I've got a vector with N-elements
> (typically N~1000, but could be any number), with some NaNs
> interspersed. Typically, there will be a block of NaNs together, but
> a single NaN by itself is also possible. I want to extract the short
> segments of good data, and their corresponding indices from the
> original vector.
>
> I can do something like this, but there has to be a better way
>
> good=FINITE(data)
> i=0L
> WHILE i LT N_ELEMENTS(data) DO BEGIN
> IF i EQ 0 THEN i++ ELSE BEGIN
>
>
ind= where(finite(data),count)
then, values = data[ind]
Jean
|
|
|
Re: segment vector with missing data [message #63360 is a reply to message #63359] |
Tue, 04 November 2008 13:47  |
Brian Larsen
Messages: 270 Registered: June 2006
|
Senior Member |
|
|
While David is on the right track this might not be quite what you
want... This could be a label_regions problem if I understand
correctly.
you have something like
[1,2,3,NaN,4,3,4,3,NaN,NaN,NaN,4]
and you want
[1,2,3]
[4,3,4,3]
Do I have this right?
If so one solution is:
IDL> NaN=!values.f_nan
IDL> a=[1,2,3,NaN,4,3,4,3,NaN,NaN,NaN,4]
IDL> mask=finite(a)
IDL> mask=[0,mask,0] ; stupid edges in label_region
IDL> roi=label_region(mask)
IDL> roi=roi[1:n_elements(roi)-2]
IDL> print, roi
1 1 1 0 2 2 2 2
0 0
0 3
then use histogram and reverse_indices to pull out the different bins.
IDL> hist=histogram(roi, reverse_indices=ri)
read http://www.dfanning.com/tips/histogram_tutorial.html to figure
this out, I have to each time.
Brian
------------------------------------------------------------ --------------
Brian Larsen
Boston University
Center for Space Physics
http://people.bu.edu/balarsen/Home/IDL
|
|
|
Re: segment vector with missing data [message #63361 is a reply to message #63359] |
Tue, 04 November 2008 13:37  |
Chad
Messages: 9 Registered: January 2008
|
Junior Member |
|
|
On Nov 4, 4:28 pm, David Fanning <n...@dfanning.com> wrote:
> Chad Bender writes:
>> This should be an easy problem, but I'm having a hard time figuring it
>> out without using a bunch of loops. I've got a vector with N-elements
>> (typically N~1000, but could be any number), with some NaNs
>> interspersed. Typically, there will be a block of NaNs together, but
>> a single NaN by itself is also possible. I want to extract the short
>> segments of good data, and their corresponding indices from the
>> original vector.
>
> How about this:
>
> goodIndices = Where(Finite(array) EQ 0, COMPLEMENT=badIndices)
>
> The goodIndices finds all the good data, the badIndices
> finds all the NANs.
>
Yes, that is part of the answer. But then I still need to loop
through the the 'goodIndices' or 'badIndices' vectors to find
continuous segements.
My original posts were too brief because hitting enter seems to
correspond to hitting send in google (which is what I get for not
using a real newsgroup reader). Let me try and describe the problem
better.
These vectors are spectra with missing data. I want to extract each
good segement one at a time so I can perform FFT operations on it. So
I need to parse the index arrays to find continuous segments, get the
beginning and end indices, and store the resulting sub-segment. There
are probably 10 or so continuous sub-segments per spectrum.
It seems to me that there should be some application of HISTOGRAM that
gets me the indices of all of the continuous segments at once, but I
haven't been able to figure it out.
|
|
|
Re: segment vector with missing data [message #63363 is a reply to message #63359] |
Tue, 04 November 2008 13:30  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning writes:
> How about this:
>
> goodIndices = Where(Finite(array) EQ 0, COMPLEMENT=badIndices)
>
> The goodIndices finds all the good data, the badIndices
> finds all the NANs.
Whooops, I probably have my indices reversed. I'm
trying to eat lunch. :-(
Cheers,
David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: segment vector with missing data [message #63364 is a reply to message #63359] |
Tue, 04 November 2008 13:28  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Chad Bender writes:
> This should be an easy problem, but I'm having a hard time figuring it
> out without using a bunch of loops. I've got a vector with N-elements
> (typically N~1000, but could be any number), with some NaNs
> interspersed. Typically, there will be a block of NaNs together, but
> a single NaN by itself is also possible. I want to extract the short
> segments of good data, and their corresponding indices from the
> original vector.
How about this:
goodIndices = Where(Finite(array) EQ 0, COMPLEMENT=badIndices)
The goodIndices finds all the good data, the badIndices
finds all the NANs.
Cheers,
David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: segment vector with missing data [message #63365 is a reply to message #63364] |
Tue, 04 November 2008 13:17  |
Chad
Messages: 9 Registered: January 2008
|
Junior Member |
|
|
shoot, sent before I was finished...sorry.
>
> good=FINITE(data)
> i=0L
> WHILE i LT N_ELEMENTS(data) DO BEGIN
> IF good[i] EQ 0 THEN i++ ELSE BEGIN
i1=i
WHILE good[i] EQ 1 THEN i++
i2=i-1
seg1=data[i1:i2]
ENDELSE
ENDWHILE
|
|
|