; script for registration and mosaicking of images ; (i.e. already bias-sub'ed, flat-fielded, 1st pass sky-sub'ed) ; ; generated from a hack of PTSOURCE.IDL, May 2001 version. ; to be used with BIASFLATSUB0.IDL ; ; used for MMT/PISCES reduction (had to use IRAF to geometrically ; transform the data after bias-sub/flatfielding/1st skysub, ; hence this separate IDL script) ; ; 05/12/01 ;goto, G_IREG ;-------------------------------------------------- ; please set these to the appropriate values: ; ; ** INPUT FILES ** objn = 'lbds091ks' ; object name string setn = '_n1.5' ; set name string (user must enter "_" if desired) infile = 'lbds091ks_n1-5-out.bfs0t.lst' ; if set, overrides ISTART FWHM = 6 ; estimated fwhm of images ; calibration frames badpixf = 'calib/badpix_PISCES.tran.ks.fits' ; telescope conventions (Keck is default) gemini = 0 ; if Gemini files lick = 0 ; if Lick files oldlick = 0 ; if old Lick/LIRC2 files, before coadding ctio = 0 ; if CTIO files ircal = 0 ; if IRCAL files ircs = 0 ; if Subaru/IRCS pisces = 1 ; if MMT/PISCES ; ** REDUCTION PARMS ** sflag = 0 ; 0=don't examine images, !0=examine images NSKY = 2 ; value for AUTOGAL sky subtraction NSKY0 = 2 ; value for 1st pass AUTOGAL sky subtraction CBOX = 2*FWHM ; box size for centroiding MASKRAD = 4*FWHM ; radius for masks (after auto-masking MASKSIG = 0.0 ; sigmascale for image masking ; parms for quick phot APRAD = 2.5*FWHM ; radius for phot INSKY = 4*FWHM ; inner sky radius OUTSKY = 6*FWHM ; outer sky radius ;-------------------------------------------------- ; script info for self-documenting SDIR = '/rice/mliu/idl/lib/reduct/scripts/' SNAME = 'regmos.idl' wclear loadct, 15 BADVAL = -1e6 dlim = 50 ; for sensible displaying NC = 1 ; step size for image numbers (only for old LIRC data) if (infile ne '') then ISTART = 0 if (ircs) or (pisces) then IMSIZE = 1024 $ else IMSIZE = 256 if (pisces) then ctio = 1 ; similar parms except for image size ;goto, G_IREG ;G_START: ; start history info hstr = strarr(6) spawn, 'date', date spawn, 'pwd', pwd id = userid() hstr(0) = '------------------------------------------------------------' hstr(1) = '<>' hstr(2) = ' starting directory = "'+pwd+'"' hstr(3) = ' starting directory = "'+pwd+'"' hstr(4) = ' LOADIMF: loaded images from "'+infile+'"' ; load bad pixel mask print, '=== loading bad pixel mask: "', badpixf, '" ===' badpix = readfits(badpixf, /silent) if (n_elements(badpix) eq 1) then $ message, '** bad pixel image does not exist !! **', /info $ else $ hstr(5) = ' loaded bad pixel mask = "'+badpixf+'"' SPT: ; number of images to process in each batch IMSET = 16 ; read list of images, determine how many sets of 8 readcol2, infile, form = 'A', imglist_tot ntot = n_elements(imglist_tot) nsets = ceil(ntot/IMSET) if (ntot mod IMSET) lt 6 and (ntot mod IMSET) gt 0 then $ message, 'we have a problem ...' for i = 1, nsets-1 do begin ;for i = 0, nsets-1 do begin loopname = '.loop'+strc(i+1) filen = objn+setn+loopname ; string for files names print & print print, '--------------------------------------------------' print, ' set = ', strc(i+1), ' out of ', strc(nsets) print, '--------------------------------------------------' print & print ; dump subset of image names to file i0 = i*IMSET i1 = ((i+1)*IMSET-1) < (ntot-1) loopfile = filen+'-in.lst' forprint, imglist_tot(i0:i1), textout = loopfile, /silent ;---------------------------------------------------------------------- ; LOAD (bias-sub'ed, flatfielded, 1st-pass skysub) IMAGES & INITIALIZE ;---------------------------------------------------------------------- loadimf, loopfile, obj_sub0, head0, imglist, /coadd sz = size(obj_sub0) NF = sz(3) G_IREG: ;---------------------------------------------------------------------- ; INITIAL REGISTRATION ;---------------------------------------------------------------------- ; cannot select frames to be discarded at this point ; or else will mess up sky subtraction w/masks!! print, '========================================' print, '=== interactively registering frames ===' print, '=== DO NOT exclude any frames !! ===' print, '========================================' ; examine 1st image to decide on centering object if getyn('use ATV to search for registration object?', 0) then begin atv, badpix*obj_sub0(*, *, 0), /block, /hist endif ireg, obj_sub0, obj_dx, obj_dy, $ badpix = badpix, cbox = CBOX, FWHm = FWHM, /setsky, $ log = filen+'_shifts.dat' sxaddhist, ' IREG: find offsets for 1st pass mosaic', head0 sxaddhist, ' cbox size = '+strc(CBOX), head0 G_MOS: ; make mosaic print, '======================' print, '=== making mosaic ===' print, '======================' wgood = where(obj_dx ne -999, ngood) nimgs = n_elements(obj_dx) print, '=== using '+strc(ngood)+' out of '+strc(nimgs)+' images ===' sxaddhist, ' using '+strc(ngood)+' out of '+strc(nimgs)+' images', head0 mosf, obj_sub0, obj_dx, obj_dy, $ obj_mos, obj_mosexp, obj_mossky, $ goodlist = (obj_dx ne -999), $ badpix = badpix, /setsky sxaddhist, ' MOSF: using /setsky', head0 ; show resulting mosaic win, 0, sz = 500 display2, obj_mos < dlim, tit = '1st pass mosaic' G_BPFILTER: ; run BPFILTER to make a mosaic mostly free of CRs print, '===============================' print, '=== making filtered mosaic ====' print, '===============================' bpfilter, temporary(obj_sub0), obj_dx, obj_dy, badpix, $ obj_fmos, obj_fmosexp, obj_fmasks, obj_fmaskmos, obj_fmossky, $ /nocheck win, 0, sz = 600 display2, obj_mos < dlim, tit = '2nd pass mosaic' win, 1, sz = 600 display2, obj_fmos < dlim, tit = 'final filtered mosaic' blink, [0, 1] sxaddhist, ' BPFILTER.PRO: '+date, head0 sxaddhist, ' filtered bad pixels and made new mosaic', head0 G_WRITE: ;-------------------------------------------------- ; SAVE THE REDUCTION PRODUCTS ;-------------------------------------------------- if not(getyn('do you want to save the files?')) then stop if getyn('obj="'+objn+'", set="'+setn+'": do you want to change ' + $ 'these?', 0) then begin read, 'enter object name: ', objn read, 'enter set name: ', setn filen = objn+setn+loopname endif ; write mosaic files print, '=== writing mosaic files for <', filen, '> ===' outfile = filen+'_mos.fits' if filecheck(outfile) then begin sxaddpar, head0, 'OBJECT', strupcase(filen+' mosaic ') writefits, outfile, obj_mos, head0 endif sxaddpar, head0, 'OBJECT', strupcase(filen+' mosaic exposure map') writefits, filen+'_mosexp.fits', obj_mosexp, head0 ; write BPFILTER output: mosaics and masks sxaddpar, head0, 'OBJECT', filen+' BPFILTER-ed mosaic ' outfile = filen+'_fmos.fits' if filecheck(outfile) then $ writefits, outfile, obj_fmos, head0 sxaddpar, head0, 'OBJECT', filen+' BPFILTER-ed mosaic exposure map' writefits, filen+'_fmosexp.fits', obj_fmosexp, head0 outfile = filen+'_fmasks.fits' if filecheck(outfile) then begin sxaddpar, head0, 'OBJECT', filen+' BPFILTER masks ' writefits, outfile, obj_fmasks, head0 endif sxaddpar, head0, 'OBJECT', filen+' BPFILTER mask - mosaic ' writefits, filen+'_fmaskmos.fits', obj_fmaskmos, head0 print if not(getyn('finished loop - continue?')) then stop ;obj_sub0 = 0 obj_fmasks = 0 obj_mos = 0 obj_mosexp = 0 obj_fmos = 0 obj_fmosexp = 0 endfor ; save copy of reduction script if getyn('save reduction script in current directory?') then begin outfile = SNAME+'.'+filen print, ' current script dir: "', SDIR, '"' print, ' current IDL script: "', SNAME, '"' print, ' output file name: "', outfile, '"' if not(getyn(' is this correct?')) then stop if filecheck(outfile) then $ spawn, 'cp '+SDIR+SNAME+' '+outfile print, 'wrote "', outfile, '" to current directory' endif print, '==============================' print, '=== REGMOS.IDL finished! ===' print, '==============================' print, '' end