function calibrate_amie, raw_label, raw_image, $ cfg_content = cfg_content, logname = logname, $ filter = filter, integer = integer, $ master_flat = master_flat, $ master_bias = master_bias, $ master_slope = master_slope ;+ ; NAME: ; amie_pipeline ; ; PURPOSE: ; Calibrates an AMIE raw image ; ; CATEGORY: ; AMIE Calibration - part of the project 'amie_pipeline' ; ; CALLING SEQUENCE: ; calibrated_image = calibrate_amie (raw_image, master_dark, master_flat, filter = filter) ; ; INPUTS: ; raw_image: array with AMIE raw image ; raw_label: string with label information ; filter: a part of the image can be selected for calibration according to the image ; below, with the names with quotes. Example: filter = 'FeH_X' ; The program will look in the header if this input is not present. ; ; _______________________ ; | | | ; | VIS_Y | | ; |___________| NONE | ; | | | ; | FeL_Y | | ; |___________|___________| ; | F | F | V | ; |FeH_Y e | e | I | ; |_____ H | L | S | ; | | | | | | | | ; |LASER| X | X | X | ; |_____|_____|_____|_____| ; ; ; OPTIONAL INPUT PARAMETERS: ; None. ; ; OUTPUTS: ; an image integer array containing the calibrated image ; cal_file_name: name of the new calibrated file ; master_flat_name: file name of the master flat used in the calibration to be inserted in the label ; master_dark_name: file name of the master dark used in the calibration to be inserted in the label ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; Hopefully none. ; ; RESTRICTIONS: ; No restrictions ; ; MODIFICATION HISTORY: ; 2002 Mar, ma: first try ; 2002 May, ma: version 2 with automatic selection of master ; darks and master flats from the information ; in the raw header ; 2003 Oct, ma: correction due to the change of image file names and image header. ; filtered parts of the image can be calibrated idipendently ; ; (c) 2004, Miguel Almeida, ESA/RSSD ;- create_log_entry, logname, 'entering calibrate_amie module' ;; 2008 Feb 13, BG: Check for keyword integer if keyword_set( integer ) then begin integer = integer endif else begin integer = 0 endelse ;------------------------------------------------------------------------------------------------------------------------- ; ;initialize calibrated label array ; ;------------------------------------------------------------------------------------------------------------------------- calibrated_label = strarr(256) ;------------------------------------------------------------------------------------------------------------------------- ; ;temperature, exposure time and filter name retrieval from the header ; ;------------------------------------------------------------------------------------------------------------------------- filter = strtrim(pdspar(raw_label, 'FILTER_NAME'),2) create_log_entry, logname, '[Calibration Module] Filter name('+filter+') retrieved from the header' ;window selection for flat field averaging and output dimension filterXY = amie_getfilter(raw_label) x1 = filterXY[0] x2 = filterXY[1] y1 = filterXY[2] y2 = filterXY[3] ;------------------------------------------------------------------------------------------------------------------------- ; ;array definition based on the filter information ; ;------------------------------------------------------------------------------------------------------------------------- dimx = x2 - x1 + 1 dimy = y2 - y1 + 1 calibrated_image_flt = fltarr(dimx,dimy) calibrated_image = intarr(dimx,dimy) avgflat = fltarr (dimx,dimy) exposure = fltarr (dimx,dimy) ;------------------------------------------------------------------------------------------------------------------------- ; ;load masters ; ;------------------------------------------------------------------------------------------------------------------------- ;; 2008 Jan 08, sm. dark_interpolation replaced by dark_frame. ;; 2008 Feb 04, bg. removed option /temperature master_dark = dark_frame(raw_label, cfg_content, logname, /polylin, /scale, $ master_bias = master_bias, $ master_slope = master_slope) create_log_entry, logname, '[Calibration Module] Loaded Master Dark frame' ;; 2008 Jan 28, BG: Added orientation = 'CCD_FRAME'. ;; 2008-03-27, BG: Moved to main program outside the loop ;master_flat = read_amie(cfg_content(5), flat_label, orientation = 'CCD_FRAME') ;create_log_entry, logname, '[Calibration Module] Loaded Master Flat Frame' ;------------------------------------------------------------------------------------------------------------------------- ; ;calibration calculations ; ;------------------------------------------------------------------------------------------------------------------------- flat = float (master_flat.image1) flat(0:494,0) = flat(0:494,1) flat(414,5) = median([flat(414,4), flat(414,5), flat(414,6), flat(415,4), flat(415,6), flat(416,4),flat(416,5), flat(416,6)]) ;; 2008 Feb 13, BG: Only equalize filters if NOT given option integer if integer eq 0 then begin ;; 2008 Feb 05, BG: Equalized filters. ;; Besides deviding by the flat field, the image is multiplied with ;; the average of the flat field. Previously, this average of the flat ;; field was computed on the filter area of the currently processed ;; image. In order to equalize the filters, one could either compute ;; the average on the complete flat field or just omit the division, ;; i.e. set the denominator to unity. ; npix = 0.0 ; Must be float zero to prevent making it short int (%$#&!!!). ; avgflatvalue = 0.0 ; for ix = 0, 1023 do begin ; for iy = 0, 1023 do begin ; npix = npix + 1 ; delta = flat(ix,iy) - avgflatvalue ; avgflatvalue = avgflatvalue + delta/npix ; endfor ; endfor ; avgflat(*,*) = avgflatvalue avgflat(*,*) = 1.0 endif flat = flat(x1:x2,y1:y2) ;; 2008 Feb 13, BG: If given option integer, compute average over ;; filter area if integer eq 1 then begin sumflat = total (flat) avgflatvalue = sumflat/((x2-x1+1)*(y2-y1+1)) avgflat(*,*) = avgflatvalue endif ;; 2008 Feb 14, BG: Moved this into the loop below to avoid division ;; by zero error. ; calibrated_image_flt = (avgflat/flat) * (raw_image.image1 - master_dark(x1:x2,y1:y2)>0) ;; 2008 Feb 14, BG: Set result to 0 if flat is lower than 0.1 or ;; result is lower than 0.0 ;; Just a comment by Stephane Erard: I think you're loosing time in ;; calibrate_amie, your modif from 18 / 02: ;; You don't have to use a loop just to set some values to 0. Using ;; indexes is much faster. for ix = 0, dimx-1 do begin for iy = 0, dimy-1 do begin if flat(ix,iy) lt 0.1 then begin calibrated_image_flt(ix,iy) = 0.0 endif else begin calibrated_image_flt(ix,iy) = (avgflat(ix,iy)/flat(ix,iy)) $ * (raw_image.image1(ix,iy) - master_dark(x1+ix,y1+iy)>0) endelse if calibrated_image_flt(ix,iy) lt 0.0 then $ calibrated_image_flt(ix,iy) = 0.0 endfor endfor ;; 2008 Feb 13, BG: Only if NOT given option integer, devide by ;; exposure time if integer eq 0 then begin exposure_time = pdspar(raw_label, 'EXPOSURE_DURATION') exposure(*,*) = exposure_time calibrated_image_flt = calibrated_image_flt / exposure endif calibrated_image = round (calibrated_image_flt) calibrated_image = uint(calibrated_image) create_log_entry, logname, '[Calibration Module] Calibrated image created' ;------------------------------------------------------------------------------------------------------------------------- ; ;return calibrated image ; ;------------------------------------------------------------------------------------------------------------------------- ;; 2008 Feb 13, BG: Added optional return of float image if integer eq 1 then begin return, calibrated_image endif else begin return, calibrated_image_flt endelse end