; NAME: ; SYNTHSPEC ; ; PURPOSE: ; This function creates a synthetic spectrum frame and ; corresponding sky frame with headers. ; ; CALLING SEQUENCE: ; SpecFrame = SYNTHSPEC(SkyFrame, SpecHeader=specheader, ; Skyheader=skyheader, Nx=nx, Ny=ny, bklevel=bklevel, gain=gain, ; Readnoise=readnoise, skylines=skylines, speclines=speclines, ; speclevel=speclevel, objpos=objpos, vari=vari, numbad=numbad, ; numrays=numrays, numdouble=numdouble, numtriple=numtriple, ; maxbadvalue=maxbadvalue, spectrum=spectrum, traceout=traceout); ; ; OPTIONAL KEYWORDS, INPUT: ; NX = Size in spacial direction (512) ; NY = Size in spectral direction (NX) ; BKLEVEL = Background level (200 ADUs) ; EPADU = Gain of ccd array (10 electrons / ADU) ; RDNOISE = Read noise of array (10 electrons) ; NUMEMIL = Number of emission lines in object spectrum (10) ; NUMABSL = Number of absorbtion lines in spect (NUMEMIL * 2/3) ; SPECLEVEL = Level of spectrum (10000 ADUs) ; OBJPOS = Position of object on array (NX / 2) ; SEEING = Amount of seeing in sky (10) ; SPECRES = Spectral resolution of array (2) ; NUMBAD = Number of bad pixels (100) ; NUMRAYS = Number of cosmic rays (NUMBAD) ; MAXBADVAL = Maximum bad pixel value (15000 ADU) ; MAXRAYVAL = Maximum ray pixel value (MAXBADVAL * 1/2) ; SKYLLVL = Maximum sky line level (BKLEVEL * 4) ; EMILLVL = Maximum emission line level (SPECLEVEL * 6) ; TEMP = Temperature of object (5000 K) ; SWAVEL = Start wavelength of array (1.5e-6 m) ; EWAVEL = End wavelength of array (SWAVEL + 0.1e-6) ; TILTANGLE = The tilt angle of all spectrum lines (1 Degree) ; TRACEOSC = Number of full oscillations in spectral curve (0.5) ; TRACEAMP = Amplitude of spectral curve (6 pixels) ; SMILE = Amplitude of smile in sky lines (7 pixels) ; INOBJSPEC = Object spectrum (1D array, len NY, overrides above) ; INSKYSPEC = Sky spectrum (1D array, len NY, overrides above) ; BIASFRAME = Bias frame (2D array, NX x NY, default 0) ; FLATFRAME = Flat field frame (2D array, NX x NY, default 1) ; OHLOC = The location of the oh line database (Searches for it) ; ; OPTIONAL KEYWORDS, SET: ; NONOISE = Set to not add noise ; NOBAD = Set to not add bad pixels ; NORAYS = Set to not add cosmic rays ; NOBBCURVE = Set to not add a black body curve to the spectrum ; NOSKYL = Set to not add sky lines ; NOSPECL = Set to not add lines to object spectrum ; RANDSKYL = Set to add random skylines ; NOTILT = Set to not rotate frame ; NOTRACE = Set to not curve the trace ; NOSMILE = Set to not curve lines of constant wavelength ; (i.e., no "smile") ; ; OPTIONAL KEYWORDS, OUTPUT: ; OBJHEADER = The header for the spec frame ; SKYHEADER = The header for the sky frame ; OBJCRMASK = The bad pixel mask used for the object frame ; SKYCRMASK = The bad pixel mask used for the sky frame ; PROFRAME = Profile image ; BGFRAME = Background image ; SPECFRAME = Object spectrum frame without noise, sky, or bad pixels ; SPECTRUM = Spectrum used to generate specframe ; TRACEOUT = 1D array of the pixel location for the profile center ; ; OUTPUT: ; An array of size nx*ny with a fake spectrum created using the ; values above, or defaults if not defined, and skyframe ; containing the coresponding fake sky array of size nx*ny ; ; PROCEDURE: ; First set the defaults for all possible keyword inputs. Then, ; Convert certain variables to units of photons. To make sure ; that the bad pixel locations are the same ; in both frames, initialize a bad pixel frame with the chip ; values. Then set up a parent frame for both frames, and a ; corresponding header that the functions can use to grab ; variables. Next fill the parent frame with the sky lines. ; Copy the parent frame into the sky frame, and add observational ; errors. Then, copy the parent frame into the object frame, and ; add the objects spectrum. Finally, add distortions and noise ; into the object frame. ; ; FUNCTIONS CALLED: ; initheader, badpixloc, badpixval, speclines, adderrors, ; distort, sxaddpar ; ; MODIFICATION HISTORY: ; created Jun 14 2003 by John Dermody ; Jun 18 2003: Made many more modules, and added lines to ; the spectrum for the sky and the object function SYNTHSPEC, skyframe, objheader=objheader, skyheader=skyheader, $ spectrum=spectrum, Nx=nx, Ny=ny, bklevel=bklevel, $ epadu=epadu, rdnoise=rdnoise, nmskyl=numskyl, $ numemil=numemil, numabsl=numabsl, $ speclevel=speclevel, objpos=objpos, seeing=seeing, $ specres=specres, numbad=numbad, numrays=numrays, $ maxbadval=maxbadval, maxrayval=maxrayval, $ skyllvl=skyllvl, emillvl=emillvl, temp=temp, $ swavel=swavel, ewavel=ewavel, tiltangle=tiltangle, $ traceosc=traceosc, traceamp=traceamp, smile=smile, $ nonoise=nonoise, nobad=nobad, norays=norays, $ doskyosc=doskyosc, noskyl=noskyl, nobbcurve=nobbcurve, $ randskyl=randskyl, notilt=notilt, nosmile=nosmile, $ notrace=notrace, nospecl=nospecl, inobjspec=inobjspec, $ inskyspec=inskyspec, flatframe=flatframe, $ biasframe=biasframe, objcrmask=objcrmask, $ skycrmask=skycrmask, proframe=proframe, $ bgframe=bgframe, specframe=specframe, ohloc=ohloc, $ traceout=traceout, tracein=tracein ; Defaults ; For every value that is not been defined, set it to a default. if not keyword_defined(nx ) then nx = 512 if not keyword_defined(ny ) then ny = nx if not keyword_defined(bklevel ) then bklevel = 200. if not keyword_defined(epadu ) then epadu = 10. if not keyword_defined(rdnoise ) then rdnoise = 10. if not keyword_defined(numskyl ) then numskyl = 8 if not keyword_defined(numemil ) then numemil = 10 if not keyword_defined(numabsl ) then numabsl = numemil * 2 / 3 if not keyword_defined(speclevel) then speclevel = 10000. if not keyword_defined(seeing ) then seeing = 10. if not keyword_defined(specres ) then specres = 2. if not keyword_defined(numbad ) then numbad = 100 if not keyword_defined(numrays ) then numrays = numbad if not keyword_defined(maxbadval) then maxbadval = 15000. if not keyword_defined(maxrayval) then maxrayval = maxbadval * 1 / 2 if not keyword_defined(emillvl ) then emillvl = speclevel * 6 if not keyword_defined(skyllvl ) then skyllvl = bklevel * 4 if not keyword_defined(temp ) then temp = 5000. ; (K) if not keyword_defined(swavel ) then swavel = 1.5e-6 ; (m) if not keyword_defined(ewavel ) then ewavel = swavel + 0.1e-6 if not keyword_defined(tiltangle) then tiltangle = 1. ; (degrees) if not keyword_defined(traceosc ) then traceosc = 0.5 if not keyword_defined(traceamp ) then traceamp = 6. if not keyword_defined(smile ) then smile = 7. if not keyword_defined(flatframe) then flatframe = 1. if not keyword_defined(biasframe) then biasframe = 0. ; Remake Variables ; Some variables need to be changed from ADUs to photons, so make new ; variables with a "p" at the ends of their names. If a 'no' keyword is ; set the corresponding varable needs to be made 0 so that the header ; reads correctly. Tx and Ty are created so that the inital array ; calculated will be large enough that the rotation and curves do not ; introduce new data. bklevelp = epadu * bklevel ; = Background level in photons speclevelp = epadu * speclevel ; = Obj Spectrum level in photons maxbadvalp = epadu * maxbadval ; = Max bad pixel level " " maxrayvalp = epadu * maxrayval ; = Max cosmic ray level " " maxskyvalp = (skyllvl - bklevel) * epadu ; = Max sky line level " " maxobjvalp = (emillvl - speclevel) * epadu ; = Max obj emission line level "" if keyword_set(nobad ) then numbad = 0 if keyword_set(norays ) then numrays = 0 if keyword_set(notilt ) then tiltangle = 0 ; So there is no tilt if keyword_set(nonoise) then rdnoise = 0. ; So there is no read noise if keyword_set(nosmile) then smile = 0. ; So no smile if keyword_set(notrace) then traceamp = 0. ; So no trace while (tiltangle lt 0) do tiltangle = 360 + tiltangle tilta = tiltangle * !pi / 180. ; Tilt angle in radians tx = ceil(abs(nx * cos(tilta)) + abs(ny * sin(tilta)) > nx + 2 * abs(traceamp)) ty = ceil(abs(ny * cos(tilta)) + abs(nx * sin(tilta)) > ny + 2 * abs(smile)) bx = float(tx-nx) / 2 ; = Where the real array begans by = float(ty-ny) / 2 ta = tiltangle if not keyword_defined(objpos) then begin objposb = (tx / 2) endif else begin objposb = objpos + abs(traceamp) endelse nh = 30 ; Initialize ; Simpleheader is the parent of both objheader and skyheader. It is ; filled with variables needed for both the sky frame and the object ; frame. Badmask is the mask used for the bad pixels in both frames. ; Badframe is a 2D array of size (nx,ny) that conains 0 for a good ; value, and the bad pixel's level for bad pixels. Skymask and ; objmask are created using badpixloc. Finally skycrmask and ; objcrmask are prepared for output. simpleheader = initheader(nh, nx, ny, 'Fake Spec') sxaddpar, simpleheader, 'SWAVEL ', swavel, 'start wavelength(m)' sxaddpar, simpleheader, 'EWAVEL ' , ewavel, 'end wavelength(m)' sxaddpar, simpleheader, 'SPECRES ', specres, 'spectral resolution' sxaddpar, simpleheader, 'SMILE ', smile, 'Maximum shift in sky lines' sxaddpar, simpleheader, 'TILT ', tiltangle, 'deg' sxaddpar, simpleheader, 'SEEING ', seeing, 'full-width at half-max' sxaddpar, simpleheader, 'TRACEAMP', traceamp, 'Max bend amount in object trace' sxaddpar, simpleheader, 'TRACEOSC', traceosc, 'Number of sine oscil. in trace' sxaddpar, simpleheader, 'MXRAYVAL', maxrayvalp, 'in photons' sxaddpar, simpleheader, 'MXBADVAL', maxbadval, 'in ADUs' sxaddpar, simpleheader, 'MXSKYVAL', maxskyvalp, 'in photons' sxaddpar, simpleheader, 'RDNOISE ', rdnoise, 'RMS readout noise (e-)' sxaddpar, simpleheader, 'EPADU ', epadu, 'Electrons per ADU' sxaddpar, simpleheader, 'BKLEVEL ', bklevelp, 'e-' badmask = badpixloc(nx, ny, numbad) ; mask contains a 0 for bad badframe = badpixval(badmask, maxbadvalp) ; = bad pixel values skyrays = badpixloc(nx, ny, numrays) ; mask for sky cos rays objrays = badpixloc(nx, ny, numrays) ; mask for obj cos rays ; Create Sky Frame ; Simpleframe is the parent frame of both objframe and skyframe. It ; is initially filled with the sky spectrum using speclines. The 1D ; array skyspec is matrix multiplied to create simpleframe. Skyframe ; becomes simpleframe with geometric distrotions, and observational ; errors (bad pixels, cosmic rays, readnoise, signal noise, gain) from ; function adderrors. Bgframe is also prepeared for output. if (not keyword_set(randskyl)) then fromoh = 1 else fromoh = 0 skyspec = speclines(simpleheader, bklevelp, maxskyvalp, numskyl, ty, $ inspec=inskyspec, fromoh=fromoh, nolines=noskyl, $ ohloc=ohloc) skysimple = skyspec ## (1 + fltarr(tx)) ; = sky frame without noise or bad skysimple = distort(skysimple, simpleheader, bx, by) skyheader = simpleheader skyframe = skysimple bgframe = skyframe / epadu skyframe = adderrors(skyframe, skyheader, skyrays, badmask, badframe, $ flatframe, biasframe, nonoise=nonoise) skycrmask = badmask * skyrays ; = all bad locations for skyframe ; Create Object Frame ; Object header is prepared by adding objframe only variables to ; simpleheader. A 1D array ob the object's spectrum is created using ; speclines. That spectrum is added into the simpleframe at objposb, ; with the resulting frame called objframe. Objframe is distorted, ; and proframe is prepared for output by distorting a frame with 0 ; background and a flat spectrum. Finally observational errors are ; added to objframe. objheader = simpleheader sxaddpar, objheader, 'OBJPOS ', objposb, 'starting object position' sxaddpar, objheader, 'SPECLVL ', speclevelp, 'speclevel(e-)' sxaddpar, objheader, 'NUMEMIL ', numemil, 'number of emission lines' sxaddpar, objheader, 'MXEMILVL', maxobjvalp, 'max obj emission lvl (e-)' sxaddpar, objheader, 'NUMABSL ', numabsl, 'number of absorbsion lines' sxaddpar, objheader, 'TEMP ', temp, 'Temperature of object (K)' if (not keyword_set(nobbcurve)) then bbcurve = 1 else bbcurve = 0 spectrum = speclines(objheader, speclevelp, maxobjvalp, numemil, ty, $ inspec=inobjspec, bbcurve=bbcurve, numabsl=numabsl, $ specoff=specoff, nolines=nospecl) objframe = fltarr(tx, ty) proframe = fltarr(tx, ty) objframe[objposb, *] = spectrum proframe[objposb, *] = 1. spectrum = spectrum / epadu objframe = distort(objframe, objheader, bx, by, xin=tracein) proframe = distort(proframe, simpleheader, bx, by, xpos=traceout, xin=tracein) specframe = objframe / epadu objframe = objframe + skysimple fakeval = max(specframe) objframe = adderrors (objframe, objheader, objrays, badmask, badframe, $ flatframe, biasframe, nonoise=nonoise, fakeval=fakeval) objcrmask = badmask * objrays ; = all bad locations for objframe traceout = traceout + nx / 2 return, objframe end