; docformat='rst'
;+
; This procedure creates a 2-D RON map by subtracting from a dark current ramp the linear fit, and estimating the residuals stdev for each pixel
;-
;+
; Creates a RON map subtracting from a dark current ramp the linear fit and estimating the residuals stdev for each pixel
;
; :categories:
; JWST Data Processing - NIRCam Cryo tests
; :examples:
; IDL> RAMP_GETRON,data0,fit_params,RON
; :Params:
; data0: in, required, type="fltarr(2048,2048,Ngroup)"
; ramp datacube to be analyzed
; fit_params: in, required, type="fltarr(2048,2048,2)"
; Two arrays with the intercept and slope derived from the linear fit
; RON : out, required, type="fltarr(2048,2048)"
; 2-D array with thre RON map
; :File Comments:
; Given a ramp, this procedure removes, for each pixel, the intercept/slope value from the linear fit.
; This makes the ramp, for each pixel, a zero average stack. In other words, one subtracts
; bias and dark current from the signal. Then take the stdev of the zero average ramp to get the RON
; :Author:
; M. Robberto, created 25 Apr. 201
;-
PRO RAMP_GETRON,data0,fit_params,RON
st=systime(1)
print,'begin optimal filtering: ',systime(1)-st,' sec ',memory(/high)/1e9,' GB'
;
s = size(data0)
nn = lindgen(s[3]) ;an array of 108 intgers, 0 to 107
;
m=fit_params[*,*,0]
b=fit_params[*,*,1]
data1 = reform(data0,s[1]*s[2],s[3])
m = reform(m,s[1]*s[2],/over)
b = reform(b,s[1]*s[2],/over)
for i=0,s[3]-1 do data1[*,i] -= nn[i]*b + m ;
;
; We can now calculate the standard deviation for each pixel: sig_data, is a 4M array, the sum of the squared discrepancies divided by 88-1 frames.
;get the size
first=(nn*0+1)##data1[0:1999,*]^2 & print,'first done'
second = (nn*0+1)##data1[2000:*,*]^2 & print,'second done'
sig_data = sqrt([first,second]/(s[3]-1)) ; mean = 0 after ramp subtraction
;
sig_data = reform(sig_data,s[1],s[2],/over)
;
RON=reform(sig_data,s[1],s[2],/over)
;
;time marker at the end of each main step to monitor the evolution of the calculation:
print,' end readoutnoise creation: ',systime(1)-st,' sec ',memory(/high)/1e9,' GB'
;
END