def test_fitter_respects_pulse_numbers(fitter, model, fake_toas): t = fake_toas delta_f = (1 / (t.last_MJD - t.first_MJD)).to(u.Hz) # Unchanged model, fitting should be trivial f_0 = fitter(t, model, track_mode="use_pulse_numbers") f_0.fit_toas() assert abs(f_0.model.F0.quantity - model.F0.quantity) < 0.01 * delta_f m_2 = deepcopy(model) m_2.F0.quantity += 2 * delta_f m_2.free_params = ["F0"] # Check fitter with and without tracking with pytest.raises(ValueError): fitter(t, m_2, track_mode="capybara") f_1 = fitter(t, m_2, track_mode="nearest") try: f_1.fit_toas() assert abs(f_1.model.F0.quantity - model.F0.quantity) > 0.1 * delta_f except ValueError: # convergence fails for Downhill fitters pass f_2 = fitter(t, m_2, track_mode="use_pulse_numbers") f_2.fit_toas() assert abs(f_2.model.F0.quantity - model.F0.quantity) < 0.01 * delta_f
def test_random_models(fitter): # Get model and TOAs m, t = get_model_and_toas(os.path.join(datadir, "NGC6440E.par"), os.path.join(datadir, "NGC6440E.tim")) f = fitter(toas=t, model=m) # Do a 4-parameter fit f.model.free_params = ("F0", "F1", "RAJ", "DECJ") f.fit_toas() # this contains TOAs up through 54200 # make new ones starting there tnew = simulation.make_fake_toas_uniform(54200, 59000, 59000 - 54200, f.model) dphase, mrand = simulation.calculate_random_models(f, tnew, Nmodels=30) # this is a bit stochastic, but I see typically < 0.14 cycles # for the uncertainty at 59000 assert np.all(dphase.std(axis=0) < 0.2) # redo it with only F0 free dphase_F, mrand_F = simulation.calculate_random_models(f, tnew, Nmodels=100, params=["F0"]) # this should be less than the fully free version assert dphase_F.std(axis=0).max() < dphase.std(axis=0).max()
def test_random_models_wb(fitter): model = get_model( os.path.join(datadir, "J1614-2230_NANOGrav_12yv3.wb.gls.par")) toas = get_TOAs( os.path.join(datadir, "J1614-2230_NANOGrav_12yv3.wb.tim"), ephem="DE436", bipm_version="BIPM2015", ) f = fitter(toas, model) # Do a 4-parameter fit f.model.free_params = ("F0", "F1", "ELONG", "ELAT") f.fit_toas() tnew = simulation.make_fake_toas_uniform(54200, 59000, (59000 - 54200) // 10, f.model) dphase, mrand = simulation.calculate_random_models(f, tnew, Nmodels=30) # this is a bit stochastic, but I see typically < 1e-4 cycles for this # for the uncertainty at 59000 assert np.all(dphase.std(axis=0) < 1e-4)