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

Home » Public Forums » archive » Subscripting help
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Subscripting help [message #92211 is a reply to message #92206] Thu, 29 October 2015 11:28 Go to previous messageGo to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Thursday, October 29, 2015 at 10:44:28 AM UTC-4, KH wrote:
> Hello,
>
> I need to convert a large 2D array to a smaller 1D array by taking the mean of several pixels in the 2D array before putting them into known locations in the 1D array (or bin). The challenge is that the number of pixels per bin varies so I don't know how to do it without creating a large loop. I was hoping there was a way I could do it with subscripts, but I haven't been able to figure it out yet.
>
> Here is an example of what I want to do using a loop. It works fine for this example, but my real 2D array is 8640x4320 and I need to move it to a ~5.6 million 1D array and it would take days to run it in a loop.
>
> ARR_2D = FINDGEN(9,10) ; Input 2D array
> ARR_1D = FLTARR(18) ; Output 1D array (bins)
>
> ; MAKE UP SUBSCRIPTS FOR THE ARRAY TO FIT INTO THE BINS (KNOWN BIN LOCATIONS)
> SUBS = LONG(ARR_2D)
> S = [REVERSE(INDGEN(9)+1),INDGEN(9)+1]
> FOR N=0, N_ELEMENTS(S)-1 DO BEGIN
> IF N EQ 0 THEN FSUB = 0 ELSE FSUB = LSUB
> IF N EQ 0 THEN LSUB = S(N)-1 ELSE LSUB = FSUB + S(N)
> SUBS(FSUB:LSUB) = N
> ENDFOR
>
>
> ; LOOP METHOD
> FOR N=0, N_ELEMENTS(ARR_1D)-1 DO BEGIN
> OK = WHERE(SUBS EQ N, COUNT)
> IF COUNT GE 1 THEN ARR_1D(N) = MEAN(ARR_2D(OK))
> ENDFOR
>
> PRINT, ARR_2D
> PRINT
> PRINT, ARR_1D
>
> Is there a faster way to get the same results? I was trying to figure out a way to do it with subscripts, but haven't had much success.
>
> Thanks for your input.
> Kim

This article is must-read for any problem like this. Basically, you want to use the double-histogram technique.

http://www.idlcoyote.com/code_tips/drizzling.html

-Jeremy.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Histogram within a colorbar
Next Topic: Read data from file

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

Current Time: Fri Oct 10 06:29:24 PDT 2025

Total time taken to generate the page: 0.31902 seconds