procedure tcombine (nScans,impref1,impref2,impref3,start1,end1,start2,end2, start3,end3,inExtn,outType,clnNum,clnOver,clnExtn,clipmode,gnW,rnW,sumNum, sumOver,sumExtn,outpref,maskType,maskZer,clnmaRMS,summaRMS,logname,convFits) int nScans {3,prompt="Number of image scans (<=3)"} string impref1 {prompt=" Scan 1: Image name prefix"} string impref2 {prompt=" Scan 2: Image name prefix"} string impref3 {prompt=" Scan 3: Image name prefix"} int start1 {prompt=" Scan 1: Image start number"} int end1 {prompt=" Scan 1: Image finish number"} int start2 {prompt=" Scan 2: Image start number"} int end2 {prompt=" Scan 2: Image finish number"} int start3 {prompt=" Scan 3: Image start number"} int end3 {prompt=" Scan 3: Image finish number"} string inExtn {"r", prompt="Extension for all input images?"} string outType {"cleaned", prompt="Output images (cleaned|summed|both)"} int clnNum {2, prompt=" Cleaned: 2 or 1 combined images output slice"} bool clnOver {yes, prompt=" Cleaned: Overlap adjacent images?"} string clnExtn {"c1", prompt=" Cleaned: Output image extension?"} string clipmode {"avsigclip", prompt=" Cleaning method (avsigclip|pclip|crreject)"} real gnW {2.74, prompt=" -> crreject: CCD gain (e-/ADU)"} real rnW {4.8, prompt=" -> crreject: CCD read noise (e-)"} int sumNum {2, prompt=" Summed: 2 or 1 combined images per slice"} bool sumOver {no, prompt=" Summed: Overlap adjacent images?"} string sumExtn {"s1", prompt=" Summed: Output image extension?"} string outpref {"b", prompt="Prefix for all output images?"} string maskType {"rms", prompt="Apply corner mask? (none|zero|rms)"} string maskZer {"-",prompt=" Zero mask image (full name)"} string clnmaRMS {"--",prompt=" Cleaned: RMS mask image (full name)"} string summaRMS {"---",prompt=" Summed: RMS mask image (full name)"} string logname {"STDOUT", prompt="Log file written here"} bool convFits {no, prompt="Convert output images to FITS FORMAT?"} struct *flist1a # list-directed structure to go thru scan 1 struct *flist1b # list-directed structure to go thru scan 1 struct *flist2a # list-directed structure to go thru scan 2 struct *flist2b # list-directed structure to go thru scan 2 struct *flist3a # list-directed structure to go thru scan 3 struct *flist3b # list-directed structure to go thru scan 3 begin # Variable Declarations: struct image1b # 2nd image from list 1 (if combining in pairs) # or 1st image (if combining individually) struct image1a # 1st image from list 1 (if combining in pairs) struct image2b struct image2a struct image3b struct image3a string itemp # temporary image name; not used for anything string outIm # name of output image string fitsname # name of fits version of image if (! defpac ("images")) { print("Package IMAGES needs to be loaded.") bye } # Cleaning-up old files and ones about to be created: delete (files="temp_tcomb*",go_ahea+,ver-) imdelete (images="tempImg",verify=no,default=yes, go_ahead=yes) # Creating individual scan lists: # temp_tcomb1 - 1st scan # temp_tcomb2 - 2nd scan # temp_tcomb3 - 3rd scan # temp_tcomb4 - all scans concatenated print (" ") print ("Creating image lists (please wait) ...") print (" ") if ((nScans>=1)&&(nScans<=3)) { tmakefile (file_out="temp_tcomb1",startNum=start1,stopNum=end1, prefixOU=impref1,anyExtn-,extnOU="",padOU+,listImgs-) !cp temp_tcomb1 temp_tcomb4 } if ((nScans>=2)&&(nScans<=3)) { tmakefile (file_out="temp_tcomb2",startNum=start2,stopNum=end2, prefixOU=impref2,anyExtn-,extnOU="",padOU+,listImgs-) ! cat -s temp_tcomb4 temp_tcomb2 >> temp_tcomb4 } if (nScans==3) { tmakefile (file_out="temp_tcomb3",startNum=start3,stopNum=end3, prefixOU=impref3,anyExtn-,extnOU="",padOU+,listImgs-) ! cat -s temp_tcomb4 temp_tcomb3 >> temp_tcomb4 } if (nScans>3) { print (" ") print (" *** Invalid number of scans *** ") bye } if (nScans<1) { print (" ") print (" *** Invalid number of scans *** ") bye } # CLEANED ---------------------------------------------------------- if ((outType=="cleaned")||(outType=="both")) { if ((clnNum==1)&&(clnOver==yes)) { print (" ") print (" *** Can not overlap single-slice CLEANED output *** ") print (" --> resetting clnOver to no") print (" ") clnOver=no } print (" ") print ("============================================================") print (" ") print ("Creating CLEANED images ...") print (" ") print ("Input slices per output slice: "//clnNum) if (clnOver==yes) { print ("Overlapping slices: Yes") } if (clnOver==no) { print ("Overlapping slices: No") } print (" ") # Initialising scan position of the second image scan variable # (or first image scan variable in the case of individual combination) if ((nScans>=1)&&(nScans<=3)) { flist1a = "temp_tcomb1" flist1b = "temp_tcomb1" itemp = fscan(flist1b, image1b) # delete(files="temp_tcomb.jnk",verify-,default+,go_ahead+) print(image1b//inExtn, > "temp_tcomb.jnk") } if ((nScans>=2)&&(nScans<=3)) { flist2a = "temp_tcomb2" flist2b = "temp_tcomb2" itemp = fscan(flist2b, image2b) print(image2b//inExtn, >> "temp_tcomb.jnk") } if (nScans==3) { flist3a = "temp_tcomb3" flist3b = "temp_tcomb3" itemp = fscan(flist3b, image3b) print(image3b//inExtn, >> "temp_tcomb.jnk") } if (clnNum==1) { outIm = image1b//clnExtn imdelete (images=outIm,verify=no,default=yes, go_ahead=yes) # type (input_fi="temp_tcomb.jnk") # print (" --> combined to make image: "//outIm) # print ("--------------------------------------") # print (" ") if ((clipmode=="avsigclip")||(clipmode=="pclip")) { imcombine(inp="@temp_tcomb.jnk",output=outIm,logfile=logname,combine="median", rej=clipmode,proj=no,outty="real",offse="none",maskty="none",scale="none", zer="none",weig="none",statsec="",lthr=INDEF,hthr=INDEF,nkee=0, mclip=yes,lsig=2.5,hsig=2.5) } else { imcombine(inp="@temp_tcomb.jnk",output=outIm,logfile=logname,combine="median", rej="crreject",proj=no,outty="real",offse="none",maskty="none",scale="none", zer="none",weig="none",statsec="",lthr=INDEF,hthr=INDEF,nkee=0, mclip=no,lsig=2.5,hsig=2.5, rdnoise=rnW, gain=gnW, snoise=0.) # i.e. differs in the rej and mclip parameters mainly } if ((maskType=="zero")||(maskType=="rms")) { # Multiplying by zero mask (required by both cases): imarith(operand1=outIm,op="*",operand2=maskZer, result="tempImg",title="combined image",divzero=0,verb=no) imdelete (images=outIm,verify=no,default=yes, go_ahead=yes) imrename (oldnames="tempImg",newnames=outIm,verb=no) if (maskType=="rms") { # Adding RMS mask: imarith(operand1=outIm,op="+",operand2=clnmaRMS, result="tempImg",title="combined image",divzero=0,verb=no) imdelete (images=outIm,verify-,default+, go_ahead+) imrename (oldnames="tempImg",newnames=outIm,verb-) } } if (convFits==yes) { fitsname = outIm//".fits" print (" ") print (" Converting "//outIm//" to fits ("//fitsname//") ...") imdelete (images=fitsname,verify=no,default=yes, go_ahead=yes) imrename (oldnames=outIm,newnames="tempImg",verb=no) wfits(iraf_fil="tempImg",fits_fil=fitsname, make_im+,long_he-, short_h+,bitpix=0,blockin=0,scale+,autosca+, bscale=1.,bzero=0.) imdelete (images="tempImg",verify=no,default=yes, go_ahead=yes) } } # Main CLEANED loop: while ( fscan(flist1b, image1b) != EOF) { if (clnNum==2) { delete(files="temp_tcomb.jnk",verify-,default+,go_ahead+) if ((nScans>=1)&&(nScans<=3)) { itemp = fscan(flist1a, image1a) print(image1a//inExtn, > "temp_tcomb.jnk") } if ((nScans>=2)&&(nScans<=3)) { itemp = fscan(flist2a, image2a) print(image2a//inExtn, >> "temp_tcomb.jnk") } if (nScans==3) { itemp = fscan(flist3a, image3a) print(image3a//inExtn, >> "temp_tcomb.jnk") } } # i.e. only obtain previous images if combining in pairs # Writing the image defining this main loop (2 cases depending # on whether the above routine was used or bypassed): if (clnNum==1) { delete(files="temp_tcomb.jnk",verify-,default+,go_ahead+) print(image1b//inExtn, > "temp_tcomb.jnk") outIm = image1b//clnExtn } if (clnNum==2) { print(image1b//inExtn, >> "temp_tcomb.jnk") outIm = image1a//clnExtn } # scanning other images accordingly (if additional scans exist): if ((nScans>=2)&&(nScans<=3)) { itemp = fscan(flist2b, image2b) print(image2b//inExtn, >> "temp_tcomb.jnk") } if (nScans==3) { itemp = fscan(flist3b, image3b) print(image3b//inExtn, >> "temp_tcomb.jnk") } imdelete (images=outIm,verify=no,default=yes, go_ahead=yes) # type (input_fi="temp_tcomb.jnk") # print (" --> combined to make image: "//outIm) # print ("--------------------------------------") # print (" ") if ((clnNum==2)&&(clnOver==no)) { if ((nScans>=1)&&(nScans<=3)) { itemp = fscan(flist1a, image1a) itemp = fscan(flist1b, image1b) } if ((nScans>=2)&&(nScans<=3)) { itemp = fscan(flist2a, image2a) itemp = fscan(flist2b, image2b) } if (nScans==3) { itemp = fscan(flist3a, image3a) itemp = fscan(flist3b, image3b) } } # extra bit of scanning forward for non-overlap of pairs if ((clipmode=="avsigclip")||(clipmode=="pclip")) { imcombine(inp="@temp_tcomb.jnk",output=outIm,logfile=logname,combine="median", rej=clipmode,proj=no,outty="real",offse="none",maskty="none",scale="none", zer="none",weig="none",statsec="",lthr=INDEF,hthr=INDEF,nkee=0, mclip=yes,lsig=2.5,hsig=2.5) } else { imcombine(inp="@temp_tcomb.jnk",output=outIm,logfile=logname,combine="median", rej=clipmode,proj=no,outty="real",offse="none",maskty="none",scale="none", zer="none",weig="none",statsec="",lthr=INDEF,hthr=INDEF,nkee=0, mclip=no,lsig=2.5,hsig=2.5, rdnoise=rnW, gain=gnW, snoise=0.) # i.e. differs in the rej and mclip parameters mainly } if ((maskType=="zero")||(maskType=="rms")) { # Multiplying by zero mask (required by both cases): imarith(operand1=outIm,op="*",operand2=maskZer, result="tempImg",title="combined image",divzero=0,verb=no) imdelete (images=outIm,verify=no,default=yes, go_ahead=yes) imrename (oldnames="tempImg",newnames=outIm,verb=no) if (maskType=="rms") { # Adding RMS mask: imarith(operand1=outIm,op="+",operand2=clnmaRMS, result="tempImg",title="combined image",divzero=0,verb=no) imdelete (images=outIm,verify-,default+, go_ahead+) imrename (oldnames="tempImg",newnames=outIm,verb-) } } if (convFits==yes) { fitsname = outIm//".fits" print (" ") print (" Converting "//outIm//" to fits ("//fitsname//") ...") imdelete (images=fitsname,verify=no,default=yes, go_ahead=yes) imrename (oldnames=outIm,newnames="tempImg",verb=no) wfits(iraf_fil="tempImg",fits_fil=fitsname, make_im+,long_he-, short_h+,bitpix=0,blockin=0,scale+,autosca+, bscale=1.,bzero=0.) imdelete (images="tempImg",verify=no,default=yes, go_ahead=yes) } } } # end of CLEANED --------------------------------------------------- delete (files="temp_tcomb.jnk",go_ahea+,ver-) # SUMMED ----------------------------------------------------------- if ((outType=="summed")||(outType=="both")) { if ((sumNum==1)&&(sumOver==yes)) { print (" ") print (" *** Can not overlap single-slice SUMMED output *** ") print (" --> resetting sumOver to no") print (" ") clnOver=no } print (" ") print ("============================================================") print (" ") print ("Creating SUMMED images ...") print (" ") print ("Input slices per output slice: "//sumNum) if (sumOver==yes) { print ("Overlapping slices: Yes") } if (sumOver==no) { print ("Overlapping slices: No") } print (" ") # Initialising scan position of the second image scan variable # (or first image scan variable in the case of individual combination) if ((nScans>=1)&&(nScans<=3)) { flist1a = "temp_tcomb1" flist1b = "temp_tcomb1" itemp = fscan(flist1b, image1b) # delete(files="temp_tcomb.jnk",verify-,default+,go_ahead+) print(image1b//inExtn, > "temp_tcomb.jnk") } if ((nScans>=2)&&(nScans<=3)) { flist2a = "temp_tcomb2" flist2b = "temp_tcomb2" itemp = fscan(flist2b, image2b) print(image2b//inExtn, >> "temp_tcomb.jnk") } if (nScans==3) { flist3a = "temp_tcomb3" flist3b = "temp_tcomb3" itemp = fscan(flist3b, image3b) print(image3b//inExtn, >> "temp_tcomb.jnk") } if (sumNum==1) { outIm = image1b//sumExtn imdelete (images=outIm,verify=no,default=yes, go_ahead=yes) # type (input_fi="temp_tcomb.jnk") # print (" --> summed to make image: "//outIm) # print ("--------------------------------------") # print (" ") imsum(inp="@temp_tcomb.jnk",output=outIm,title="summed image",option="sum",low_rej=0., high_rej=0.,verb+) if ((maskType=="zero")||(maskType=="rms")) { # Multiplying by zero mask (required by both cases): imarith(operand1=outIm,op="*",operand2=maskZer, result="tempImg",title="combined image",divzero=0,verb=no) imdelete (images=outIm,verify=no,default=yes, go_ahead=yes) imrename (oldnames="tempImg",newnames=outIm,verb=no) if (maskType=="rms") { # Adding RMS mask: imarith(operand1=outIm,op="+",operand2=summaRMS, result="tempImg",title="combined image",divzero=0,verb=no) imdelete (images=outIm,verify-,default+, go_ahead+) imrename (oldnames="tempImg",newnames=outIm,verb-) } } if (convFits==yes) { fitsname = outIm//".fits" print (" ") print (" Converting "//outIm//" to fits ("//fitsname//") ...") imdelete (images=fitsname,verify=no,default=yes, go_ahead=yes) imrename (oldnames=outIm,newnames="tempImg",verb=no) wfits(iraf_fil="tempImg",fits_fil=fitsname, make_im+,long_he-, short_h+,bitpix=0,blockin=0,scale+,autosca+, bscale=1.,bzero=0.) imdelete (images="tempImg",verify=no,default=yes, go_ahead=yes) } } # Main SUMMED loop: while ( fscan(flist1b, image1b) != EOF) { if (sumNum==2) { delete(files="temp_tcomb.jnk",verify-,default+,go_ahead+) if ((nScans>=1)&&(nScans<=3)) { itemp = fscan(flist1a, image1a) print(image1a//inExtn, > "temp_tcomb.jnk") } if ((nScans>=2)&&(nScans<=3)) { itemp = fscan(flist2a, image2a) print(image2a//inExtn, >> "temp_tcomb.jnk") } if (nScans==3) { itemp = fscan(flist3a, image3a) print(image3a//inExtn, >> "temp_tcomb.jnk") } } # i.e. only obtain previous images if combining in pairs # Writing the image defining this main loop (2 cases depending # on whether the above routine was used or bypassed): if (sumNum==1) { delete(files="temp_tcomb.jnk",verify-,default+,go_ahead+) print(image1b//inExtn, > "temp_tcomb.jnk") outIm = image1b//sumExtn } if (sumNum==2) { print(image1b//inExtn, >> "temp_tcomb.jnk") outIm = image1a//sumExtn } # scanning other images accordingly (if additional scans exist): if ((nScans>=2)&&(nScans<=3)) { itemp = fscan(flist2b, image2b) print(image2b//inExtn, >> "temp_tcomb.jnk") } if (nScans==3) { itemp = fscan(flist3b, image3b) print(image3b//inExtn, >> "temp_tcomb.jnk") } imdelete (images=outIm,verify=no,default=yes, go_ahead=yes) # type (input_fi="temp_tcomb.jnk") # print (" --> summed to make image: "//outIm) # print ("--------------------------------------") # print (" ") if ((sumNum==2)&&(sumOver==no)) { if ((nScans>=1)&&(nScans<=3)) { itemp = fscan(flist1a, image1a) itemp = fscan(flist1b, image1b) } if ((nScans>=2)&&(nScans<=3)) { itemp = fscan(flist2a, image2a) itemp = fscan(flist2b, image2b) } if (nScans==3) { itemp = fscan(flist3a, image3a) itemp = fscan(flist3b, image3b) } } # extra bit of scanning forward for non-overlap of pairs imsum(inp="@temp_tcomb.jnk",output=outIm,title="summed image",option="sum",low_rej=0., high_rej=0.,verb+) if ((maskType=="zero")||(maskType=="rms")) { # Multiplying by zero mask (required by both cases): imarith(operand1=outIm,op="*",operand2=maskZer, result="tempImg",title="combined image",divzero=0,verb=no) imdelete (images=outIm,verify=no,default=yes, go_ahead=yes) imrename (oldnames="tempImg",newnames=outIm,verb=no) if (maskType=="rms") { # Adding RMS mask: imarith(operand1=outIm,op="+",operand2=summaRMS, result="tempImg",title="combined image",divzero=0,verb=no) imdelete (images=outIm,verify-,default+, go_ahead+) imrename (oldnames="tempImg",newnames=outIm,verb-) } } if (convFits==yes) { fitsname = outIm//".fits" print (" ") print (" Converting "//outIm//" to fits ("//fitsname//") ...") imdelete (images=fitsname,verify=no,default=yes, go_ahead=yes) imrename (oldnames=outIm,newnames="tempImg",verb=no) wfits(iraf_fil="tempImg",fits_fil=fitsname, make_im+,long_he-, short_h+,bitpix=0,blockin=0,scale+,autosca+, bscale=1.,bzero=0.) imdelete (images="tempImg",verify=no,default=yes, go_ahead=yes) } } } # end of SUMMED --------------------------------------------------- delete (files="temp_tcomb*",go_ahea+,ver-) print (" ") print ("============================================================") print (" ") print (" ") print ("Done.") print (" ") end