; NAME: ; extractspec_xs ; ; PURPOSE: ; Extracts extended source spectra ; ; CATEGORY: ; data reduction ; ; CALLING SEQUENCE: ; result = extractspec_xs(image,var,edgecoeffs,tracecoeffs,norders,naps,$ ; start,stop,xranges,slit_arc,apradii,BGR=bgr,$ ; BGORDER=bgorder,UPDATE=update,$ ; WIDGET_ID=widget_id,CANCEL=cancel) ; ; INPUTS: ; image - A 2-D image with spectra to be extracted ; var - The variance image ; edgecoeffs - Array [degree+1,2,norders] of polynomial coefficients ; which define the edges of the orders. array[*,0,0] ; are the coefficients of the bottom edge of the ; first order and array[*,1,0] are the coefficients ; of the top edge of the first order. ; tracecoeffs - Array [fitdegree+1,naps*norders] of polynomial ; coefficients of the traces of the apertures. ; The coefficients should be indexed starting with ; the bottom order and looping through the apertures ; in that order. ; norders - The number of orders ; naps - The number of apertures ; start - Start column ; stop - Stop column ; xranges - An array [2,norders] of pixel positions where the ; orders are completely on the array ; slith_arc - Slit length in arcseconds ; apradii - Array of aperture radii in arcseconds ; ; OUTUTS: ; Returns an (stop-start+1,naps*norders) array of spectra. ; ; KEYWORD PARAMETERS: ; BGR - (Background Regions) Array of background regions ; in arcseconds ([[1,2],[13-15]]). ; BGORDER - Polynomial fit degree order of the background. If ; omitted, then the background is not subtracted. ; UPDATE - If set, the program will launch the Fanning ; showprogress widget. ; WIDGET_ID - If given, a cancel button is added to the Fanning ; showprogress routine. The widget blocks the ; WIDGET_ID, and checks for for a user cancel ; command. ; CANCEL - Set on return if there is a problem. ; ; PROCEDURES CALLED: ; Requires the Astronomy User's Library ; mkmask_xs ; poly_fit1d ; ; PROCEDURE: ; At every column within an order, mkmask_ps is called to ; create a mask of aperture regions, and background regions. ; The background is subtracted if BGORDER is given and then the ; flux and variance is summed within defined aperture regions. ; Set plot1 to see extraction in progress. ; ; REVISION HISTORY: ; 2000-08-24 - written by M. Cushing, Institute for Astronomy, UH ; 2000-11-13 - Modified to accept multiple background regions. ; 2001-10-04 - Added xranges input ; function extractspec_xs,image,var,edgecoeffs,tracecoeffs,norders,naps,start,$ stop,xranges,slith_arc,apradii,BGR=bgr,$ BGORDER=bgorder,UPDATE=update,WIDGET_ID=widget_id,$ CANCEL=cancel cancel = 0 ; Check parameters if n_params() lt 11 then begin print, 'Syntax - result = extractspec_xs(image,var,edgecoeffs,$' print, ' tracecoeffs,norders,naps,start,$' print, ' stop,xranges,slith_arc,apradii,$' print, ' BGR=bgr,BGORDER=bgorder,$' print, ' UPDATE=update,$' print, ' WIDGET_ID=widget_id,CANCEL=cancel' cancel = 1 return, -1 endif zparcheck, 'extractspec_xs', image, 1, [2,3,4,5], 2, '2D image' zparcheck, 'extractspec_xs', var, 2, [2,3,4,5], 2, 'Variance image' zparcheck, 'extractspec_xs', edgecoeffs, 3, [2,3,4,5], [2,3], 'Edgecoeffs' zparcheck, 'extractspec_xs', tracecoeffs, 4, [2,3,4,5], [1,2], 'Tracecoeffs' zparcheck, 'extractspec_xs', norders, 5, [2,3,4,5], 0, 'Norders' zparcheck, 'extractspec_xs', naps, 6, [2,3,4,5], 0, 'Naps' zparcheck, 'extractspec_xs', start, 7, [2,3,4,5], 0, 'Start Column' zparcheck, 'extractspec_xs', stop, 8, [2,3,4,5], 0, 'Stop Column' zparcheck, 'extractspec_xs', xranges, 9, [2,3,4,5], [1,2], 'Xranges' zparcheck, 'extractspec_xs', slith_arc, 10, [2,3,4,5], 0, 'Slit Height' zparcheck, 'extractspec_xs', apradii, 11, [2,3,4,5], 1, 'Aperture Radius' s = size(image) ncols = s[1] nrows = s[2] spectra = replicate(!values.f_nan,stop-start+1,2,naps*norders) x = findgen(stop-start+1)+start y = findgen(nrows) ; Set up the Fanning showprogress object if requested. if keyword_set(UPDATE) then begin cancelbutton = (n_elements(WIDGET_ID) ne 0) ? 1:0 progressbar = obj_new('SHOWPROGRESS',widget_id,color=2,$ CANCELBUTTON=cancelbutton,$ MESSAGE='Extracting Spectra...') progressbar -> start endif for i = 0, norders-1 do begin trace_pix = fltarr(stop-start+1,naps) pixtoarc = fltarr(stop-start+1,2) bot = poly(x,edgecoeffs[*,0,i]) top = poly(x,edgecoeffs[*,1,i]) for j = 0, naps-1 do begin l = i*naps+j trace_pix[*,j] = poly(x,tracecoeffs[*,l]) endfor pixtoarc[*,1] = float(slith_arc) / (top-bot) pixtoarc[*,0] = -1.* (pixtoarc[*,1] * bot) for j = 0,stop-start do begin if x[j] lt xranges[0,i] or x[j] gt xranges[1,i] then goto, cont2 low = 0 > bot[j] high = nrows-1 < top[j] slity_pix = y[low:high] slity_arc = poly(slity_pix,pixtoarc[j,*]) slitz = image[x[j],low:high] vslitz = var[x[j],low:high] trace_arc = poly(trace_pix[j,*],pixtoarc[j,*]) mask = mkmask_xs(slity_arc,reform(trace_arc),apradii,BG=bgr,$ CANCEL=cancel) if cancel then return, -1 if n_elements(BGORDER) ne 0 then begin z = where(mask eq -1) coeff = poly_fit1d(slity_arc[z],slitz[z],bgorder,YERR=vslitz,$ /SILENT,VAR=cvar) slitz = temporary(slitz)-poly1d(slity_arc,coeff,cvar,YVAR=yvar) vslitz = temporary(vslitz)+yvar endif for k = 0, naps-1 do begin l = i*naps+k z = where(mask gt float(k) and mask le float(k+1)) spectra[j,0,l] = total( slitz[z]*(mask[z]-float(k)) ) spectra[j,1,l] = total( vslitz[z]*(mask[z]-float(k))^2) endfor cont2: endfor if keyword_set(UPDATE) then begin if cancelbutton then begin cancel = progressBar->CheckCancel() if cancel then begin progressBar->Destroy obj_destroy, progressbar cancel = 1 return, -1 endif endif percent = (i+1)*(100./float(norders)) progressbar->update, percent endif endfor if keyword_set(UPDATE) then begin progressbar-> destroy obj_destroy, progressbar endif return, spectra end