コード例 #1
0
ファイル: plot_resids.py プロジェクト: rferdman/pypsr
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()
コード例 #2
0
ファイル: show_resid_info.py プロジェクト: rferdman/pypsr
def main():

     progname = 'show_resid_info.py'
     args = get_opt(progname)

# 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)


     # For now worry about ntoa in calculating chi2's but will implement 
     # par file reader to determine the number of DOF
     # ( = n_toa + n_free_param + 1 for fit for phase)
     if(args.parfile==None):
         n_param = 0
     else:
         if(args.tempo2):
             ffmt='tempo2'
         else:
             ffmt='tempo1'
         param_name, para_val, param_fit = read_par(args.parfile, file_format=ffmt, return_tuple=True)
         n_param = param_fit.count(True)
#         param_data = read_par(args.parfile, file_format=ffmt)



     # Now get information from residuals
     rinfo = get_resid_info(resid_data, nparam=n_param)
               
     # Now print out results, to stdout for now:
     print ''
     print 'Residual file:  ', args.resfile
     print 'Par file:       ', args.parfile
     print 'Number of TOAs: ', rinfo['ntoa']
     print 'Number of parameters:  ', rinfo['nparam'] 
     print 'Number of DOF:         ', rinfo['ndof']
     print '\n'
     
     print 'Info        Total   Avg weight  Number     Chi^2    Adjusted chi^2     rms         rms        MJD range     Years   Centre'
     print '            weight   per TOA    of TOAs   per TOA     (per DOF)     unweighted   weighted                            freq '
     print ''
     
     for i_info in range(len(resid_data['info_val'])):
         print '{0:8}    {1:7.5f}  {2:7.5f}  {3:7d}  {4:10.4f}  {5:10.4f}     {6:10.4f}  {7:10.4f}    {8:5d} - {9:5d}  {10:5.2f}    {11:6.1f}'.format(
             resid_data['info_val'][i_info], rinfo['normwgt'][i_info], 
             rinfo['avgwgt'][i_info], rinfo['npts'][i_info], 
             rinfo['rchi2'][i_info], rinfo['rchi2x'][i_info], 
             rinfo['resrms'][i_info], rinfo['resrmsw'][i_info], 
             int(rinfo['mjdstart'][i_info]), int(rinfo['mjdend'][i_info]), 
             (rinfo['mjdend'][i_info]-rinfo['mjdstart'][i_info])/365.25,
             rinfo['cfreq'][i_info] )

     print ''
     print '{0:8}    {1:7.5f}  {2:7.5f}  {3:7d}  {4:10.4f}  {5:10.4f}     {6:10.4f}  {7:10.4f}    {8:5d} - {9:5d}  {10:5.2f}    {11:6.1f}'.format(
         'Total', rinfo['sum_normwgt'], 
         rinfo['sum_avgwgt'], rinfo['sum_npts'], 
         rinfo['sum_rchi2'], rinfo['sum_rchi2x'], 
         rinfo['sum_resrms'], rinfo['sum_resrmsw'], 
         int(rinfo['sum_mjdstart']), int(rinfo['sum_mjdend']), 
         (rinfo['sum_mjdend']-rinfo['sum_mjdstart'])/365.25,
         rinfo['sum_cfreq'] )
コード例 #3
0
ファイル: plot_shapiro_resids.py プロジェクト: rferdman/pypsr
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()