def test_full_phase(center, npoints): params = {"semi_amp": 1, "period": 15, "tau": 2400000, "omega": 0, "ecc": 0.1} rv1 = RV(**params).rv_full_phase(center, npoints) rv2 = RV(**params).rv_full_phase(center + 1, npoints) assert len(rv1) == npoints assert np.allclose(rv1, rv2) assert np.allclose(rv1[0], rv1[-1])
def test_set_ignore_mean(): rv = RV() assert rv.ignore_mean is False rv.ignore_mean = True assert rv.ignore_mean is True rv.ignore_mean = False assert rv.ignore_mean is False
def test_create_companion(): host = RV(semi_amp=1, m1=10, m2=5) companion = host.create_companion() assert companion.semi_amp == -host.semi_amp * host._params["m1"] / host._params["m2"] assert companion._params["k2"] == host._params["k1"] assert companion._params["k1"] == companion.semi_amp
def test_create_companion_with_k2(k2): host = RV(semi_amp=1, m1=10, m2=5, k2=k2) companion = host.create_companion() assert companion.semi_amp == k2 # does not depend on m1 and m2 if k2 given assert companion._params["k2"] == host._params["k1"] assert companion._params["k1"] == companion.semi_amp
def test_double_create_companion_returns_host(): host = RV(semi_amp=1, m1=10, m2=5) companion = host.create_companion() host_2 = companion.create_companion() assert host_2.semi_amp == host.semi_amp assert host == host_2 assert host != companion
def test_double_create_companion_with_ratio_returns_host(mass_ratio): host = RV(semi_amp=1, m1=10, m2=5) print("host parsm", host._params) companion = host.create_companion(mass_ratio=mass_ratio) print("comp params", companion._params) host_2 = companion.create_companion(1.0 / mass_ratio) print("host_2 params", host_2._params) assert host_2.semi_amp == host.semi_amp assert host == host_2 assert host != companion
def test_create_companion_with_mass_ratio(semi_amp, mass_ratio): host = RV(semi_amp=1, k1=1, m1=10, m2=5) print("host params", host._params) companion = host.create_companion(mass_ratio=mass_ratio) print("companion params", companion._params) assert companion.semi_amp == (- host.semi_amp * mass_ratio) assert host.period == companion.period assert host.gamma == companion.gamma assert host.ecc == companion.ecc assert host.tau == companion.tau assert companion._params["k2"] == host._params["k1"] assert companion._params["k1"] == companion.semi_amp
def test_RV_to_dict_updates_parameters_in_params(): rv = RV(semi_amp=1.0, period=3, tau=4, omega=5, ecc=0.5, mean_val=8, ignore_mean=True) assert rv.ignore_mean == True assert rv._params["ignore_mean"] == True assert rv.semi_amp == 1.0 # _params not updated (yet) rv.semi_amp = 2 rv.ignore_mean = False assert rv._params["k1"] == 1 assert rv._params["ignore_mean"] == True assert rv.ignore_mean == False # RV.to_dict() updates _params param_dict = rv.to_dict() assert param_dict["ignore_mean"] == False assert rv._params["ignore_mean"] == False assert rv.semi_amp == 2 assert param_dict["k1"] == 2 assert rv._params["k1"] == 2
def test_rv_object_instance_of_rv_class(): rv = RV() assert isinstance(rv, RV)
def test_rv_class_max_amp_on_elipse(semi_amp, period, ecc, tau, gamma, omega, expected_amp): rv = RV(semi_amp, period, ecc, tau, gamma, omega) assert rv.max_amp() <= abs(semi_amp * (1 + ecc)) # omega = 0, 2pi etc assert rv.max_amp() == expected_amp
def test_rv_class_max_amp_on_circle(semi_amp, period, tau, gamma, omega): ecc = 0 rv = RV(semi_amp, period, ecc, tau, gamma, omega) assert rv.max_amp() == semi_amp
def test_RV_can_handle_ignore_mean_as_input(ignore): rv = RV(ignore_mean=ignore) assert rv.ignore_mean == ignore assert rv._params["ignore_mean"] == ignore assert "ignore_mean" in rv.to_dict().keys()
def test_companion_without_mass_gives_errors(): rv = RV() with pytest.raises(ValueError): # Needs mass parameters rv.create_companion()
def test__repr__(): rv = RV(semi_amp=1.0, period=1, omega=35, k2=7, m1=0.81, tau=3561.51) assert isinstance(rv.__repr__(), str) assert rv.__repr__() == "RV(semi_amp=1.0, period=1, ecc=0.0, tau=3561.51, omega=35, gamma=0.0, k2=7, m1=0.81)" assert RV().__repr__() == "RV(semi_amp=0.0, period=0.0, ecc=0.0, tau=0.0, omega=0.0, gamma=0.0)"
def test_companion_label_with_no_flags(): assert generate_companion_label(RV()) == "M2 Companion"
def test_generate_companion_label(msini_flag, k2_flag, ratio_flag, expected): orbit = RV(msini_flag=msini_flag, k2_flag=k2_flag, ratio_flag=ratio_flag) assert generate_companion_label(orbit) == expected