;+ ; ; NAME : SUMER_DISTORT_COR ; gives the destretched image of a SUMER spectrum ; based on a bilinear interpolation scheme ; CALIING SEQUENCE: ; REsult=SUMER_DISTORT_COR( Data, Refw, Refy, ; Refw_n, Ref_n,Detector=Detector) ; INPUTS: ; Data : a spectrum image ; (2 D :n_spectral x n_spatial) ; (3 D :n_spectral x n_spatial x n_step) ; (4 D :n_spectral x n_spatial x n_step x n_line) ; Refw : the column position of the lower ; left corner of the spectrum on the detector plane. ; 0:shorter wavelength side ege, ; 1023 :longer wavength side edge ; (Scalars) : in case of 1 line ; (1 D : n_line) : in case of lines more than 1 ; Refy : the row position of the lower ; left corner of the spectrum on the detector plane. ; ; OUTPUTS: ; ; Xoff_new, Yoff_new : the position of ; the new corrected sprectrum on the detector ; plane ; ; ; OUPUTS: ; DATA : distortion corrected data ; with the same dimensions as the input data ; KEYWORD ; Detector : 'a' or 'b' ( case insensitive) ; ; When one repeatedly calls this routine for ; a set of data obtained using the same detector, ; he may specify this keyword only in the first ; call and omit it after the first call ; since the common block DISTORT_BLOCK keeps the ; distortion data for that detector. ; This speeds up this routine by skipping ; data reading. ; ; ; ; RESTRICTIONS : ; The data files :del_x_at.fits, del_x_at.fits, ; del_x_bt.fits, del_x_bt.fits ; should exist in one of the directories in IDL path ; HISTORY ; December 1996, Jongchul CHAE ; April 1997 J Chae change of routine name and arguments ;- ; function sumer_distort_cor, data, xoff_data, yoff_data, $ xoff_new, yoff_new, detector=detector, xoff=xoff, yoff=yoff common distort_block, del_x, del_y if n_elements(xoff) eq 0 then xoff=0. if n_elements(yoff) eq 0 then yoff=0. print, 'xoff, yoff=', xoff, yoff if n_elements(detector) eq 1 then begin det=strlowcase(detector) del_x_file=concat_dir(!sumer_config.aux_dir,'del_x_'+det+'t.fits') if not file_exist(del_x_file) then begin tmp=widget_message('The file '+'del_x_'+det+'t.fits'+' can not be found.', /error) return,0 endif del_x = readfits(del_x_file)/1000. del_y_file=concat_dir(!sumer_config.aux_dir, 'del_y_'+det+'t.fits') if not file_exist(del_y_file) then begin tmp=widget_message('The file '+'del_y_'+det+'t.fits'+' can not be found.', /error) return,0 endif del_y = readfits(del_y_file)/1000. if n_elements(data) eq 0 then return,0 endif nx=n_elements(data(*,0,0,0)) ny=n_elements(data(0,*, 0,0)) ns = n_elements(data(0,0,*,0)) n_line= n_elements(data(0,0,0,*)) if n_elements(xoff_data) eq 0 then xoff_data=0 if n_elements(yoff_data) eq 0 then yoff_data=0 xcen_old = xoff_data+nx/2 ycen_old = yoff_data+ny/2 xcen_new = xcen_old-del_x(xcen_old, ycen_old)*(1-xoff) ycen_new = ycen_old-del_y(xcen_old, ycen_old)*(1-yoff) xoff_new = (xcen_new-nx/2)>0<1023 yoff_new = (ycen_new-ny/2)>0<359 value=data*0 det_image=fltarr(1024, 360) for s=0, ns-1 do begin det_image=det_image*0 for i=0, n_line-1 do $ det_image(xoff_data(i):xoff_data(i)+nx-1, yoff_data(i):yoff_data(i)+ny-1) = $ data(*,*,s, i) for i=0, n_line-1 do begin x_new = indgen(nx)#replicate(1, ny) +xoff_new(i) y_new = replicate(1, nx)#indgen(ny) +yoff_new(i) sign= 1 xm1=x_new>0<1023 ym1=y_new>0<359 for k=0, 3 do begin xm1=(sign*del_x(xm1, ym1)*(1-xoff)+x_new)>0<1023 ym1=(sign*del_y(xm1, ym1)*(1-yoff)+y_new)>0<359 endfor tmp=bilinear(det_image, xm1,ym1) ; y_new-yoff_new(i)) value(*,*,s,i)=tmp ; bilinear(tmp, x_new-xoff_new(i), ym1) endfor endfor return, value end