;+ ; NAME: ; NIRC2DEWARP ; ; PURPOSE: ; Remove distortion from an array of positions measured in a NIRC2 image. ; ; EXPLANATION: ; All three NIRC2 cameras have known distortion. This procedure returns ; rectified measured positions. ; ; A discussion of the NIRC2 optical quality is provided in the pre-ship ; testing document, available at: ; http://www.keck.hawaii.edu/realpublic/inst/nirc2/preship_testing.pdf ; and updated investigation of the distortion can be found at: ; http:// URL ; ; CALLING SEQUENCE: ; NIRC2DEWARP_POSITIONS(x_in, y_in, camera, x_out, y_out, [, version=version]) ; ; INPUTS: ; X_IN - Array of x-pixel positions ; ; Y_IN - Array of y-pixel positions ; ; CAMERA - Should be set to 'narrow', 'medium' or 'wide'. ; ; OPTIONAL INPUTS: ; None ; ; OPTIONAL KEYWORD PARAMETERS: ; VERSION - Version of the solution to be used. Default is 'new', ; but 'preship' is also available. ; ; OUTPUTS: ; X_OUT - array of corrected x-pixel positions. ; ; Y_OUT - array of corrected y-pixel positions. ; ; SIDE EFFECTS: ; ; RESTRICTIONS: ; Assumes the image is centered on the NIRC2 chip. ; PROCEDURE: ; ; EXAMPLE: ; IDL> readcol, 'wide_camera_positions.dat', x_in, y_in ; IDL> NIRC2DEWARP_POSITIONS, x_in, y_in, 'wide', x_out, y_out ; ; PROCEDURES CALLED: ; POLYSOL() - Provided ; ; MODIFICATION HISTORY: ; Written by P. B. Cameron, Caltech, March 2007. ; ;- FUNCTION NIRC2DEWARP_POSITIONS, x_in, y_in, camera, x_out, y_out, version=version ;;; 1. Cubic polynomial coefficients from pre-ship testing document x0 = 512. ; X origin of polynomial y0 = 512. ; Y origin of polynomial ;The offset terms are irrelevant for ;correcting distortion (which is ;simply relative). We set them here to ;zero for the new solution, but ;include them for the preship solution ;since they were used previously. if ( KEYWORD_SET(version) ) then begin vers=version endif else begin vers = 'new' endelse if( vers eq 'preship') then begin a = DBLARR(3,15) a[*,0] = [-2.7200d-01, -3.12530d-01, 4.0600d-01] a[*,1] = [ 1.0009d+00, 9.99382d-01, 1.0008d+00] a[*,2] = [ 5.0800d-03, 1.23970d-03, -3.2400d-03] a[*,3] = [-5.5200d-06, -2.80460d-06, -1.7500d-06] a[*,4] = [ 7.7000d-07, 1.20020d-06, -5.6000d-07] a[*,5] = [ 5.3700d-06, 1.08800d-05, 1.0000d-05] a[*,6] = [-8.6000d-09, -9.61700d-09, -6.8000d-09] a[*,7] = [-8.0000d-10, -1.51400d-09, 8.0000d-10] a[*,8] = [-6.1000d-09, -5.05300d-09, -3.6000d-09] a[*,9] = [-4.4000d-09, 3.90000d-10, 9.0000d-10] b = DBLARR(3,15) b[*,0] = [ 1.6800d-01, 3.87000d-01, 3.4000d-02] b[*,1] = [ 1.6000d-04, -1.40000d-04, 2.1000d-04] b[*,2] = [ 1.0008d+00, 9.95730d-01, 9.9477d-01] b[*,3] = [ 2.1000d-07, 7.60000d-07, -4.4000d-07] b[*,4] = [-9.9300d-06, -8.27000d-06, -9.2000d-07] b[*,5] = [ 1.7800d-06, 1.86000d-06, -1.5700d-06] b[*,6] = [-1.6000d-09, 3.00000d-10, 2.0000d-10] b[*,7] = [-2.8000d-09, -1.60000d-09, 2.6000d-09] b[*,8] = [-4.0000d-10, 8.00000d-10, 5.0000d-10] b[*,9] = [-1.2000d-08, -6.40000d-09, 5.9000d-09] endif else begin a = DBLARR(3,15) a[*,0] = [ 0d0, -3.12530d-01, 0d0] a[*,1] = [ 1.00116d+00, 9.99382d-01, 1.00258d+00] a[*,2] = [ 1.96010d-03, 1.23970d-03,-1.07553d-03] a[*,3] = [-3.14182d-06, -2.80460d-06,-8.44603d-07] a[*,4] = [-3.08788d-06, 1.20020d-06,-8.66153d-07] a[*,5] = [ 5.59549d-06, 1.08800d-05, 1.03161d-05] a[*,6] = [-6.04724d-09, -9.61700d-09,-2.80832d-09] a[*,7] = [ 6.53706d-10, -1.51400d-09, 2.11712d-12] a[*,8] = [-3.99943d-09, -5.05300d-09,-8.90944d-10] a[*,9] = [-1.63796d-09, 3.90000d-10,-3.14757d-11] a[*,10]= [-1.12204d-11, 0d0, 0d0] a[*,11]= [ 1.35291d-11, 0d0, 0d0] a[*,12]= [ 5.73354d-12, 0d0, 0d0] a[*,13]= [ 3.37186d-12, 0d0, 0d0] a[*,14]= [-8.50332d-13, 0d0, 0d0] b = DBLARR(3,15) b[*,0] = [ 0d0, 3.87000d-01, 0d0] b[*,1] = [ 1.75403d-03, -1.40000d-04,-1.39196d-03] b[*,2] = [ 1.00129d+00, 9.95730d-01, 9.96806d-01] b[*,3] = [-1.91215d-06, 7.60000d-07,-2.81300d-07] b[*,4] = [-1.16438d-05, -8.27000d-06,-5.77556d-07] b[*,5] = [-2.51404d-06, 1.86000d-06,-1.44116d-06] b[*,6] = [ 6.03978d-11, 3.00000d-10, 5.30766d-10] b[*,7] = [-3.24360d-09, -1.60000d-09, 4.39543d-09] b[*,8] = [-3.55861d-09, 8.00000d-10,-3.07567d-10] b[*,9] = [-8.66718d-09, -6.40000d-09, 7.84907d-09] b[*,10]= [ 5.17175d-12, 0d0, 0d0] b[*,11]= [ 2.66960d-12, 0d0, 0d0] b[*,12]= [ 5.29880d-12, 0d0, 0d0] b[*,13]= [ 7.83758d-12, 0d0, 0d0] b[*,14]= [ 4.80703d-12, 0d0, 0d0] endelse ;;; 2. Camera definition cam = STRTRIM(STRUPCASE(camera),2) i=-1 case cam of 'NARROW':i=0 'MEDIUM':i=1 'WIDE':i=2 endcase if(i eq -1) then begin print, 'Define camera. wide,medium or narrow.' return, -1 end ;;; 3. Set up x and y coordinate arrays x1 = x_in - x0 y1 = y_in - y0 ;;; 4. Perform transformation (x -> x') x_out = x0+POLYSOL(x1,y1,a[i,*]) y_out = y0+POLYSOL(x1,y1,b[i,*]) return, 1 END ;######################### FUNCTION POLYSOL, x, y, p n = p[0] + p[1]*x + p[2]*y + p[3]*x^2. + p[4]*x*y + p[5]*y^2. + $ p[6]*x^3. + p[7]*x^2*y + p[8]*x*y^2 + p[9]*y^3 + $ p[10]*x^4. + p[11]*x^3.*y + p[12]*x^2.*y^2. + p[13]*x*y^3. + p[14]*y^4. RETURN,n END