procedure AptProc (dir, files, useflat, bias, short, flat) # An IRAF program to process APT images taken with lo gain. # # Michael Ashley / UNSW / 03-Aug-1995 # Daniel Marlay / UNSW / 07-Feb-1997 # # Type the following command into the IRAF cl to use this program: # # task AptProc=/usr/users/astro/mcba/apt/AptProc.cl # # The following are the typical steps to use when processing 800x1200 pixel # APT images: # # - Create a file containing the names of the flat field images # - Process these with "AptProc ./ @flatfile useflat- short- bias=0" # - Produce a "superflat", by, for example: # # imcombine @flatfile output=superflat combine="average" # reject="avsigclip" scale="median" weight="median" mclip+ lsigma=3 # hsigma=2 # # (make sure that the means from imcombine look OK (i.e., close to 20000 # counts)) # # then normalise the image to 1.000 by dividing by the mean: # # imstatistics (images=temp2, fields="mean", format-) | scan (mean) # imarith (temp2, "/", mean, outfile) # # - Create a file containing the names of the star images # - Process these with "AptProc ./ @starfile useflat+ flat="superflat" short- bias=0" # string dir="./" {prompt="Input directory"} string files="im?????" {prompt="Input filename template"} bool useflat {prompt="Do you wish to flat field the images?"} string flat = "" {prompt="Flat field image to use"} bool short {prompt="Do you wish to convert to short integers?"} real bias {prompt="Bias value? (0 to find automatically)"} char version = "27Sep98" {prompt="Program version"} struct *imglist begin string Idir, Ifiles, Iflat bool Iuseflat, Ishort real Ibias, Jbias real stddev string imgfile, img, outfile string j1, j2 int n1, n2, nf1, nf2 # Load the parameters into local variables so that they are prompted # for early on, and in the right order. Idir = dir Ifiles = files Iuseflat = useflat Ibias = bias Ishort = short # If flatfielding is being done, make sure that the flat field file # exists, and find its size. if (Iuseflat) { Iflat = flat imgets (image = Iflat, param = "i_naxis1") nf1 = int (imgets.value) imgets (image = Iflat, param = "i_naxis2") nf2 = int (imgets.value) # if ((n1 != 770) && (n2 != 1150)) { # printf ("the flat field image is the wrong size (should be 770, 1150)\n"); # bye # } } # Restore defaults for all the IRAF routines we use. unlearn sections unlearn imcopy unlearn imexpr unlearn imdelete unlearn rfits unlearn imstatistics unlearn imarith # Create some temporary files. j1 = mktemp ("/tmp/j1") j2 = mktemp ("/tmp/j2") imgfile = mktemp ("/tmp/img") # Check to see whether the user provided a trailing slash on the # directory name. If not, add it. i = strlen (Idir) if (substr (Idir, i, i) == "/") { sections (Idir//Ifiles, option="fullname", > imgfile) } else { sections (Idir//"/"//Ifiles, option="fullname", > imgfile) } # Now process each file found. First, strip the .fits suffix and # directory prefix, to create the IRAF name. imglist = imgfile while (fscan (imglist, img) != EOF) { Jbias = Ibias i = strlen (img) if (substr (img, i-4, i) == ".fits") img = substr (img, 1, i-5) outfile = img//"p" j = stridx ("/", outfile) while (j != 0) { i = strlen (outfile) outfile = substr (outfile, j+1, i) j = stridx ("/", outfile) } # Convert to IRAF format. printf ("Processing %s --> %s\n", img, outfile) # rfits (fits_file=img, # file_list= "", iraf_file= j1, make_im+, long_he-, # short_header-) imcopy (img, j1, >& "dev$null") if (Jbias == 0.0) { # Find the bias level. printf ("finding bias level...") imstatistics (images=j1//'[797:800,4:573]', fields="mean,stddev",format-) | scan (Jbias, stddev) imstatistics (images=j1//'[797:800,4:573]', fields="mean,stddev", lower=(Jbias-2*stddev), upper=(Jbias+2*stddev) ,format-) | scan (Jbias, stddev) printf ("%8.2f+/-%4.2f...", Jbias, stddev) # Trim the image. printf ("trimming...\n") imcopy (input=j1//"[24:793,2:1151]", output=j1, ver-) } # Find the image dimensions. imgets (image = j1, param = "i_naxis1") n1 = int (imgets.value) imgets (image = j1, param = "i_naxis2") n2 = int (imgets.value) # Subtract the bias level. printf (" bias subtraction...") imarith (operand1 = j1, op = "-", operand2 = Jbias, result = j1) # Linearity correction. printf ("linearity...") if (access (outfile//".imh")) imdelete (images = outfile) if (access (outfile//".fits")) imdelete (images = outfile) # imexpr ("a < 15700 ? a*(1-6e-7*a) : a*(0.9424+3.07e-6*a)", outfile, j1) imexpr ("a < 12000 ? a*(1-6.8e-7*a) : 806+a*(0.8586+a*(5.90e-6-a*3.12e-11))", outfile, j1) # Flat field correction, if required. if (Iuseflat) { printf (" flat fielding...") if ((n1 != nf1) && (n2 != nf2)) { printf ("the image and the flat field are different sizes\n"); bye } imarith (operand1 = outfile, op = "/", operand2 = Iflat, result = j2) imdelete (images = outfile) imrename (j2, outfile) } # Divide by two and convert to short, to reduce the disk storage requirements. if (Ishort) { printf (" converting to short integers...") imarith (operand1 = outfile, op = "/", operand2 = 2, result = j2, pixtype = "short") imdelete (images = outfile) imrename (j2, outfile) } printf ("\n") imdelete (j1, ver-, >& "dev$null") imdelete (j2, ver-, >& "dev$null") } delete (imgfile, ver-, >& "dev$null") end