;+ ; ccd2bias.pro ; ; Subtract overscan region from CCD-2 images in one-amp mode ; ; Usage: ; ccd2bias, InFileName, OutFileName, lengendre=legendre ; ; Author: Elinor L. Gates, Lick Observatory, December 2006 ; ; Version: 3 (2010 June 29) ; Adapted from IRAF procedure pfcambias.cl by Mike Bolte. ; Extracts data regions and overscan regions from CCD-2 FITS data. ; Finds mean of each row of overscan and subtracts that from the ; data, or fits Legendre polynomial to overscan region. Subtracts overscan ; fit from data. Writes overscan subtracted data to new FITS file. ; ; Inputs: ; InFileName - Input file name ; OutFileName - Output file name ; Fit - [optional] no or legendre fitting to overscan. Default is ; no fitting. ; ; Examples: ; ccd2bias,'d100.fits','d100_new.fits' ; ccd2bias,'d1000.fits','d1000new.fits',/legendre ;- pro ccd2bias,infile,outfile,legendre=legendre ;read in FITS file and header im=readfits(infile,h) ;read necessary parameters from FITS header xsize=sxpar(h,'NAXIS1') ; number of columns (including overscan) ysize=sxpar(h,'NAXIS2') ; number of rows xorig=sxpar(h,'CRVAL1U') ; readout origin on unbinned chip cdelt1=sxpar(h,'CDELT1U') ; column change per pixel (i.e. binning and direction) cover=sxpar(h,'COVER') ; number of overscan columns for each amplifier ;extract overscan regions (each over scan region is cover pixels wide) biassec=float(im[xsize-cover:xsize-1,*]) ;average overscan regions along the readout axis n=(size(biassec))[2] overscan=fltarr(n) for i=0,n-1 do overscan[i]=total(biassec[*,i])/float(cover) if keyword_set(legendre) then begin ;fit third order legendre polynomial to overscan regions x=findgen(n) ofit=svdfit(x,overscan,2,yfit=overscanfit,/legendre) endif else overscanfit=overscan ;extract data regions and subtract overscan fits imnew=float(im[0:xsize-1-cover,*]) m=(size(imnew))[1] for i=0,m-1 do imnew[i,*]=imnew[i,*]-overscanfit ;update header information bzero=sxpar(h,'BZERO') bzero=float(bzero) if bzero ne 0 then begin sxaddpar,h,'O_BZERO',bzero,'Original Data is unsigned Integer' sxaddpar,h,'BZERO',0.0,/PDU endif bscale=sxpar(h,'BSCALE') bscale=float(bscale) if bscale ne 1.0 then begin sxaddpar,h,'O_BSCALE',bscale,'Original Data is scaled' sxaddpar,h,'BSCALE',1.0,/PDU endif sxaddpar,h,'HISTORY',"= 'OVERSCAN SUBTRACTED'" ;write overscan subtracted image to file writefits,outfile,imnew,h end