pro even_light_pedestal, adu_in_fov, back_pix_raw, sloped=sloped, $ gain, P1pP2, P1, P2, P1pP2sigma, P1sigma, P2sigma, valid_img=valid_img ;+ ; NAME: ; even_light_pedestal ; PURPOSE: ; ; CATEGORY: ; camera/idl/cert ; CALLING SEQUENCE: ; INPUTS: ; OPTIONAL INPUT PARAMETERS: ; OUTPUTS: ; OPTIONAL OUTPUT PARAMETERS: ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, gridgen, LocalExtrema ; PROCEDURE: ; MODIFICATION HISTORY: ; ???-200?, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, sloped, /key nimg = n_elements(adu_in_fov) nvalid = n_elements(valid_img) if nvalid eq 0 then valid_img = indgen(nimg) ; Calculate gain by making mean intensity in fov the same for all images gain = adu_in_fov/mean(adu_in_fov[valid_img]) dgain = gain[valid_img]-1 dback = back_pix_raw[valid_img] ; Calculate P1+P2 and P2 by linear fit between gain-1 and background jj = linfit(dgain, dback, sigma=sigma) P1pP2 = jj[0] P2 = jj[1] ;================ if sloped then begin zmin = min(dback-(P1pP2+dgain*P2), max=zmax) nslope = 100 slope = 5*(zmax-zmin)/(nimg-1)*gridgen(nslope,range=[-1,1]) chisq = fltarr(nslope) for i=0,nslope-1 do begin jj = linfit(dgain, dback-slope[i]*valid_img, chisq=zval) chisq[i] = zval endfor slope = interpolate(slope, LocalExtrema(chisq, /minima, /float)) endif else $ slope = 0. ;======================== if slope ne 0 then begin jj = linfit(dgain, dback-slope*valid_img, sigma=sigma) P1pP2 = jj[0] P2 = jj[1] endif P1pP2 = P1pP2 + slope*findgen(nimg) P2 = P2 + fltarr(nimg) P1pP2sigma = sigma[0] + fltarr(nimg) P2sigma = sigma[1] + fltarr(nimg) P1 = P1pP2-P2 P1sigma = sqrt( P1pP2sigma*P1pP2sigma+P2sigma*P2sigma ) return & end