function adapt_smooth,im,snr,rmax,snrim=snrim, expmap=expmap, thresh=thresh if n_params(0) eq 0 then begin print,'smim = adapt_smooth(im,snr,rmax,snrm=snrim, expmap=expmap, thresh=thresh)' print,'Adaptively smooth im until each pixel contains a minimum of print,'snr^2 counts (resultant pixel will contain snr^2/n, n = no. of print,'total pixels required in sum for pixel to have n counts' print,'rmax = max distance to continue summing pixels' print,'These parameters are analogous to the parameters for setplot rebin in XSPEC' print,'snrim contains raw number of counts summed into each pixel (i.e., snr^2' print,'expmap contains optional exposure map to simultaneously smooth and divide' print,' i.e., if units are secs, the output would be in cts/sec' print,' only consider pixels where expmap > thresh (def. thresh=0) retall endif sz = size(im) sm = fltarr(sz(1),sz(2)) sn = snr^2 snrim = im ; emap = n_elements(expmap) gt 0 if n_elements(expmap) eq 0 then expmap = replicate(1l, sz(1), sz(2)) $ else print,'Output will be divided by expmap' if n_elements(thresh) eq 0 then thresh = 0 for j=0,sz(2)-1 do begin w = where(expmap(*,j) gt thresh, n) if n gt 0 then for i=min(w), max(w) do begin ; for i=0,sz(1)-1 do begin c = long(im(i,j)) ; n = 1.0 r = 1 t = expmap(i,j) en = 0 while r lt rmax and c lt sn do begin i1 = (i-r)>0 i2 = (i+r)0 j2 = (j+r)