class TestD_phase_d_toa(unittest.TestCase): @classmethod def setUpClass(self): os.chdir(datadir) self.parfileB1855 = "B1855+09_polycos.par" self.timB1855 = "B1855_polyco.tim" self.toasB1855 = toa.get_TOAs(self.timB1855, ephem="DE405", planets=False, include_bipm=False) self.modelB1855 = mb.get_model(self.parfileB1855) # Read tempo style polycos. self.plc = Polycos() self.plc.read_polyco_file("B1855_polyco.dat", "tempo") def testD_phase_d_toa(self): pint_d_phase_d_toa = self.modelB1855.d_phase_d_toa(self.toasB1855) mjd = np.array([ np.longdouble(t.jd1 - DJM0) + np.longdouble(t.jd2) for t in self.toasB1855.table["mjd"] ]) tempo_d_phase_d_toa = self.plc.eval_spin_freq(mjd) diff = pint_d_phase_d_toa.value - tempo_d_phase_d_toa relative_diff = diff / tempo_d_phase_d_toa assert np.all( np.abs(relative_diff) < 1e-7), "d_phase_d_toa test failed."
def setUpClass(self): os.chdir(datadir) self.parfileB1855 = "B1855+09_polycos.par" self.timB1855 = "B1855_polyco.tim" self.toasB1855 = toa.get_TOAs(self.timB1855, ephem="DE405", planets=False, include_bipm=False) self.modelB1855 = mb.get_model(self.parfileB1855) # Read tempo style polycos. self.plc = Polycos() self.plc.read_polyco_file("B1855_polyco.dat", "tempo")
def setUpClass(self): self.parfileB1855 = 'B1855+09_polycos.par' self.timB1855 = 'B1855_polyco.tim' self.toasB1855 = toa.get_TOAs(self.timB1855, ephem="DE405", planets=False, include_bipm=False) self.modelB1855 = mb.get_model(self.parfileB1855) # Read tempo style polycos. self.plc = Polycos() self.plc.read_polyco_file('B1855_polyco.dat', 'tempo')
class TestD_phase_d_toa(unittest.TestCase): @classmethod def setUpClass(self): self.parfileB1855 = 'B1855+09_polycos.par' self.timB1855 = 'B1855_polyco.tim' self.toasB1855 = toa.get_TOAs(self.timB1855, ephem="DE405", planets=False, include_bipm=False) self.modelB1855 = mb.get_model(self.parfileB1855) # Read tempo style polycos. self.plc = Polycos() self.plc.read_polyco_file('B1855_polyco.dat', 'tempo') def TestD_phase_d_toa(self): pint_d_phase_d_toa = self.modelB1855.d_phase_d_toa(self.toasB1855) mjd = np.array([np.longdouble(t.jd1 - ut.DJM0)+np.longdouble(t.jd2) for t in self.toasB1855.table['mjd']]) tempo_d_phase_d_toa = self.plc.eval_spin_freq(mjd) diff = pint_d_phase_d_toa.value - tempo_d_phase_d_toa relative_diff = diff/tempo_d_phase_d_toa assert np.all(relative_diff < 1e-8), 'd_phae_d_toa test filed.'
def test_find_entry(polyco_file): """Check polycos find the correct entry and out of bounds throws an error.""" p = Polycos() p.read_polyco_file(polyco_file) assert np.all(p.find_entry(55000) == 0) assert np.all(p.find_entry(55001) == 4) ts_2 = np.linspace(55000.3125, 55000.52, 1000) assert np.all(p.find_entry(ts_2) == 2) for t in [54999.8, 55000.8, 55001.8, np.linspace(54999, 55002, 1000)]: with pytest.raises(ValueError): _ = p.find_entry(t)
def test_read_write_round_trip(tmpdir, polyco_file): with open(polyco_file, "r") as f: p1 = f.read() output_polyco = tmpdir / "B1855_polyco_round_trip.dat" p = Polycos() p.read_polyco_file(polyco_file) p.write_polyco_file(output_polyco) with open(output_polyco, "r") as f: p2 = f.read() assert p1 == p2
def test_generate_polycos(tmpdir, par_file, obs, obsfreq, nspan, ncoeff): output_polyco = tmpdir / "B1855_polyco_round_trip_from_par.dat" mjd_start, mjd_end = 55000.0, 55001.0 model = get_model(str(par_file)) p = Polycos() p.generate_polycos(model, mjd_start, mjd_end, obs, nspan, ncoeff, obsfreq) p.write_polyco_file(output_polyco) q = Polycos() q.read_polyco_file(output_polyco) mjds = np.linspace(mjd_start, mjd_end, 51) t = toa.get_TOAs_list( [toa.TOA(mjd, obs=obs, freq=obsfreq) for mjd in mjds], ephem=model.EPHEM.value) ph1 = p.eval_abs_phase(mjds) ph2 = q.eval_abs_phase(mjds) ph3 = model.phase(t, abs_phase=True) assert np.allclose(ph1.int.value[0], ph3.int.value[0]) assert np.allclose(ph1.frac.value[0], ph3.frac.value[0]) assert np.allclose(ph2.int.value[0], ph3.int.value[0]) assert np.allclose(ph2.frac.value[0], ph3.frac.value[0])
def test_generate_polycos_maxha_error(par_file): model = get_model(str(par_file)) p = Polycos() with pytest.raises(ValueError): p.generate_polycos(model, 55000, 55002, "ao", 144, 12, 400.0, maxha=8)
def test_polycos_basic(polyco_file): """Just run various features to make sure none of them throw errors. Except the ones that should. """ p = Polycos() p.read_polyco_file(polyco_file) table = p.polycoTable entry = table["entry"][0] print(entry) for mjd in [55000.0, np.array([55000.0, 55001.0])]: p.eval_spin_freq(mjd) p.eval_abs_phase(mjd) p.eval_phase(mjd) p.find_entry(mjd)