; NAME: ; ADDERRORS ; ; PURPOSE: ; Add to a frame cosmic rays, bad pixel values, noise, gain, ; flatten, add bias, and add 'FAKE' in lower left ; ; CALLING SEQUENCE: ; Result = ADDERRORS(inframe, header, raymask, badmask, badframe, ; flatframe, biasframe) ; ; INPUTS: ; Inframe = The frame to be modified ; Header = The header file ; Raymask = The cosmic ray mask ; Badmask = The bad pixel value mask ; Badframe = A frame with 0 at good pixels, and values at ; badpixels ; Flatframe = The flat field frame for the array ; Biasframe = The frame with bias values for the array ; Fakeval = The level of 'FAKE' ; ; KEYWORDS: ; Nonoise = Set to not add noise ; ; OUTPUT: ; A modified frame with array and sky errors ; ; PROCEDURE: ; Extract necessary variables out of the header, and initialize ; the variables. Then add to inframe the cosmic rays, bad ; pixels, signal noise, and readnoise. Then divide by gain, ; multiply by flatframe, and add biasframe. Finally add the word ; 'FAKE' in the lower left. ; ; FUNCTIONS CALLED: ; sxpar, cosrays, sxaddpar ; ; MODIFICATION HISTORY: ; created Augest 1 2003 by John Dermody function ADDERRORS, inframe, header, raymask, badmask, badframe, $ flatframe, biasframe, nonoise=nonoise, fakeval=fakeval nx = (size(inframe))[1] ny = (size(inframe))[2] maxrayvalp = sxpar(header, 'MXRAYVAL') rdnoise = sxpar(header, 'RDNOISE') epadu = sxpar(header, 'EPADU') nbad = n_elements(where(raymask eq 0)) nrays = n_elements(where(badmask eq 0)) fakeval = max(inframe) wordframe = ([ $ [fltarr(nx, 2)], $ [0., 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, intarr(nx - 17)], $ [0., 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, intarr(nx - 17)], $ [0., 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, intarr(nx - 17)], $ [0., 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, intarr(nx - 17)], $ [0., 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, intarr(nx - 17)], $ [intarr(nx, ny - 7)] ]) * fakeval outframe = inframe + cosrays (raymask, maxrayvalp) outframe = outframe * badmask + badframe sxaddpar, header, 'NUMRAYS', nrays, 'in pixels' sxaddpar, header, 'NUMBAD', nbad if (not keyword_set(nonoise)) then begin outframe = outframe + randomn(seed, nx, ny)*sqrt(outframe) outframe = outframe + randomn(seed, nx, ny)*rdnoise sxaddhist, 'Added noise to frame', header endif outframe = outframe / epadu outframe = outframe * flatframe outframe = outframe + biasframe outframe = outframe + wordframe ; make 'FAKE' in lower right raymask = (raymask - (wordframe < 1)) > 0 return, outframe end