procedure tringSub (imageFile, maxShift, smth, boxSize, doSubtraction, report) string imageFile {prompt="Image list to create flats from (no extensions)"} real maxShift {15, prompt="Amount of shift (in pix) for the 9 images"} bool smth {no, prompt="Smooth background map before applying?"} int boxSize {40, prompt=" Size of box for background smoothing"} bool doSubtraction {no, prompt="Subtract original images with flats?"} bool report {yes, prompt="Report creation of each shifted image?"} struct *flist # list-directed structure to go thru imageFile begin # ################################################################# # # NOTE: THIS TASK RELIES ON THERE BEING: # (A) RAW BIAS-SUBTRACTED,TRIMMED AND F-F IMAGES ("ff" extension) # (B) SAME IMAGES BUT NORMALISED TO 1.0 ("f" extension) # HOWEVER, THE IMAGE FILE LIST CONTAINS NEITHER OF THESE EXTENSIONS # # ################################################################# # Variable Declarations: struct image # current image name (NO EXTENSIONS) string inpImage # input image name (WITH EXTENSIONS) string newFlat # new background flat being created from "image" string newShifted # new shifted version of "image" string newImage # new flat-fielded "image" string message # string containing a message output to user int i # counter real X,Y # amounts to shift "image" in order to # create the 9 new images flist = imageFile # putting the contents of the list contained in imageFile # to the list-directed structure *flist # Make sure the IMAGES package is loaded: if (! defpac ("images")) { print("IMAGES package not loaded") bye } # Looping to form temporary file of sky background samples: while ( fscan(flist, image) != EOF) { print (" ") print ("-----------------------------------") message = image//":" print (message) print (" ") # X = maxShift # Y = maxShift X = -1*maxShift Y = -1*maxShift # message = "initially: ("//X//","//Y//")" # print (message) # print(" ") i=0 # i.e. inital values of x and y shifts; fresh image ==> i=0 initially delete (files="temp_shiftlist",go_ahea+,ver-) while (X <= maxShift) { while (Y <= maxShift) { i = i + 1 newShifted="tempSH"//image//"_"//i print(newShifted, >> "temp_shiftlist") # inpImage = image//"f" # N.B.: Shifted images are created from "f" images inpImage = image//"ff" # *** N.B.: Shifted images are created from "ff" images imshift (input=inpImage,output=newShifted,xshift=X, yshift=Y,shifts_="",interp_="linear",boundar="nearest",constant=0) if (report==yes) { message = newShifted//" created at ("//X//","//Y//")" print(message) } Y = Y+maxShift } # i.e. end of Y loop X = X+maxShift Y = -1*maxShift } # i.e. end of X loop # print(" ") # !ls -l # Combining shifted images to form flat (with "flat" extension): # *** N.B.: We have to use ".imh" extension when using * wildcard, # (to avoid confusion with ".pix" files of same name). newFlat = image//"flat" # imcombine (input="tempSHIFT*.imh",output=newFlat,combin="median", reject="pclip",outtype="real",lsigma=3.,hsigma=3.,sigscal=0.1,pclip=-2.) # ** OLD VERSION OF IMCOMBINE USED imdelete (images=newFlat,verify=no,default=yes,go_ahead=yes) imcombine (input="@temp_shiftlist",output=newFlat,combin="median", reject="minmax",outtype="real", scale="none", nlow=1, nhigh=3, nkeep=5, mclip=yes, lsigma=3.,hsigma=3) # Smoothing the resulting background map: if (smth==yes) { fmedian (input=newFlat, output="tempSMOOTH", xwind=boxSize, ywind=boxSize, hmin=-32768, hmax=32767, zmin=INDEF, zmax=INDEF, unmap=yes, boundar="nearest", constan=0) imdelete (images=newFlat,verify=no,default=yes,go_ahead=yes) imrename (oldnames="tempSMOOTH", newnames=newFlat, verb=no) } print(" ") message = newFlat//" has been created ..." print (message) # Deleting shifted images (and list) before starting next input image: # *** N.B.: We have to use ".imh" extension when using * wildcard, # (to avoid confusion with ".pix" files of same name). imdelete (images="@temp_shiftlist",verify=no,default=yes,go_ahead=yes) message = "Shifted images for "//image//" have been deleted ..." print(" ") print (message) # print ("(Ignore above warnings about inability to access images.)") # Subtracting original image by flat (if this has been requested): if (doSubtraction == yes) { inpImage = image//"ff" newImage = image//"c" imdelete (images=newImage,verify=no,default=yes,go_ahead=yes) imarith (operand1=inpImage,op="-",operand2=newFlat, result=newImage,divzero=0,verbose=yes) message = newImage//" has been created (= "//image//"ff - "//newFlat//") ..." print(message) } # ################## } # i.e. end of main image-list loop delete (files="temp_shiftlist",go_ahea+,ver-) print (" ") print ("-----------------------------------") end