; NAME: ; linBkgdByCol.Pro ; ; PURPOSE: ; Returns a background image where the background for each column is calculated from ; two regions extracted around a trace. ; ; DESCRIPTION: ; Given a 2-D spectrum, it calculates a linear background for each column from a ; fit of the median of two background boxes. ; ; CALLING SEQUENCE: ; linBkgdByCol, pctr, offset1, offset2, image, bkgd ; ; INPUTS: ; pctr - The center of the Pluto trace. ; offset1 - The lower bound of the background box in pixels away from pctr. ; offset2 - The upper bound of the background box in pixels away from pctr. ; image - The A-B image ; ; OUTPUTS: ; bkgd - the resulting background image ; ; REVISON HISTORY: ; 28-APR-2004, CBO, SwRI ;- pro linBkgdByCol, pctr, offset1, offset2, image, outarr ; This procedure will extract two boxes equidistant from pctr. Using the mean coordinate ; of the columns in the box and the median value of the pixels, a line is fit. The ; line is the background for that column. Caution, do not apply this background far from ; pctr. x1 = mean([pctr-offset2,pctr-offset1]) x2 = mean([pctr+offset1,pctr+offset2]) sz = size(image, /DIM) p = findgen(sz[1]) outarr = fltarr(sz[0], sz[1]) for i=0, sz[0]-1 do begin y1 = median(image[i, pctr-offset2:pctr-offset1]) y2 = median(image[i, pctr+offset1:pctr+offset2]) slope = (y2 - y1)/(x2 - x1) intcpt = y1 - slope*x1 bkgd = slope*p + intcpt outarr[i,*] = bkgd end end pro linBkgdByColDRIVE file = '/Users/colkin/Work04/Pluto_3um/Reduction/fileNameMaxRow2' readcol, file, list1, list2, maxrow, format="A, A, F" num = n_elements(list1) offset1 = 15 offset2 = 25 ; dir1 = '/Users/colkin/Work04/Pluto_3um/Background3/' dir2 = '/Users/colkin/Work04/Pluto_3um/BackgroundSubt3/' datadir = '/Users/colkin/Work04/Pluto_3um/Rectified6/' dirAonly = '/Users/colkin/Work04/Pluto_3um/BackgroundAonly2/' for i=0, num-1 do begin d1 = readfits(datadir+list1[i]) d2 = readfits(datadir+list2[i]) linBkgdByCol, maxrow[i], offset1, offset2, d1-d2, outarr ; writefits, dir1+list1[i], outarr writefits, dir2+list1[i], d1-d2 - outarr ; need the background signal for each image to calculate the variance maps ; which are needed for the optimal extraction. linBkgdByCol, maxrow[i], offset1, offset2, d1, outarr writefits, dirAonly+list1[i], outarr endfor end pro linBkgdByColDRIVETriton dir = "/Users/colkin/Work04/Triton_NIRSPEC/" file = dir+"Reduction/filePairs" readcol, file, list1, list2, maxrow, format="A, A, F" num = n_elements(list1) offset1 = 15 offset2 = 25 dir2 = dir+'BackgroundSubt/' datadir = dir+'Rectified1/' dirAonly = dir+'BackgroundAonly/' for i=0, num-1 do begin d1 = readfits(datadir+list1[i]) d2 = readfits(datadir+list2[i]) linBkgdByCol, maxrow[i], offset1, offset2, d1-d2, outarr writefits, dir2+list1[i], d1-d2 - outarr ; need the background signal for each image to calculate the variance maps ; which are needed for the optimal extraction. linBkgdByCol, maxrow[i], offset1, offset2, d1, outarr writefits, dirAonly+list1[i], outarr endfor end