FUNCTION DIcal_realToInt, in, fitsHdr ;;----------------------------------------------------------------------------- ;; PURPOSE: ;; Used in the DI Calibration Pipeline. ;; Scales the image from real values to integer values by multiplying the ;; the image by 10^n. N is recorded in fitsHdr. Saturated pixels receive ;; the value 2^16-1 since we cannot represent Infinity in integers ;; ;; CALLING SEQUENCE: ;; out = DIcal_realToInt(in, fitsHdr) ;; ;; REQUIRED INPUTS: ;; in - The image to which this pipeline element is going to be applied ;; fitsHdr - The FITS header for the image ;; ;; OUTPUTS: ;; RETURN - the image after going through this calibration step ;; fitsHdr - the new FITS header with the muliplication power recorded ;; ;; OPTIONAL INPUT KEYWORDS: ;; ;; EXAMPLE: ;; IDL> imgOut = DIcal_realToInt(imgIn, fitsHdr) ;; ;; PROCEDURES USED (i.e. called directly!): ;; ;; ;; MODIFICATION HISTORY: ;; 2004-05-24 M. Desnoyer Created ;; ;;----------------------------------------------------------------------------- ;; Do error handling ;CATCH, error error=0 IF error NE 0 THEN BEGIN CATCH, /CANCEL message, 'Scale to Halfword - ' + !ERROR_STATE.MSG, /NONAME ENDIF ;; Find all the saturated pixels sat = where(finite(in,/INFINITY) EQ 1) ;; Find all the bad pixels bad = where(finite(in,/NAN) EQ 1) ;; Find all the good pixels good = where(finite(in) NE 0) ;; Determine the scaling factor (ie the highest value of N such that ;; max*10^2<=2^16) N = UINT(alog10((double(2)^16)/max(in[good]))) ;; Record the scaling factor in the fits file TODO ;; Scale the image, making sure that all values are non-negative dims = size(in,/dimensions) out = uintarr(dims[0],dims[1],/nozero) out[sat] = 2^16-1 out[bad] = 0 out[good] = (in[good] > 1)*10^N RETURN, out END