;Compacts an arranged stack ; input ; L - arranged stack, as returned by arrange_stack() ; ; returns ; a 3D compacted array of floats. Each column result[x,y,*] has no NaN's "underneath" ; the real data. The array is the same thickness as the valid data part of the thickest ; pixel function compact_layers,l ;Get the original size of the stack s=size(l,/dimensions) n_x=s[0] n_y=s[1] n_layers=s[2] ;Keep track of maximum stack thickness max_overlap=1 ;Set up the return value new_stack=dblarr(n_x,n_y,1,/nozero)*!values.d_nan ;For each pixel column in the stack... for i_x=0,n_x-1 do begin for i_y=0,n_y-1 do begin ;Find the valid points in the column w=where(finite(l[i_x,i_y,*]),n_w) ;If there are any... if n_w gt 0 then begin ;Check if this is the thickest column so far... if n_w gt max_overlap then begin new_stack=[[[new_stack]],[[dblarr(n_x,n_y,n_w-max_overlap,/nozero)*!values.d_nan]]] max_overlap=n_w end ;Just record the valid data in the new stack new_stack[i_x,i_y,0:n_w-1]=l[i_x,i_y,w] end end end ;Return the new stack return,new_stack end