from fitsio import * import re import os,string,pickle,Numeric,umath #import FitsUtils,SpecUtils,PGPlotUtils import Scientific, Scientific.Statistics import fpformat from Scientific.IO.TextFile import TextFile ########################################################################### # program that use the n images taken to do the image analysis, and # use SEXTRACTOR to mesure the ellipticity of the stars ########################################################################### # function that assign the values to the pixels for each position on the # detector # fonction qui assigne les valeurs de pixels pour chaque position. def position(xpos,ypos): for xi in range(6): xetoile.append(xpos[xi]) yetoile.append(ypos[0]) for xi in range(5,-1,-1): xetoile.append(xpos[xi]) yetoile.append(ypos[1]) for xi in range(6): xetoile.append(xpos[xi]) yetoile.append(ypos[2]) for xi in range(5,-1,-1): xetoile.append(xpos[xi]) yetoile.append(ypos[3]) for xi in range(6): xetoile.append(xpos[xi]) yetoile.append(ypos[4]) for xi in range(5,-1,-1): xetoile.append(xpos[xi]) yetoile.append(ypos[5]) return xetoile, yetoile # debut du programme principal ############################################## # ouverture et lecture du fichier liste.txt qui comprend toutes les # informations : repertoire ou trouver les images, ficher listant les images # reduites .fits, # champ utilise (SMALL ou LARGE) pour SOFI ou instrument SUSI ou SOFI, # ainsi que le prefix a utiliser pour les fichiers # sextractor ############################################# file_liste = open('liste.txt', 'r') for line_mode in TextFile('liste.txt', 'r'): ####################################################################### # definition of the 36 positions and creation of pairs of position # ( xetoile, ytoile) that correspond to the positions that the star has on # the detector depending of which type of field (small or large) field = string.split(line_mode)[2] if field == 'SMALL' or field == 'FE': xpos = [-100,150,325,500,672,848] ypos = [69,244,419,595,769,945] elif field == 'LARGE' or field == 'SO': xpos = [45,210,395,569,741,916] ypos = [57,231,405,583,753,925] # a implementer quand je connaitrais les valeurs des pixels correpondant # aux offesets definis dans les templates. elif field == 'SUSI': xpos = [572,1143,1715,2387,1959,3531] ypos = [572,1143,1715,2387,1959,3531] elif field == 'EMMI': xpos = [146,292,438,584,730,876] ypos = [69,244,419,595,769,945] xetoile, yetoile = [], [] # appel la fonction qui definit les positions en pixels. position(xpos,ypos) ################################################################## # directory where are localised the .fits files (reduced images) that we use # for the SEXTRATION #prefix--> the path of the reduced images: prefix = string.split(line_mode)[0] # determination of the filter or the prefix you want name_sex_init = string.split(line_mode)[3] # the file liste_*.txt is the list of the reduced images to use file_txt = string.split(line_mode)[1] # erase the previous files created by SEXTRACTOR os.system("rm *.cat") # initialization of variables for smongo use. os.system("rm smongo.dat") file_smongo = open('smongo.dat', 'wr') # determination of the number of frames in the list nbe_frame = [] for line_frame in TextFile(prefix+file_txt, 'r'): nbe_frame.append(line_frame) nbe_fits = len(nbe_frame) liste_frames = open(prefix+file_txt,'r') # read each ligne of the liste file, so each name of fits files # lit chaque ligne dans la liste de fichiers : donc lit chaque nom de fihcier # .fits line = liste_frames.readline() # beginnning of the "boucle" under the number of frames in the list file xs, ys, as, bs, thetas = [],[],[],[],[] for i in range(nbe_fits): ############################################### # a cause des mauvaises images je mets des conditions sur les indices : # je supprime les points qui ne sont pas bons : j'ai trois possibilites # small, large_FE, large_SO et donc j'ai des i differents pour chauqe # ############################################### ####################################################################### # pour plus de faciliter, si vous ne voulez pas inclure une image, ne pas # la mettre dans la liste ! ####################################################################### # print '--> avant condition %d \n' % i # if name_sex_init =='small_J': # if (i ==0 or (i >= 7 and i <=12 ) or i == 15 or (i >= 19 and i <= 24) | (i >= 31 and i <= 35)): # print '---> toto %d' % i # continue # if name_sex_init == 'FE': # if ((i >= 4 & i <= 13) | i == 16 | ( i >= 16 & i<= 24) | (i>= 31 & i <= 36)): # print 'toto' # continue # if name_sex_init == 'SO': # if ( i == 6 | (i>= 8 & i <= 12) | (i >= 15 & i <= 18) | (i >= 20 & i <=24) | i == 28 | i == 29 | i == 32 | i == 34 | i == 35): # print 'toto' # continue # print '--> apres condition %d' % i ##################################################################### # open each file .fits file = open(prefix+string.strip(line),'r') commande = 'sex '+prefix+string.strip(line) # send to the system the command to use SEXTRACTOR print '' print ("******** file %s / %s *************" % ((i+1), nbe_fits)) print " --> Beginning of Sextractor" os.system(commande) # rename the output file of SEXTRACTOR (normaly, test.cat). Condition to # have the rigth numerotion of the files. if i < 9: name_sex = name_sex_init+"00%s.cat" % (i+1) elif i>=9: name_sex = name_sex_init+"0%s.cat" % (i+1) print '********** fin de Sextrator **********' print '' commande = 'mv test.cat '+name_sex os.system(commande) # go to pick in the output file of SEXTRACTOR the line that corresponds to # the reference star use to do the image quality and write it in the input # file for smongo file_sexcat = open(name_sex,'r') # read the informations in the sextractor catalog for line in TextFile(name_sex, 'r'): # go to read only the interesting rows # the if is only to pass thourgh the header (7 lines) # besoin de passer en float car sinon les conditions <= >= ne fonctionnent pas if (string.split(line)[0] != '#'): numero = string.split(line)[0] xs_tmp = float(string.split(line)[1]) ys_tmp = float(string.split(line)[2]) as_tmp = float(string.split(line)[3]) bs_tmp = float(string.split(line)[4]) thetas_tmp = float(string.split(line)[5]) test = 0 if (float(xetoile[i]) - 20. <= xs_tmp) & (xs_tmp <= float(xetoile[i]) + 20.) & (float(yetoile[i]) - 20. <= ys_tmp) & (ys_tmp <= float(yetoile[i]) + 20.) : test = 1 xs.append(xs_tmp) file_smongo.write(" %7.3f %7.3f %7.3f %7.3f %7.3f \n" %(xs_tmp, ys_tmp, as_tmp, bs_tmp, thetas_tmp)) if test != 1: if (float(xetoile[i]) - 50. <= xs_tmp) & (xs_tmp <= float(xetoile[i]) + 50.) & (float(yetoile[i]) - 50. <= ys_tmp) & (ys_tmp <= float(yetoile[i]) + 50.) : xs.append(xs_tmp) file_smongo.write(" %7.3f %7.3f %7.3f %7.3f %7.3f \n" %(xs_tmp, ys_tmp, as_tmp, bs_tmp, thetas_tmp)) line = liste_frames.readline() file_sexcat.close() file.close() liste_frames.close() file_smongo.close() os.system("rm *.cat") list_line = [] nbe_etoile = [] for line in TextFile('smongo.dat', 'r'): nbe_etoile.append(line) list_line.append(line) nbe = len(nbe_etoile) name_smongo2_prefix = 'ellip_'+name_sex_init name_smongo2 = name_smongo2_prefix+'.dat' file_smongo2 = open(name_smongo2,'w') file_smongo2.write("%3i\n" % nbe) file_smongo2.writelines(list_line) file_smongo2.close() # needed for the plot_mac.f program to plot the data. # smongo.dat is a genric name # juste pour que le programme plot_max puisse tracer les donnees contenues # dans smongo.dat et que ce soit un nom generique commande = 'cp '+name_smongo2+' smongo.dat' os.system(commande) # start of the program that plots the graphs # demarage du programme smongo qui trace les figures os.system("./plot_mac.x") commande = 'mv gr.ps '+name_smongo2_prefix+'.ps' os.system(commande) commande = 'rm ps*' os.system(commande)