; automaked sky flat generator : 10/1/2008 dir= '/home/kitt_peak/slotis_081007/' ; choose the data directory ; first pick your Filter by uncommenting the keyword that identifies the ; frame as a V-, R-, or I-band flat search_str = 'Flat_R ' ;search_str = 'Flat_V ' ;search_str = 'Flat_I ' nx = 2200 ny = 2200 skythres = 3000.0 ; sky signal must be above this level to be ; included ; Range of filenames to search n0 = 1 n1 = 120 iflat = 0 ; Loop over flat data and look for appropriate ; flats for i = n0, n1 do begin fn = dir+'flat'+string(i,form='(i03)')+'.fits' print,'File ',fn x = readfits(fn,hdr,/silent) if n_elements(x) gt 1 then begin obj = sxpar(hdr,'OBJECT') if obj eq search_str and median(x) gt skythres then begin if iflat eq 0 then begin fns = fn endif else begin fns=[fns,fn] endelse iflat++ endif endif endfor nf = n_elements(fns) print,'There are ',nf,' flats brighter than ', skythres flats = fltarr(nx,ny,nf) for i=0,nf-1 do begin x = readfits(fns[i],hdr,/silent) ; bias subtract biasval = median(x[2104:2194,4:2194]) x -= biasval ; scale to the median value medval = median(x[50:2097,0:2047]) x /= medval ; stuff the frame into a 3-d array flats[*,*,i] = x endfor ; combine the median image skyflat = median(flats,dim=3) writefits, dir+strcompress(search_str,/rem)+'-med-sky-flat.fits',skyflat,header end