def test_fitter(): # Get model m = tm.get_model(os.path.join(datadir,'NGC6440E.par')) # Get TOAs t = toa.TOAs(os.path.join(datadir,'NGC6440E.tim')) t.apply_clock_corrections(include_bipm=False) t.compute_TDBs() try: planet_ephems = m.PLANET_SHAPIRO.value except AttributeError: planet_ephems = False t.compute_posvels(planets=planet_ephems) f=fitter.WlsFitter(toas=t,model=m) # Print initial chi2 print('chi^2 is initially %0.2f' % f.resids.chi2) # Plot initial residuals xt = f.resids.toas.get_mjds().value yerr=t.get_errors()*1e-6 plt.close() p1=plt.errorbar(xt, f.resids.toas.get_mjds().value,f.resids.time_resids.value,yerr.value,fmt='bo'); # Do a 4-parameter fit f.set_fitparams('F0','F1','RA','DEC') f.fit_toas() print('chi^2 is %0.2f after 4-param fit' % f.resids.chi2) p2=plt.errorbar(xt,f.resids.time_resids.value,yerr.value,fmt='go'); # Now perturb F1 and fit only that. This doesn't work, though tempo2 easily fits # it. f.model.F1.value=1.1*f.model.F1.value f.fit_toas() print('chi^2 is %0.2f after perturbing F1' % f.resids.chi2) p3=plt.errorbar(xt,f.resids.time_resids.value,yerr.value,fmt='ms'); f.set_fitparams('F1') f.fit_toas() print('chi^2 is %0.2f after fitting just F1 with default method="Powell"' % f.resids.chi2) p4=plt.errorbar(xt,f.resids.time_resids.value,yerr.value,fmt='k^');
# Get model m = tm.get_model(os.path.join(datadir, 'NGC6440E.par')) # Get TOAs t = toa.TOAs(os.path.join(datadir, 'NGC6440E.tim')) t.apply_clock_corrections(include_bipm=False) t.compute_TDBs() try: planet_ephems = m.PLANET_SHAPIRO.value except AttributeError: planet_ephems = False t.compute_posvels(planets=planet_ephems) f = fitter.WlsFitter(toas=t, model=m) # Print initial chi2 print('chi^2 is initially %0.2f' % f.resids.chi2) # Plot initial residuals xt = f.resids.toas.get_mjds().value yerr = t.get_errors() * 1e-6 plt.close() p1 = plt.errorbar(xt, f.resids.toas.get_mjds().value, f.resids.time_resids.value, yerr.value, fmt='bo') # Do a 4-parameter fit
# continue if b_name.endswith('+12'): par = b_name + '_ori.par' tempo_par = b_name + '_ptb.par' else: par = b_name + '.gls_ori.par' tempo_par = b_name + '.gls_ptb.par' tim = b_name + '.tim' m = mb.get_model(par) result_par = m.PSR.value + '.par' res[b_name] = {} cmd = subprocess.list2cmdline(["grep", "'EPHEM'", par]) out = subprocess.check_output(cmd, shell=True) out = out.split() t = toa.get_TOAs(tim, ephem=out[1].lower()) f = fitter.WlsFitter(t, m) ori_resd = f.resids.calc_time_resids(False) ori_rms = ori_resd.std().to('us').value ori_red_chi = f.resids.chi2_reduced pp_row = [] pt_row = [] pt2_row = [] for p, v in zip(per_step.keys(), per_step.values()): #for p,v in zip(['E',], [per_step['E'],]): pn = f.model.match_param_aliases(p) # if pn != 'ECC': # continue if pn != '': print pn p_init = getattr(f.model_init, pn)