# procedure maestro_biaser (filenames) #---------------------------------------------------------------------------- # # Maestro de-overscanner, version of 21 July 2007 # Modified by Jill, Aug. 2 2007 so that you don't have to make # funky temporary files # Modified by Jill, Nov. 27, 2007 to make sure header info is retained # Modified by Christy, Dec 12, 2007 to work on lists # # THIS DESTROYS THE ORIGINAL COPY OF THE IMAGE, so make copies in a # REDUCED AREA # # The values for binning 1x1 are hardwired in at this time # # To run this, in iraf you say "task maestro_biaser = maestro_biaser.cl" # then you say "maestro_biaser filename.fits" or just "maestro_biaser" # you can also say "epar maestro_biaser" # # It works by making two temporary copies of the file to be de-overscanned # and doing ccdproc and trimming on each amp in turn, then copying the two # halves onto an already existing 4096x4096 image. At the end, it cleans # up and fools iraf into thinking it did the work itself so, flatfielding, # etc. ought to work in iraf as usual. # #---------------------------------------------------------------------------- # Define parameter file string filenames {prompt="Images to de-overscan"} bool interact = no {prompt="Interactively fit overscan?"} int oorder = 3 {prompt="Overscan fitting order"} struct *flist begin #---------------------------------------------------------------------------- # Define variables string filelist, temp_list, temp_img1, temp_img2, temp_img3 string ba, da, bb, db, new_bb, new_db string db_x1, db_x2, ba_x1, ba_x2, bb_x1, bb_x2, ysec string temp_name1, temp_name2 bool iact int order, dwidth, bwidth, nx, ny struct imgname filelist = filenames iact = interact order = oorder #--------------------------------------------------------------------------- # Check that appropriate packages are loaded if (! defpac("ctio")) {print ("Load package 'ctio' before proceeding")} if (! defpac("imred")) {print ("Load package 'imred' before proceeding")} if (! defpac("ccdred")) {print ("Load package 'ccdred' before proceeding")} if ( (!defpac("ctio")) || (!defpac("imred")) || (!defpac("ccdred")) ) { bye } #---------------------------------------------------------------------------- # Make temporary images delete ("tmp$maestro_tmp*", ver-) temp_list = mktemp("tmp$maestro_tmp") temp_img1 = mktemp("tmp$maestro_tmp") temp_img2 = mktemp("tmp$maestro_tmp") temp_img3 = mktemp("tmp$maestro_tmp") #----------------------------------------------------------------------------- # Loop through input images # expand list files(filelist, >> temp_list) flist = temp_list while (fscan (flist, imgname) != EOF) { # Check to see if it's already been done imgets(imgname, "TRIM") if (strstr("maestro", imgets.value) != 0) { print ("Skipping "//imgname//" -- already done." ) next } print("Processing "//imgname) #---------------------------------------------------------------------------- # Copy left and right halves of the image into temporary files # Get dimensins from image imgets(imgname, "DSEC01A") # Datasec Chip A da = imgets.value ysec = substr(da, stridx(",",da), strlen(da)) # y-dimiensions imgets(imgname, "DSEC01B") # Datasec Chip B db = imgets.value db_x1 = substr(db, 2, stridx(":",db)-1) db_x2 = substr(db, stridx(":",db)+1, stridx(",",db)-1) imgets(imgname, "BSEC01A") # Biassec Chip A ba = imgets.value ba_x1 = substr(ba, 2, stridx(":",ba)-1) ba_x2 = substr(ba, stridx(":",ba)+1, stridx(",",ba)-1) imgets(imgname, "BSEC01B") # Biassec Chip B bb = imgets.value bb_x1 = substr(bb, 2, stridx(":",ba)-1) bb_x2 = substr(bb, stridx(":",ba)+1, stridx(",",ba)-1) # Copy chips A & B into separate temporary images imcopy (imgname//"[1:"//ba_x2//ysec, temp_img1, verb-) imcopy (imgname//"["//bb_x1//":"//db_x2//ysec, temp_img2, verb-) bwidth = int(bb_x2) - int(bb_x1) + 1 # x-width of bias dwidth = int(db_x2) - int(db_x1) + 1 # x-width of data new_bb = "[1:"//bwidth//ysec # new biassec for Chip B new_db = "["//bwidth+1//":"//dwidth + bwidth//ysec # new datasec for Chip B #---------------------------------------------------------------------------- # Edit temporary headers and use CCDPROC to bias subtract hedit (temp_img1, "BIASSEC", ba, delete-, verify-, show-, update+) hedit (temp_img1, "DATASEC", da, delete-, verify-, show-, update+) hedit (temp_img1, "TRIMSEC", da, delete-, verify-, show-, update+) hedit (temp_img1, "CCDSEC", da, delete-, verify-, show-, update+) unlearn("ccdproc") ccdproc (temp_img1, ccdtype="", fixpix-, overscan+, trim+, zerocor-, darkcor-, biassec=ba, trimsec=da, flatcor-, order=order, interact=iact) hedit (temp_img2, "BIASSEC", new_bb, delete-, verify-, show-, update+) hedit (temp_img2, "DATASEC", new_db, delete-, verify-, show-, update+) hedit (temp_img2, "TRIMSEC", new_db, delete-, verify-, show-, update+) hedit (temp_img2, "CCDSEC", new_db, delete-, verify-, show-, update+) ccdproc (temp_img2, ccdtype="", fixpix-, overscan+, trim+, zerocor-, darkcor-, flatcor-, biassec=new_bb, trimsec=new_db, order=order, interact=iact) #---------------------------------------------------------------------------- # Make an empty fullsize image and copy the image halves into it #nx = dwidth * 2 #ny = int(substr(ysec, stridx(":", ysec) + 1, strlen(ysec) - 1)) #imcreate (temp_img3, 2, nx, ny, header="copy", reference=imgname) #imcopy (temp_img1, temp_img3//"[1:"//dwidth//ysec, verbose-) #imcopy (temp_img2, temp_img3//"["//dwidth+1//":"//nx//ysec, verbose-) print(temp_img1) | scan(temp_name1) print(temp_img2) | scan(temp_name2) imjoin (temp_name1//","//temp_name2, temp_img3, 1, pixtype="", verb-) hedit (temp_img3, "DATASEC", "[1:"//dwidth*2//ysec, delete-, verify-, show-, update+) hedit (temp_img3, "CCDSEC", "[1:"//dwidth*2//ysec, delete-, verify-, show-, update+) # Fake iraf into thinking it did the work hedit (temp_img3, "CCDPROC", "CCD PROCESSING DONE", add+, delete-, verify-, show-, update+) hedit (temp_img3, "TRIM", "TRIM done in maestro_biaser.cl", add+, delete-, verify-, show-, update+) hedit (temp_img3, "OVERSCAN", "OVERSCAN done in maestro_biaser.cl", add+, delete-, verify-, show-, update+) #--------------------------------------------------------------------------- # Clean up imdel (temp_img1, ver-) imdel (temp_img2, ver-) # this next step deletes the original image imdel (imgname, verify = iact) #this next step renames the tempfile to the original name imrename (temp_img3, imgname, verb-) } end