FUNCTION NDDIST2, DIMS, Centers ;+ ; Copyright (c) 1993 P. R. Blanco, CASS, 0111, UCSD, La Jolla, CA92093-0111, USA ; and SERC, Polaris House, North Star Avenue, SN2 1ET, United Kingdom. ; ; Calculates an array, of dimensions specified by DIMS, of (distances)^2 ; from the a central point specified by coordinates Centers. If the center ; is not specified, it is assumed to be at the origin of the array. ; ; Returns: ; NDDIST2 (Float array(DIMS)) - array of distances^2. ; ; Input Parameters: ; DIMS (Integer , vector(NDIM)) - List of dimensions for the output array ; Centers (Float, vector(NDIM), default FLTARR(NDIM)) - Coordinates of the ; center from which the distances^2 are calculated. ; ; History: ; 22 Sep 93 - written by P. R. Blanco, CASS/UCSD to replace a routine of ; the same name. ;- NDIM=N_ELEMENTS(DIMS) IF N_ELEMENTS(Centers) EQ 0 THEN Centers=FLTARR(NDIM) ; ; Calculate integer array of dimension products ; PROD=LONARR(NDIM) & PROD(0)=1 FOR I=0, NDIM-2 DO PROD(I+1)=DIMS(I)*PROD(I) ; ; Make an array of indices in the same dimensions as the output ; index= MAKE_ARRAY(/LONG, DIM=DIMS) & Dist2=FLOAT(index) NPTS=N_ELEMENTS(INDEX) & INDEX(*)=LINDGEN(NPTS) ; ; Count down through dimensions and add up the distances^2 along each axis ; FOR i= NDIM-1,0, -1 DO BEGIN Coord = index / PROD(I) index = index - Coord*PROD(I) Dist2 = Dist2 + (Coord-Centers(i))^2 ENDFOR ; RETURN, Dist2 END ;-------------------------------------------------------------------------- FUNCTION PXN_PSF, DistSQ, PEAK, BASE ; + ; PSF Generation- Parabolic version ; ; Produce a positive, parabolic PSF of height Peak and radius Base ; using the array DistSQ of distances^2 from some origin. ; Input parameters: ; DistSQ (N-dim. array, FLOAT) - array of (distances)^2 from some center. ; (DistSQ may be generated with the DIST function (USERLIB) for 2D data ; or NDDIST2(Im. Recon collection) for N-dimensional data). ; BASE (Scalar) - radius of the "base" of the PSF. If negative, a ; delta function at the origin is returned. ; PEAK (scalar) - height of the PSF ; ; History: ; 20 Aug 1993 - written by P. R. Blanco, UCSD, based on a routine by ; R. K. Pina and R. C. Puetter. ;- A=DistSQ & A(*)=0 ; Make our answer the same type and dimensions as DistSQ ; Base2 = FLOAT(Base^2) IF ( Base LE 0.0 ) THEN BEGIN ; ; Return a delta function at the 1st occurence of the minimum distance ; MINDIST=MIN(DistSQ) & MINPLACE=(WHERE(DistSQ LE MINDIST))(0) A(MINPLACE)=Peak RETURN, A ENDIF $ ELSE BEGIN ; ; Find all pixels where the parabola will be positive (within Base radius) ; and set these equal to the parabolic function ; VALID=WHERE(DistSQ LE Base2, N_VALID) ; find points inside base radius IF N_VALID GT 0 THEN A(VALID)=Peak*(1-DistSQ(VALID)/Base2) RETURN, A ENDELSE END ;-------------------------------------------------------------------------- FUNCTION NDSHIFT, Data, Vector ;+ ; Copyright (c) 1993 P. R. Blanco and ; SERC, Polaris House, North Star Ave. Swindon SN2 1ET, United Kingdom. ; ; Shifts an array in by Vector(1,2,3...) elements in N-dimensions ; Due to the inflexibility of IDL's SHIFT command each number of ; dimensions is handled separately. If an error occurs, the original ; input array is returned. ; ; Input parameters: ; Data (array) - the array to be shifted ; Vector (1-D array, size = no. of dimensions of array Data) - Size and ; direction of shift. Vector may be a scalar if Data is a 1-D array. ; ; History: ; 17 August 1993- new version by P. R. Blanco, CASS/UCSD. ; Handles 0 to 5 dimensions. ;- SD=SIZE(Data) N_DIM=SD(0) ; IF N_ELEMENTS(Vector) NE N_DIM THEN BEGIN MESSAGE, 'Incompatible dimensions of data and shift array', /INFO print, SIZE(Data), Vector RETURN, Data ENDIF ; CASE N_DIM OF 0: BEGIN MESSAGE, 'Argument is a scalar or un-defined variable!' RETURN, Data END 1: RETURN, SHIFT(Data, Vector(0)) 2: RETURN, SHIFT(Data, Vector(0), Vector(1)) 3: RETURN, SHIFT(Data, Vector(0), Vector(1), Vector(2)) 4: RETURN, SHIFT(Data, Vector(0), Vector(1), Vector(2), Vector(3)) 5: RETURN, SHIFT(Data, Vector(0), Vector(1), Vector(2), Vector(3), Vector(4)) ELSE: BEGIN MESSAGE, 'Number of dimensions = '+STRTRIM(N_DIM,2)+ $ ' - NDSHIFT cannot deal with that many yet - edit NDSHIFT.PRO!' RETURN, Data END ENDCASE ; END ;-------------------------------------------------------------------------- FUNCTION WRAP, ARRAY ;+ ; Returns an array in wraparound order ; Due to the inflexibility of IDL's SHIFT command each number of ; dimensions is handled separately by NDSHIFT. If an error occurs, ; the original input array is returned. ; Input parameter: ; ARRAY (Array) - array to be wrapped around by 1/2 its dimensions. ; ; Calls: ; NDSHIFT (Im. Recon. collection) - general N(<=5)-dimensional array shift ; ; History: ; 17 August 1993- new version by P. R. Blanco, CASS/UCSD, based on ; the original routine by R. K. Pina. Handles 0 to 5 dimensions. ; ;- ARRSZ = SIZE(array) & NDIM=ARRSZ(0) MIDDLE=ARRSZ(1:NDIM)/2 RETURN, NDSHIFT(ARRAY, MIDDLE) ; END ;-------------------------------------------------------------------------- FUNCTION CONV, IM1, IM2 ;+ ; N-D convolution without normalization ; Input: ; IM1, IM2 (Arrays, float) - arrays to be convolved ; ; Returns: ; A FLOAT array of the pure convolution ; ; Calls: ; WRAP (Im. Recon. collection) - Wrap an N-dimensional array such that the ; corners meet at the center. ;- f_im1 = FFT(im1,1) f_im2 = FFT(WRAP(im2),1) f_prod = f_im1*f_im2 RETURN, FLOAT( FFT(f_prod,-1) ) END ;-------------------------------------------------------------------------- FUNCTION smooth_image,image,scale sz = SIZE(image) dims = sz(1:2) ; create array of distance square from central pixel distsq = nddist2(dims, dims/2.0) ; create weighted pixon over which to smooth pixon = pxn_psf( distsq, 1.0, scale ) ; normalize pixon to unit area pixon = pixon/TOTAL(pixon) ; smooth data over scale of pixon image = conv(pixon,image) RETURN, image END