Re: [Q]IDL: Using WHERE. [message #5958] |
Fri, 22 March 1996 00:00 |
steinhh
Messages: 260 Registered: June 1994
|
Senior Member |
|
|
In article <31519B73.167E@silk.gsfc.nasa.gov>, "Thomas A. McGlynn" <tam@silk.gsfc.nasa.gov> writes:
|>
|> It would be extremely useful if there were an optional, perhaps keyword,
|> parameter in where which gave the complement of the array-elements retrieved
|> so that one needn't call where twice, i.e.,
|>
|> w=where(image le 0, complement=ww)
|>
Yes please! I'd like that!
Too bad I'm stuck with programming for IDL 3.6 ....
Stein Vidar
|
|
|
Re: [Q]IDL: Using WHERE. [message #5962 is a reply to message #5958] |
Thu, 21 March 1996 00:00  |
Paul Schopf
Messages: 2 Registered: March 1996
|
Junior Member |
|
|
Thomas A. McGlynn wrote:
[snip, snip, snip]
> This is something that I've always wanted to be able to do efficiently
> but seem always to need to go through large arrays twice.
> I frequently run into the situation that I want to do one thing for
> with some bad pixels set to <0 and I want to display a logarithmic
> image of the data, I might want to do something like:
>
> w=where(image le 0)
> ww = where(image gt 0)
> qmin = min(image(ww))
> image(w) = .5*qmin
> tvscl,alog(image)
>
I know that this is not exactly what we are discussing here, but
how about
tvscl, alog( image > 0.5*min( image(where(image gt 0))) )
BTW, For Andy Loughe, note that we only ever need 1 line of
code, for maximum obfuscation. In this case if the where
statement fails, you are screwed anyway.
For Tom, I won't guarantee that this takes any less time.
--
Paul Schopf mailto://schopf@gsfc.nasa.gov
Coupled Climate Dynamics Group/971 http://ccdg.gsfc.nasa.gov/~paul
NASA Goddard Space Flight Center
Greenbelt, MD 20771
|
|
|
Re: [Q]IDL: Using WHERE. [message #5965 is a reply to message #5962] |
Thu, 21 March 1996 00:00  |
Thomas A. McGlynn
Messages: 23 Registered: March 1996
|
Junior Member |
|
|
Mark Rivers wrote:
>
> In article <314F31C4.2C6B@cdc.noaa.gov>, Andy Loughe <afl@cdc.noaa.gov> writes:
>> Joe Fitzgerald wrote:
>
>>> Is there a way to use B to get the complementary values; i.e., the array
>>> of subscripts for which ARRAY is less than 20?
>
>> Uh! This is a set-up, isn't it?
>> Is my boss watching?
>> How about LESS THAN OR EQUAL TO? That would be complementary.
>>
>> Why use B? Why not use...
>> C = Where(array LE 20., count)
>> if (count gt 0) then print, 'Hurray!'
>
> I think the idea was to use B to avoid the potentially expensive operation of
> comparing the entire array again to find the complementary elements.
>
> I think this will cut the computation time:
>
> t = (array gt 20) ; t(i) will be 0 or 1 depending upon comparison
> b = where(t) ; b is the indices of the > 20 elements
> c = where(t-1) ; c is the indices of the <= 20 elements
>
> This method avoids doing the floating point comparison twice.
>
> ____________________________________________________________
> Mark Rivers (312) 702-2279 (office)
> CARS (312) 702-9951 (secretary)
> Univ. of Chicago (312) 702-5454 (FAX)
> 5640 S. Ellis Ave. (708) 922-0499 (home)
> Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
This is something that I've always wanted to be able to do efficiently
but seem always to need to go through large arrays twice.
I frequently run into the situation that I want to do one thing for
one set of pixels and another for all of the rest, e.g., if I have an image
with some bad pixels set to <0 and I want to display a logarithmic
image of the data, I might want to do something like:
w=where(image le 0)
ww = where(image gt 0)
qmin = min(image(ww))
image(w) = .5*qmin
tvscl,alog(image)
It would be extremely useful if there were an optional, perhaps keyword,
parameter in where which gave the complement of the array-elements retrieved
so that one needn't call where twice, i.e.,
w=where(image le 0, complement=ww)
would replace the first two lines above. I imagine this could be substantially
faster than running where twice or using '<' or '>' operators to
replace one of the where's.
Tom McGlynn
Goddard Space Flight Center
|
|
|
Re: [Q]IDL: Using WHERE. [message #5973 is a reply to message #5962] |
Wed, 20 March 1996 00:00  |
Mirko Vukovic
Messages: 124 Registered: January 1996
|
Senior Member |
|
|
Mark Rivers wrote:
> I think this will cut the computation time:
>
> t = (array gt 20) ; t(i) will be 0 or 1 depending upon comparison
> b = where(t) ; b is the indices of the > 20 elements
> c = where(t-1) ; c is the indices of the <= 20 elements
>
> This method avoids doing the floating point comparison twice.
> Yesss!! good thinking and thanks a lot. I was wondering how one might
be able to accomplish this
--
Mirko Vukovic, Ph.D. mirko.vukovic@grc.varian.com
Varian Research Center Phone: (415) 424-4969
3075 Hansen Way, M/S K-109 Fax: (415) 424-6988
Palo Alto, CA 94304-1025
|
|
|
Re: [Q]IDL: Using WHERE. [message #5974 is a reply to message #5973] |
Wed, 20 March 1996 00:00  |
rivers
Messages: 228 Registered: March 1991
|
Senior Member |
|
|
In article <314F31C4.2C6B@cdc.noaa.gov>, Andy Loughe <afl@cdc.noaa.gov> writes:
> Joe Fitzgerald wrote:
>> Is there a way to use B to get the complementary values; i.e., the array
>> of subscripts for which ARRAY is less than 20?
> Uh! This is a set-up, isn't it?
> Is my boss watching?
> How about LESS THAN OR EQUAL TO? That would be complementary.
>
> Why use B? Why not use...
> C = Where(array LE 20., count)
> if (count gt 0) then print, 'Hurray!'
I think the idea was to use B to avoid the potentially expensive operation of
comparing the entire array again to find the complementary elements.
I think this will cut the computation time:
t = (array gt 20) ; t(i) will be 0 or 1 depending upon comparison
b = where(t) ; b is the indices of the > 20 elements
c = where(t-1) ; c is the indices of the <= 20 elements
This method avoids doing the floating point comparison twice.
____________________________________________________________
Mark Rivers (312) 702-2279 (office)
CARS (312) 702-9951 (secretary)
Univ. of Chicago (312) 702-5454 (FAX)
5640 S. Ellis Ave. (708) 922-0499 (home)
Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
|
|
|
Re: [Q]IDL: Using WHERE. [message #5979 is a reply to message #5973] |
Tue, 19 March 1996 00:00  |
Andy Loughe
Messages: 174 Registered: November 1995
|
Senior Member |
|
|
Joe Fitzgerald wrote:
>
> Where finds the non-zero elements of an array; e.g.
Huh?
If array=[30, 40, 10, 0]? Then B=[0,1]
If array=dist(10)-50., then B=-1
> array = FINDGEN(100)
> B = Where(array GT 20., count)
> B is an array containing the subscripts of ARRAY for values greater than
> 20.
Yes. If there are any (see above example)!
> Is there a way to use B to get the complementary values; i.e., the array
> of subscripts for which ARRAY is less than 20?
Uh! This is a set-up, isn't it?
Is my boss watching?
How about LESS THAN OR EQUAL TO? That would be complementary.
Why use B? Why not use...
C = Where(array LE 20., count)
if (count gt 0) then print, 'Hurray!'
If you must use B, then try using the uniq function.
--
Andrew F. Loughe (afl@cdc.noaa.gov)
University of Colorado, CIRES * Campus Box 449 * Boulder, CO 80309
phone: (303) 492-0707 fax: (303) 497-7013
|
|
|