pro refsub_h1rg, input_data, output_data, fwindow=fwindow, order=order, degree=degree, plot=plot, simple=simple, verbose=verbose ; Name: ; refsub_H1RG.pro ; ; PURPOSE: ; This program performs a reference pixel correction ; on Rockwell HAWAII-1RG detector data when read out using 2 ; outputs. ; ; CALLING SEQUENCE: ; refsub_H1RG, input_data, output_data ; ; INPUTS: ; input_data - A 1024x1024 array containing the image data. ; output_data - A 1024x1024 fltarr for the result ; ; KEYWORD PARAMETERS: ; fwindow - The size of the filter window. ; order - Filter order, see the SAVGOL help page ; degree - Filter degree, see the SAVGOL help page ; plot - Set this =1 to plot the fits ; simple - Set this =1 to subtract a median reference pixel ; ; verbose - Set this =1 for verbose mode. ; ; ; EXAMPLE ; IDL> fits_read, 'theImage.fits', myData, myHeader ; IDL> myNewDate = fltarr(1024, 1024) ; IDL> refsub_H1RG, myData, myNewData ; ; ; REFERENCE: ; ; This program has been approved by B.J. Rauscher for ; release to Rockwell, U. Hawaii, NASA Civil Servants, ; and others who have signed the relevant NDA with ; Rockwell. It contains competition sensitive ; information. ; ; ; MODIFICATION HISTORY: ; Written by: ; Modified: B.J. Rauscher, IDTL, August 4, 2002 ; Initial release ; B.J. Rauscher, IDTL, August 16, 2002 ; Modified to exclude outtermost reference pixels ; from statistics. These appear to be anomalously ; bright. ; B.J. Rauscher, IDTL, January 15, 2002 ; Handle the first and last 4 rows of reference ; pixels differently from others. This fixes a bug ; that was causing the first and last approximatelykernel size ; region of reference pixels to be effected by the ; reference rows. Include only rows [4:1019] in the area ; to be smoothed. In rows [0:3] and [1020:1023] use ; a row-by-row average of the reference columns. ; ;- ; The reference pixels on the Rockwell HAWAII-1RG SCA are the ; outermost 4 pixels all around the chip. This program makes a ; reference pixel correction using data in the regions [1:3,*] ; and [1020:1022,*]. ;; Set defaults if (not(keyword_set(plot))) then plot = 0 ; Default is no plots if (not(keyword_set(simple))) then simple = 0; Default is Savitzky-Golay filter if (not(keyword_set(verbose))) then verbose = 0; Default is quiet mode ;; We will use a Savitzky-Golay filter to smooth the reference pixel data. ;; See the SAVGOL procedure's help page for more information on ;; the following. if (not(keyword_set(fwindow))) then fwindow = 64 ; Default uses 64 pixels on ; either side of current pixel ; for smoothing if (not(keyword_set(order))) then order = 0; Use zero to smooth if (not(keyword_set(degree))) then degree=3; Three seems reasonable ;; Extract and average reference pixels row = intarr(1024) ; Y values vector. Undersize mean_refcol_l = fltarr(1024) ; Signals vector on left mean_refcol_r = fltarr(1024) ; Signals vector on right for y=0, 1023 do begin row[y] = y ;; Do not use the first reference pixel on each output. It ;; appears to be anomalous (contains signal, this may be memory). mean_refcol_l[y] = mean(input_data[1:3,y]) ; Average left side reference pixels mean_refcol_r[y] = mean(input_data[1020:1022,y]) ; Average right side reference pixels endfor ;; Sigma clip to get rid of outliers sigclip, mean_refcol_l, threshold=3.0, maxiter=5 sigclip, mean_refcol_r, threshold=3.0, maxiter=5 if (verbose) then begin print, 'Mean reference pixel on left = ', mean(input_data[0:3,*]) print, 'Mean reference pixel on right = ', mean(input_data[1020:1023,*]) endif ;; Apply reference pixel correction smooth_refcol_l = mean_refcol_l; Create arrays to hold the smoothed ref. col smooth_refcol_r = mean_refcol_r; if (not simple) then begin ;; Apply Savitzky-Golay filter. See the SAVGOL help page for ;; more information. ;; ;; Exclude the first and last 4 rows from convolution with the kernel. These are ;; reference rows and they need to be handled differently for unknown ;; physical reasons. savgol_filter = savgol(fwindow, fwindow, order, degree) smooth_refcol_l[4:1019] = convol(mean_refcol_l[4:1019], savgol_filter, /EDGE_TRUNCATE) smooth_refcol_r[4:1019] = convol(mean_refcol_r[4:1019], savgol_filter, /EDGE_TRUNCATE) endif else begin ;; Apply simple reference pixel correction. for y=0, 1023 do begin smooth_refcol_l[y] = mean(mean_refcol_l) smooth_refcol_r[y] = mean(mean_refcol_r) endfor endelse ;; Make plots if requested ;; if (plot) then begin set_device = 'X' !P.MULTI = [0,1,2] ; Plot 1 plot over the other ;; First plot left hand reference pixels plot, row, mean_refcol_l, $ title = 'Mean Reference Column [1:3,*]', $ xtitle = 'Row Number', $ ytitle = 'Signal (ADU)', $ xrange = [0,1023], $ xstyle = 1 ;; Draw a smooth curve through pixels oplot, row, smooth_refcol_l, thick=3 ;; Now plot right hand reference pixels plot, row, mean_refcol_r, $ title = 'Mean Reference Column [1020:1022,*]', $ xtitle = 'Row Number', $ ytitle = 'Signal (ADU)', $ xrange = [0,1023], $ xstyle = 1 ;; Draw a smooth curve through points. oplot, row, smooth_refcol_r, thick=3 !P.MULTI = 0 ; Return to default plotting mode endif ;; Perform reference pixel correction for x=0, 511 do begin output_data[x,*] = input_data[x,*] - smooth_refcol_l output_data[1023-x,*] = input_data[1023-x,*] - smooth_refcol_r endfor end