Re: Using where() on slices of data cubes [message #68448 is a reply to message #68346] |
Fri, 23 October 2009 13:27   |
JDS
Messages: 94 Registered: March 2009
|
Member |
|
|
On Oct 21, 6:20 pm, David Fanning <n...@dfanning.com> wrote:
> JD Smith writes:
>
>> On Oct 20, 4:32 pm, David Fanning <n...@dfanning.com> wrote:
>>> JD Smith writes:
>>>> you should easily be able to generalize the above arguments to access
>>>> these elements
>
>>> I think in this case the word "easily" might be
>>> too subtly sarcastic to be easily appreciated by
>>> the vast majority of this newsgroup. :-)
>
>> (Almost) no sarcasm was intended.
>
>> Suppose you have this:
>
>> w=where(cube[1,5:*,10:1024] lt 0)
>
>> The "slice" is no longer as large as the cube in the yz dimensions,
>> and is offset by [5,10] too. So
>
>> y_full_cube = slice_column + 5
>> z_full_cube = slice_row + 10
>
>> and since the slice is smaller than the cube by 5 columns, to convert
>> our WHERE index vector w into col,row in the slice, we use
>
>> slice_column = w mod (sz[1]-5)
>> slice_row = w/(sz[1]-5)
>
>> Putting it all together we have:
>
>> ind = 1 + sz[0] * (5 + w mod (sz[1]-5) + (10 + w/(sz[1]-5)) * sz[1])
>
> Ah, OK. Even Coyote seems to be catching on now. ;-)
>
> I'm curious if you have a method to test these indices?
>
> Those of us unused to typing (I would say *most* of us,
> but I don't want to offend anyone) would find it a challenge,
> probably, to type a line of code like this and get it right.
>
> How did you test this code to know it was correct?
My standard test uses a small bindgen array with an analogous offset.
Small so you can actually just check by printing it out. But I'll
admit I didn't even test in this case. Obviously for higher
dimensions this gets less useful.
IDL> a=bindgen(3,4,5)
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
IDL> slice=a[1,1:*,2:3]
IDL> print,slice
28
31
34
40
43
46
IDL> w=where(slice gt 0)
IDL> sz=[3,4,5]
IDL> print,1 + sz[0] * (1+ w mod (sz[1]-1) + (2+ w/(sz[1]-1)) * sz[1])
28 31 34 40 43
46
|
|
|