function means,imgs,help=help, skymode = skymode, masks = masks ;+ ; NAME: means ; PURPOSE: ; return the means for a stack of images ; ; NOTES: ; [See also: meds.pro] ; ; function means,imgs,help=help, skymode = skymode, masks = masks ; ; INPUTS: ; imgs a stack of images ; KEYWORDS: ; masks Bad pixel mask. 0=bad, 1=good ; skymode uses skymode.pro to find medians; disabled, not sure why ; RETURNS: ; an array containing the median for each image in the stack. ; That is, it computes the median for each image individually and ; returns all of those, rather than medianning across images. ; ; HISTORY: ; 2005-05-03 mperrin: started, based on meds.pro ; 2005-11-14 mperrin: calls mean with /NAN ;- if n_params() lt 1 or keyword_set(help) then begin message,'function means(imgs,/help,/skymode,[masks=])' endif sz = size(imgs) if sz[0] lt 3 then $ message,"First arguement to means must be a 3D array." mm = fltarr(sz(3)) if keyword_set(masks) then begin szm = size(masks) if total(sz(0:3)-szm(0:3)) ne 0 then begin message, 'images & masks do not match!', /info help, imgs, masks stop endif endif for i=0,sz(3)-1 do begin if keyword_set(masks) then begin wg = where(masks[*, *, i] eq 1, ng) if (ng gt 0) then mm[i] = mean( (imgs[*, *, i])[wg],/NAN) $ else message, 'no good pixels for image '+strc(i), /info endif else $ mm(i) = mean(imgs[*,*,i],/NAN) endfor return,mm end