;+ ; NAME: setsky ; PURPOSE: ; Add offsets to images to make the background sky level equal ; to the background of the first image. ; ; INPUTS: ; KEYWORDS: ; /mean subtract mean from each slice (old default) ; new default is to subtract the output of 'sky' for each. ; smooth= smooth this many pixels before computing sky values. ; OUTPUTS: ; ; HISTORY: ; Began 2005-11-14 15:36:18 by Marshall Perrin ;- PRO setsky,imgs,center=center,boxsize=boxsize,alsofix=alsofix,dsky=dsky, $ mean=use_mean,all=all,smooth=smooth if ~(keyword_set(boxsize)) then boxsize=100 if ~(keyword_set(center)) then begin findmaxstar,imgs[*,*,0],mx,my endif else begin mx=center[0] my=center[1] endelse if keyword_set(all) then imgs2=imgs else $ imgs2 = imgs[mx-boxsize:mx+boxsize-1,my-boxsize:my+boxsize-1,*] if keyword_set(smooth) then imgs2 = smooth(imgs2,[smooth,smooth,1],/nan) if keyword_set(use_mean) then dsky = means(imgs2) else dsky = skys(imgs2) dsky -= mean(dsky) ; keep average sky level the same message,/info,"Found sky offsets:" print,dsky if total(finite(dsky)) ne n_elements(dsky) then message,"That box contains NaNs!" sz = size(imgs) for i=0L,sz[3]-1 do begin imgs[*,*,i] -= dsky[i] endfor if arg_present(alsofix) then begin for i=1L,sz[3]-1 do begin alsofix[*,*,i] -= dsky[i] endfor endif end