I have lots of data cubes that need to be descrambled before they can be analyzed.
I was trying to figue out why the I/O was so slow and the culprit turned out to be my use of the REVERSE() function for 3d images.
So I wrote my own 4 line code and found a factor of ~20 speed improvement.
function reverse3,im
;Much faster than REVERSE(,1) for 3d images
dim = size(im,/dim)
for i=0,dim[2]-1 do $
im[0,0,i] = rotate(im[*,*,i],5) ;Rotate(,5) = Reverse(,1) for 2d
return,im
end
Below is a sample test to show the speed improvement.
IDL> a = randomn(seed,128,2048,50)
IDL> acopy=a
IDL> tic & b = reverse(a,1) & toc
% Time elapsed: 1.7325780 seconds.
IDL> tic & b1 = reverse3(acopy) & toc
% Time elapsed: 0.080199957 seconds.
IDL> array_equal(b,b1)
1
IDL> print,!version
{ x86_64 linux unix linux 8.5 Jul 7 2015 64 64}
REVERSE() is a standard IDL function, although the source code is available.
The code was updated to handle 3D in 1991.
It comments that the code could be faster but that it needs to conserve memory.
I would think that computer memory is slightly more available now than in 1991 ;-)
--Wayne