def main(): progname = 'plot_resids.py' args = get_opt(progname) # Input print_resids-format data file will be first argument. # (command-line options to come later) # resid_file = argv[1] # First, read in residuals data file, and assign each column to a separate # numpy array resid_data = read_resid(args.resfile, tempo2=args.tempo2, info_file=args.infofile, info_flag=args.infoflag) # print res_data['mjd'] # if (len(argv) > 2): # meaning 2nd argument is the desired output plot file name # plot_file = argv[2] # else: print "OUTFILE = ", args.outfile if(args.outfile == None): fig_size = (16, 6) else: fig_size = (14, 5) plot_file = args.outfile # If --info is not used and this is a tempo2 input file, then make info_plot==None if(args.tempo2): if(args.info==None): resid_data['info']=None resid_data['info_val']=None resid_data['info_instr']=None elif(args.info==[]): # gave flag but no arguments args.info = resid_data['info_val'] else: if(args.info==[]): args.info=None print 'resoffset = ', args.resoffset plot_resid(resid_data, info_plot=args.info, binsize=args.binsize, canvassize=fig_size, symsize=2.0, xunits=args.xunits, yunits=args.yunits, xlim=args.xlim, ylim=args.ylim, gridlines=[0.], resoffset=args.resoffset, colour=args.colour) if(args.outfile): plt.savefig(plot_file) else: plt.show()
def main(): progname = 'plot_shapiro_resids.py' args = get_opt(progname) # First, read in par file: f_par = open(args.parfile, 'r') par_data = [par_line.split() for par_line in f_par.readlines()] f_par.close() if(args.tempo2): resid_file = tempo2_resid_file infofile = None else: resid_file = tempo_resid_file infofile = tempo_info_file # Will run tempo/tempo2 3 times on best fit profile: # (1) Full solution with par file as is: if(args.tempo2): print 'par file = ', args.parfile tempo_command = 'tempo2 -output print_resids -f '+args.parfile+' '+\ args.timfile+' -file resid_output_format.dat '+ \ '-outfile '+tempo2_resid_file print 'tempo_command: ', tempo_command cmd_out = exec_cmd(tempo_command) print cmd_out else: tempo_command = 'tempo -f '+args.parfile+' '+args.timfile cmd_out = exec_cmd(tempo_command) exec_cmd('extract') # Read in residuals resid_data_allfit = read_resid(resid_file, tempo2=args.tempo2, info_file=infofile, info_flag=args.infoflag) if(args.tempo2): if(args.info==None): resid_data_allfit['info']=None resid_data_allfit['info_val']=None resid_data_allfit['info_instr']=None elif(args.info==[]): # gave flag but no arguments args.info = resid_data_allfit['info_val'] # (2) Get rid of SINI and M2 lines and fit everything else # Check as we go that SINI and M2 are in file temp_par_file = 'temp.par' f_temp_par = open(temp_par_file, 'w') for par_line in par_data: if((par_line[0] != 'SINI') & (par_line[0] != 'M2')): f_temp_par.write(' '.join(par_line)+'\n') f_temp_par.close() if(args.tempo2): tempo_command = 'tempo2 -output print_resids -f '+temp_par_file+' '+\ args.timfile+' -file resid_output_format.dat '+ \ '-outfile '+tempo2_resid_file cmd_out = exec_cmd(tempo_command) else: tempo_command = 'tempo -f '+temp_par_file+' '+args.timfile cmd_out = exec_cmd(tempo_command) exec_cmd('extract') # Read in residuals resid_data_orbfit = read_resid(resid_file, tempo2=args.tempo2, info_file=infofile, info_flag=args.infoflag) if(args.tempo2): if(args.info==None): resid_data_orbfit['info']=None resid_data_orbfit['info_val']=None resid_data_orbfit['info_instr']=None elif(args.info==[]): # gave flag but no arguments args.info = resid_data_orbfit['info_val'] # (3) Sam as (2), but turn off all fitting f_temp_par = open(temp_par_file, 'w') for par_line in par_data: if(len(par_line) > 2): if(par_line[2]=='1'): par_line[2]='0' if(par_line[0]=='JUMP'): if(par_line[4]=='1'): par_line[4]='0' if((par_line[0] != 'SINI') & (par_line[0] != 'M2')): f_temp_par.write(' '.join(par_line)+'\n') f_temp_par.close() if(args.tempo2): tempo_command = 'tempo2 -output print_resids -f '+temp_par_file+' '+ \ args.timfile+' -file resid_output_format.dat '+ \ '-outfile '+tempo2_resid_file exec_cmd(tempo_command) else: tempo_command = 'tempo -f '+temp_par_file+' '+args.timfile cmd_out = exec_cmd(tempo_command) exec_cmd('extract') # Read in residuals resid_data_nofit = read_resid(resid_file, tempo2=args.tempo2, info_file=infofile, info_flag=args.infoflag) if(args.tempo2): if(args.info==None): resid_data_nofit['info']=None resid_data_nofit['info_val']=None resid_data_nofit['info_instr']=None elif(args.info==[]): # gave flag but no arguments args.info = resid_data_nofit['info_val'] # First, read in residuals data file, and assign each column to a separate # numpy array # print res_data['mjd'] # if (len(argv) > 2): # meaning 2nd argument is the desired output plot file name # plot_file = argv[2] # else: print "OUTFILE = ", args.outfile if(args.outfile == None): fig_size = (16, 18) else: fig_size = (14, 15) plot_file = args.outfile resid_data_list = [resid_data_allfit, resid_data_orbfit, resid_data_nofit] # resid_data_list = resid_data_allfit print 'xlim = ', args.xlim print 'ylim = ', args.ylim plot_resid(resid_data_list, info_plot=args.info, binsize=args.binsize, canvassize=fig_size, symsize=2.0, xunits='orbphase', yunits=args.yunits, xticks=[True, False, False], xlabel=[True, False, False], ylabel=[False, True, False], xlim=args.xlim, ylim=args.ylim, gridlines=[0.], axislabelsize=32, ticklabelsize=32) if(args.outfile): plt.savefig(plot_file) else: plt.show()