comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: a newbie question on code efficiency
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: a newbie question on code efficiency [message #26277] Mon, 20 August 2001 11:06 Go to next message
Dominic R. Scales is currently offline  Dominic R. Scales
Messages: 12
Registered: April 2001
Junior Member
David Fanning wrote:

> Folks,
>
> I'm writing "A GE 50" *not* (and I repeat, *not*) "A > 50".
>
> IDL> print, a GE 50
> 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0
> 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1
>
> Cheers,
>
> David

Argh, pardon me, please.
You've pointed it out ever so clear. Seems that people who can
read DO have advatages in life...

Yours humbly,
Dominic


--
Dipl. Phys. Dominic R. Scales | Aero-Sensing Radarsysteme GmbH
Tel: +49 (0)8153-90 88 90 | c/o DLR Oberpfaffenhofen
Fax: +49 (0)8153-908 700 | 82234 Wessling, Germany
WWW: aerosensing.de | email: Dominic.Scales@aerosensing.de
Re: a newbie question on code efficiency [message #26291 is a reply to message #26277] Sat, 18 August 2001 12:26 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
GB Smith (gogosgogos@usa.net) writes:

> i feel soooo stupid :)
> better go back to the books and study the old fashioned way :P

Yeah, well, it happens to, uh, all of us occasionally.
Although usually it has something to do with a
Histogram function. :-(

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: a newbie question on code efficiency [message #26292 is a reply to message #26291] Sat, 18 August 2001 11:31 Go to previous messageGo to next message
gogosgogos is currently offline  gogosgogos
Messages: 15
Registered: July 2001
Junior Member
quote: 'Relational operators apply a relation to two operands and
return a logical value of true or false'

i feel soooo stupid :)
better go back to the books and study the old fashioned way :P

thank you all for this valuble advice, i would have been stuck
here for over a week without ur help.
Re: a newbie question on code efficiency [message #26293 is a reply to message #26292] Sat, 18 August 2001 06:41 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Dominic R. Scales (dominic.scales@aerosensing.de) writes:

> Hi David,
>
> this seems to be not true as b = a > cutoff sets the values smaller
> than cutoff to cutoff and keeps the others as they are.
>
> IDL> a=bindgen(10,10)
> IDL> b = a > 50
> IDL> print,a
> 0 1 2 3 4 5 6 7 8 9
> 10 11 12 13 14 15 16 17 18 19
> 20 21 22 23 24 25 26 27 28 29
> 30 31 32 33 34 35 36 37 38 39
> 40 41 42 43 44 45 46 47 48 49
> 50 51 52 53 54 55 56 57 58 59
> 60 61 62 63 64 65 66 67 68 69
> 70 71 72 73 74 75 76 77 78 79
> 80 81 82 83 84 85 86 87 88 89
> 90 91 92 93 94 95 96 97 98 99
> IDL> b= a > 50
> IDL> print,b
> 50 50 50 50 50 50 50 50 50 50
> 50 50 50 50 50 50 50 50 50 50
> 50 50 50 50 50 50 50 50 50 50
> 50 50 50 50 50 50 50 50 50 50
> 50 50 50 50 50 50 50 50 50 50
> 50 51 52 53 54 55 56 57 58 59
> 60 61 62 63 64 65 66 67 68 69
> 70 71 72 73 74 75 76 77 78 79
> 80 81 82 83 84 85 86 87 88 89
> 90 91 92 93 94 95 96 97 98 99
> IDL>
>
> the following does the trick:
>
> IDL> b[where(a le 50)] = 0
> IDL> b[where(a gt 50)] = 1
> IDL> print,b
> 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0
> 0 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1
> 1 1 1 1 1 1 1 1 1 1

Folks,

I'm writing "A GE 50" *not* (and I repeat, *not*) "A > 50".

IDL> print, a GE 50
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: a newbie question on code efficiency [message #26294 is a reply to message #26293] Sat, 18 August 2001 05:44 Go to previous messageGo to next message
Dominic R. Scales is currently offline  Dominic R. Scales
Messages: 12
Registered: April 2001
Junior Member
David Fanning wrote:

> Uh, I think you must have tried this:
>
> e = b > cutoff
>
> I can assure you that this:
>
> e = b GT cutoff
>
> gives you a mask of 0s and 1s. :-)
>
> Cheers,
>
> David
>
Hi David,

this seems to be not true as b = a > cutoff sets the values smaller
than cutoff to cutoff and keeps the others as they are.

IDL> a=bindgen(10,10)
IDL> b = a > 50
IDL> print,a
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99
IDL> b= a > 50
IDL> print,b
50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50 50 50
50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69
70 71 72 73 74 75 76 77 78 79
80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99
IDL>

the following does the trick:

IDL> b[where(a le 50)] = 0
IDL> b[where(a gt 50)] = 1
IDL> print,b
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
IDL>


--
Dipl. Phys. Dominic R. Scales | Aero-Sensing Radarsysteme GmbH
Tel: +49 (0)8153-90 88 90 | c/o DLR Oberpfaffenhofen
Fax: +49 (0)8153-908 700 | 82234 Wessling, Germany
WWW: aerosensing.de | email: Dominic.Scales@aerosensing.de
Re: a newbie question on code efficiency [message #26295 is a reply to message #26294] Sat, 18 August 2001 05:22 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
GB Smith (gogosgogos@usa.net) writes:

>> e = b GE cutoff
>>
>> Cheers,
>>
>> David
>
> well, i thought of that already and it just kept all the values above cutoff
> but did not set them to 1. my array has values between 0 and 255 and i want
> to set all the values higher than 180 to 1 and all the rest to 0.
>
> maybe i did not put it that clear in the first post :)
>
> sorry...

Uh, I think you must have tried this:

e = b > cutoff

I can assure you that this:

e = b GT cutoff

gives you a mask of 0s and 1s. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: a newbie question on code efficiency [message #26296 is a reply to message #26295] Sat, 18 August 2001 04:10 Go to previous messageGo to next message
Dominic R. Scales is currently offline  Dominic R. Scales
Messages: 12
Registered: April 2001
Junior Member
GB Smith wrote:
>
>> e = b GE cutoff
>>
>> Cheers,
>>
>> David
>
> well, i thought of that already and it just kept all the values above cutoff
> but did not set them to 1. my array has values between 0 and 255 and i want
> to set all the values higher than 180 to 1 and all the rest to 0.
>
> maybe i did not put it that clear in the first post :)
>
> sorry...

Hi GB,

is this what you are looking for?

e = b
e[where(b le 180)] = 0
e[where(b gt 180)] = 1

Cheers,
Dominic

--
Dipl. Phys. Dominic R. Scales | Aero-Sensing Radarsysteme GmbH
Tel: +49 (0)8153-90 88 90 | c/o DLR Oberpfaffenhofen
Fax: +49 (0)8153-908 700 | 82234 Wessling, Germany
WWW: aerosensing.de | email: Dominic.Scales@aerosensing.de
Re: a newbie question on code efficiency [message #26297 is a reply to message #26296] Sat, 18 August 2001 03:13 Go to previous messageGo to next message
gogosgogos is currently offline  gogosgogos
Messages: 15
Registered: July 2001
Junior Member
> e = b GE cutoff
>
> Cheers,
>
> David

well, i thought of that already and it just kept all the values above cutoff
but did not set them to 1. my array has values between 0 and 255 and i want
to set all the values higher than 180 to 1 and all the rest to 0.

maybe i did not put it that clear in the first post :)

sorry...
Re: a newbie question on code efficiency [message #26298 is a reply to message #26297] Fri, 17 August 2001 20:47 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
GB Smith (gogosgogos@usa.net) writes:

> i have a little challenge for you which i stumbled into..
> i tried to write a program which takes a 3d array,
> sets a cutoff at a certain level and then creates a mask
> of all values above that level. the mask has to be 1 and 0.
> i came up with this code, but could never get rid of the loop.
>
> any suggestions on how to get rid of the loop?
> i would prefer array operators for speed :)
>
> ;----------------------------------------------------------- ------
>
> PRO MAKE_MASK
>
> a = dialog_pickfile()
> b = READ_BINARY(a, DATA_TYPE=1, DATA_DIMS=[160,256,256])
>
> b_dims = size(b)
> x_dim = b_dims[1]
> y_dim = b_dims[2]
> z_dim = b_dims[3]
>
> cutoff = 180
>
>
> e = b
>
> for i = 0, (x_dim-1) do begin
> for j = 0, (y_dim-1) do begin
> for k = 0, (z_dim-1) do begin
>
> if e[i,j,k] lt cutoff then e[i,j,k]=0
> if e[i,j,k] ge cutoff then e[i,j,k]=1
>
> endfor
> endfor
> endfor
>
> ; and so on to use the mask further in the program
>
>
> END

My goodness, an array operator question even I
can handle! :-)

e = b GE cutoff

Cheers,

David
--

---
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: a newbie question on code efficiency [message #26533 is a reply to message #26291] Sun, 09 September 2001 11:48 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
David Fanning wrote:
>
> GB Smith (gogosgogos@usa.net) writes:
>
>> i feel soooo stupid :)
>> better go back to the books and study the old fashioned way :P
>
> Yeah, well, it happens to, uh, all of us occasionally.
> Although usually it has something to do with a
> Histogram function. :-(
>
> Cheers,
>
> David
>
> --
> David W. Fanning, Ph.D.
> Fanning Software Consulting
> Phone: 970-221-0438, E-mail: david@dfanning.com
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155


Here is my solution,

cut_off=180
x=indgen(255)
v=make_array(/int,255 ,value=cut_off)
x[((x-v) >1 +cut_off)]=1
print,x

0 1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35
36 37 38 39 40 41 42 43 44
45 46 47 48 49 50 51 52 53
54 55 56 57 58 59 60 61 62
63 64 65 66 67 68 69 70 71
72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98
99 100 101 102 103 104 105 106 107
108 109 110 111 112 113 114 115 116
117 118 119 120 121 122 123 124 125
126 127 128 129 130 131 132 133 134
135 136 137 138 139 140 141 142 143
144 145 146 147 148 149 150 151 152
153 154 155 156 157 158 159 160 161
162 163 164 165 166 167 168 169 170
171 172 173 174 175 176 177 178 179
180 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1


regards

Reimar

--
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg1/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml

http://www.fz-juelich.de/zb/text/publikation/juel3786.html
============================================================ ======

read something about linux / windows
http://www.suse.de/de/news/hotnews/MS.html
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: object graphic / direct graphic
Next Topic: call_method

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 14:01:08 PDT 2025

Total time taken to generate the page: 0.00604 seconds