def test_param_from_dict_and_to_dict_give_the_same_dict(): params = {"k1": 10, "eccentricity": 0.5, "period": 5, "mean_val": 4, "tau": 1, "omega": 1, "m1": 4, "m2": 6, "k2": 100, "name": "test", "ignore_mean": True} rv1 = RV.from_dict(params) rv1_params = rv1.to_dict() assert params == rv1_params assert params == rv1._params assert rv1_params == rv1._params rv2 = RV.from_dict(rv1_params) assert rv2 == rv1
def test_from_dict_works_properly(): params = {"k1": 10, "eccentricity": 0.5, "period": 5, "mean_val": 4, "tau": 1, "omega": 1, "m1": 4, "m2": 6} rv = RV.from_dict(params) assert rv._params.get("other_params") is None assert rv._params.get("m1") == 4 assert rv._params.get("m2") == 6
def test_initalize_rv_class_from_dict(): params = {"k1": 1, "period": 2, "tau": 5000, "omega": 1, "eccentricity": 0.5, "mean_val": 5} rv = RV.from_dict(params) assert rv.semi_amp == params["k1"] assert rv.period == params["period"] assert rv.ecc == params["eccentricity"] assert rv.tau == params["tau"] assert rv.gamma == params["mean_val"] assert rv.omega == params["omega"]
def main(params, mode="phase", obs_times=None, obs_list=None, date=None, cycle_fraction=1, phase_center=0, save_only=False): # obs_times=None, mode='phase', rv_diff=None # type: (Dict[str, Union[str, float]], str, List[str], str, str, bool) -> None r"""Radial velocity displays. Parameters ---------- params: str Filename for text file containing the rv parameters. Format of 'param = value\n'. mode: str Mode for script to use. Phase, time, future. obs_times: list of str Dates of observations added manually at command line of format YYYY-MM-DD. obs_list: str Filename for list which contains obs_times (YYY-MM-DD HH:MM:SS). date: str Reference date for some modes. Defaults=None) """ # Load in params and store as a dictionary parameters = parse_paramfile(params) parameters = prepare_mass_params(parameters, only_msini=True) parameters = check_core_parameters(parameters) # combine obs_times and obs_list and turn into jd. if obs_times: if (".txt" in obs_times) or (".dat" in obs_times): raise ValueError("Filename given instead of dates for obs_times.") obs_times = join_times(obs_times, obs_list) obs_jd = strtimes2jd(obs_times) test_jd = obs_jd[0] if isinstance(obs_jd, (list, tuple)) else obs_jd if ((str(parameters["tau"]).startswith("24") and not str(test_jd).startswith("24")) or (not (str(parameters["tau"]).startswith("24")) and str(test_jd).startswith("24"))): raise ValueError( "Mismatch between Tau parameter '{0}' and times used '{1}'.". format(parameters["tau"], obs_jd)) date_split = JulianDate.now().jd if date is None else JulianDate.from_str( date).jd # Slit past and future obs future_obs = [obs for obs in obs_jd if obs > date_split] past_obs = [obs for obs in obs_jd if obs <= date_split] host_orbit = RV.from_dict(parameters) companion_orbit = host_orbit.create_companion() if mode == "phase": fig = binary_phase_curve(host_orbit, companion_orbit, t_past=past_obs, t_future=future_obs, cycle_fraction=cycle_fraction, phase_center=phase_center) elif mode == "time": fig = binary_time_curve(host_orbit, companion_orbit, t_past=past_obs, start_day=date_split, t_future=future_obs, cycle_fraction=cycle_fraction) else: raise NotImplementedError("Other modes are not Implemented yet.") if not save_only: fig.show() return fig
def main(params, mode="phase", obs_times=None, obs_list=None, date=None, cycle_fraction=1, phase_center=0, save_only=False): # obs_times=None, mode='phase', rv_diff=None # type: (Dict[str, Union[str, float]], str, List[str], str, str, bool) -> None r"""Radial velocity displays. Parameters ---------- params: str Filename for text file containing the rv parameters. Format of 'param = value\n'. mode: str Mode for script to use. Phase, time, future. obs_times: list of str Dates of observations added manually at command line of format YYYY-MM-DD. obs_list: str Filename for list which contains obs_times (YYY-MM-DD HH:MM:SS). date: str Reference date for some modes. Defaults=None) """ # Load in params and store as a dictionary parameters = parse_paramfile(params) parameters = prepare_mass_params(parameters, only_msini=True) parameters = check_core_parameters(parameters) # combine obs_times and obs_list and turn into jd. if obs_times: if (".txt" in obs_times) or (".dat" in obs_times): raise ValueError("Filename given instead of dates for obs_times.") obs_times = join_times(obs_times, obs_list) obs_jd = strtimes2jd(obs_times) test_jd = obs_jd[0] if isinstance(obs_jd, (list, tuple)) else obs_jd if ((str(parameters["tau"]).startswith("24") and not str(test_jd).startswith("24")) or (not(str(parameters["tau"]).startswith("24")) and str(test_jd).startswith("24"))): raise ValueError("Mismatch between Tau parameter '{0}' and times used '{1}'.".format(parameters["tau"], obs_jd)) date_split = JulianDate.now().jd if date is None else JulianDate.from_str(date).jd # Slit past and future obs future_obs = [obs for obs in obs_jd if obs > date_split] past_obs = [obs for obs in obs_jd if obs <= date_split] host_orbit = RV.from_dict(parameters) companion_orbit = host_orbit.create_companion() if mode == "phase": fig = binary_phase_curve(host_orbit, companion_orbit, t_past=past_obs, t_future=future_obs, cycle_fraction=cycle_fraction, phase_center=phase_center) elif mode == "time": fig = binary_time_curve(host_orbit, companion_orbit, t_past=past_obs, start_day=date_split, t_future=future_obs, cycle_fraction=cycle_fraction) else: raise NotImplementedError("Other modes are not Implemented yet.") if not save_only: fig.show() return fig