#!/usr/bin/python2 # # This program reads the name of two WFI MEF # files and outputs a list with global positions # in both frames, magnitude differences, and # magnitude errors # from irafdao import * from zplib import * def printUsageMessage(): print """ USAGE: zpPrepareData.py MEFFile1 MEFFile2 outputFile where can be any, all, or none of: -help # print general help to the routine -bckgStdDev [20.0] # std deviation of back sky (find) -xsigma [10.0] # number of sigmas above bckg for detection (find) -ap [5.0] # radius of aperture for photometry (phot) -sr [4.0] # inner radius of sky annulus (phot) -sw [5.0] # width of sky annulus (phot) -nFrames [8] # number of chips to be analyzed per image -im1FrameList ["1 2 3 4 5 6 7 8"] # list of chip numbers in MEFFile1 -im2FrameList ["1 2 3 4 5 6 7 8"] # corresponding list of chip numbers in MEFFile2 The numbers in the square brackets are the default values. For further help call the program with the option -help. The program needs to be able to call shell wraper scripts to the IRAF routines find,phot,pdump, and tvmark, called from the library irafdao.py, and zplib.py. Read the documentation for further details. DEPENDENCIES: irafdao.py # local python library to interface with IRAF zplib.py # python library with utility functions ds9 # the SAO image display program IRAF # a working installation of IRAF tcliraf # a set of irafscripts to the IRAF functions (not pyraf) EXAMPLES: 1.- zpPrepareData.py WFI_Ima.12.fits WFI_Ima.13.fits Vdx.zp This is used to analyze all 8 chips, and to store the results in the file Vdx.zp. You would use this if the offsets are in the x direction (constant declination), and not larger than one chip width, e.g. 400 pixels. 2.- zpPrepareData.py -nFrames 6 -im1FrameList "2 3 4 5 6 7" -im2FrameList "1 2 3 6 7 8" WFI_Ima.12.fits WFI_Ima.13.fits Vdx.zp This is used if the offsets are approximately one chip width. Thus, chip 2 of WFI_Ima.12.fits corresponds to chip 1 of WFI_Ima.13.fits, etc. """ return def printHelpMessage(): print """\n GENERAL HELP: This routine is used to find stars and to do apperture photometry on these stars. A large portion of the same stars should be present in both files MEFFile1 and MEFFile2. The stars could or could not be in the same chips, although the former case is easier to analyze. This routine is used to prepare data for the python script zpAnalyze.py, which fits a 2D Chebyshev polynomial basis to data generated by this routine. A typical run is as follows for each of the chips to be analyzed the program: 1. display the chip of File1 2. Find stars automatically in this chip of File1 3. tvmarks the finds in the display 4. display the corresponding chip of File2 5. marks the previous finds on this chip 6. INTERACTIVE: the program ask the user to click first on a star and then on the corresponding dot. 7. The program then does aperture photometry on the second image 8. Then the positions of the stars, refered to the whole WFI mosaic, together with the magnitude differences are appended at the end of outputFile. """ return if __name__ == "__main__": xsigma = 10.0 # number of sigmas above bckg for detection bckgStdDev = 20.0 # std deviation of background sr = 4.0 # inner radius of sky annulus sw = 5.0 # outer radius of sky annulus ap = 5.0 # aperture radius for photometry nFrames = 8 # number of frames out of the total that will be analyzed im1FrameList = [] # list of frame numbers in image 1. should be of length nFrames im2FrameList = [] # list of frame numbers in image 2. should be of length nFrames varlistNames = ['bckgStdDev', 'xsigma', 'sr','sw','ap', 'nFrames', 'im1FrameList', 'im2FrameList'] # if there is a -help option we just print the general help message # notice that this is the only no-argument option allowed. # for anArgument in argv: if anArgument == '-help': printHelpMessage() sys.exit(0) # parsing options lineargs = getopts(argv) # if there is an optfile we read the variable values from it # if lineargs.has_key('-optfile'): optDict = getoptsFromFile(lineargs['-optfile']) for i in range(len(varlistNames)): if optDict.has_key(varlistNames[i]): if varlistNames[i] == "im1FrameList": exec(varlistNames[i] + " = " + "\"" + optDict[varlistNames[i]] + "\"") im1FrameList = string.split(im1FrameList) elif varlistNames[i] == "im2FrameList": exec(varlistNames[i] + " = " + "\"" + optDict[varlistNames[i]] + "\"") im2FrameList = string.split(im2FrameList) else: exec(varlistNames[i] + " = " + optDict[varlistNames[i]]) # now we fill the rest of the variables in the # command line # for i in range(len(varlistNames)): thekey = '-' + varlistNames[i] if lineargs.has_key(thekey): if varlistNames[i] == "im1FrameList": exec(varlistNames[i] + " = " + "\"" + lineargs[thekey] + "\"") im1FrameList = string.split(im1FrameList) elif varlistNames[i] == "im2FrameList": exec(varlistNames[i] + " = " + "\"" + lineargs[thekey] + "\"") im2FrameList = string.split(im2FrameList) else: exec(varlistNames[i] + " = " + lineargs[thekey]) if len(im1FrameList) != 0 or len(im2FrameList) != 0: if nFrames != len(im1FrameList) or nFrames != len(im2FrameList): print "incompatible lengths of input frame numbers" sys.exit(0) # now we create a dictionary with the corresponding chip numbers # if nFrames < 8: chipInImage1 = {} chipInImage2 = {} for counter in range(nFrames): chipInImage1[counter] = string.atoi(im1FrameList[counter]) chipInImage2[counter] = string.atoi(im2FrameList[counter]) elif nFrames == 8: chipInImage1 = {} chipInImage2 = {} for counter in range(nFrames): chipInImage1[counter] = counter + 1 chipInImage2[counter] = counter + 1 else: print "error in nFrames" sys.exit(0) print chipInImage1 print chipInImage2 writeFindpars(xsigma) # number of sigmas above bckg for detection writeCenterpars() writeFitskypars("median",sr,sw) # inner rad= 4.0 width = 5.0 writeDatapars(bckgStdDev) # std deviation of bckg = 4.0 assuming only RON writePhotpars(ap) # with aperture radius = 5 parsedFileList = getFileList(argv) # whatever is not an otion is the file list if len(parsedFileList) == 3: # daophot parameter files # datapars=dataparsFileName() findpars=findparsFileName() centerpars=centerparsFileName() fitskypars=fitskyparsFileName() photpars=photparsFileName() # temporary files used by script # daofindTemp = "daofind_tmp.coo" daofindTemp2 = "daofind_tmp2.coo" photTemp = "phot_tmp.mag" photTemp2 = "phot_tmp2.mag" # mosaic parameters # chipOriginX,chipOriginY = getChipOriginXY('WFI') # here we start... frame1 = parsedFileList[0] frame2 = parsedFileList[1] zpFileName = parsedFileList[2] # name of file to store zero point data z1=-100 z2=3600 for i in range(nFrames): chipN1 = chipInImage1[i] chipN2 = chipInImage2[i] chip1x0,chip1y0 = chipOriginX[chipInImage1[i]-1],chipOriginY[chipInImage1[i]-1] chip2x0,chip2y0 = chipOriginX[chipInImage2[i]-1],chipOriginY[chipInImage2[i]-1] currentFrame1 = frame1 + "[" + str(chipN1) + "]" currentFrame2 = frame2 + "[" + str(chipN2) + "]" # we first display the first image # print "Processing chip %2d of frame1=%s" % (chipN1,currentFrame1,) print "Displaying chip %2d of frame1=%s" % (chipN1,currentFrame1,) Disp(currentFrame1,z1,z2) # we now find stars in this frane # print "Finding stars in chip %2d of frame1=%s" % (chipN1,frame1,) Find(currentFrame1,daofindTemp,datapars,findpars) # we now mark the findings # print "tvmarking the finds in chip %2d of frame1=%s" % (chipN1,currentFrame1,) Tvmark(daofindTemp,color=204,psize=1) # we now do aperture photometry on the findings # print "running phot on chip %2d of frame1=%s" % (chipN1,currentFrame1,) Phot(currentFrame1,daofindTemp,photTemp,datapars,centerpars,fitskypars,photpars) # now we display the second frame # print "Displaying chip %2d of frame2=%s" % (chipN2,currentFrame2) Disp(currentFrame2, z1, z2) # and we dump the finds on the first frame over this image # print "tvmarking the finds in chip %2d of frame1=%s over chip %2d of frame2=%s" % (chipN1,currentFrame1,chipN2,currentFrame2,) Tvmark(daofindTemp,color=205,psize=3) # now we interact with ds9 to calculate the offset # print "identifying the same star in both frames" (xOffset,yOffset) = ds9_getOffsetInteractor(1000,2000) # now we offset the coordinates # print "offsetting coordinates" offsetCoo(daofindTemp,xOffset,yOffset,daofindTemp2) # and we dump the offseted coordinates on the second image # print "tvmarking the offseted coordinates" Tvmark(daofindTemp2,color=205,psize=3) print "running phot on chip %2d of frame2=%s" % (chipN2,frame2,) Phot(currentFrame2, daofindTemp2, photTemp2, datapars, centerpars, fitskypars, photpars) print "Calculating differences" (xc1,yc1,xc2,yc2,dm21,merr,mavg,id) = calcPhotDiff(photTemp,photTemp2,chip1x0,chip1y0,chip2x0,chip2y0) print "Storing results" writePhotDiffTo(zpFileName,xc1,yc1,xc2,yc2,dm21,merr,mavg,id,chipN1,chipN2) # and now some housecleaning before continuing # os.system("rm " + daofindTemp + " " + daofindTemp2) os.system("rm " + photTemp + " " + photTemp2) print "\n" # y aqui no paso nada # delPhotpars() delFindpars() delCenterpars() delFitskypars() delDatapars() else: print "wrong number of arguments to program" printUsageMessage()