def test_prepare_mass_params_with_m2(m2): """M2 does not change if given.""" params = {"m2": m2, "m_sini": 20, "m_sun": 0.8, "m_true": 80} assert params["m2"] == m2 params = prepare_mass_params(params) assert params["m2"] == m2
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
def test_prepare_mass_params_scales_m1_to_jup_mass(): params = {"m1": 1., "m2": 0} params = prepare_mass_params(params) assert params["m1"] == M_sun / M_jup
def test_prepare_mass_params_with_m_true_m2(): params = {"m_sini": 20, "m_sun": 0.8, "m_true": 80} params = prepare_mass_params(params, only_msini=False) assert params["m2"] == params["m_true"] assert params["msini_flag"] is False
def test_prepare_mass_params_with_k2_param(k2, expected): params = {"k2": k2, "m_sini": 20, "m_sun": 0.8, "m_true": 80} assert params.get("k2_flag") is None prepare_mass_params(params) assert params.get("k2_flag") == expected
def test_prepare_mass_params_with_no_m1(): params = {"m_sini": 20, "m_sun": 0.8, "m_true": 80} params = prepare_mass_params(params) assert params["m1"] == params["m_sun"] * M_sun / M_jup
def test_prepare_mass_params_sets_msini_flag(only_msini): params = {"m_sini": 20, "m_sun": 0.8, "m_true": 35} assert prepare_mass_params( params, only_msini=only_msini)["msini_flag"] == only_msini
def test_prepare_mass_params_sets_msini_flag(only_msini): params = {"m_sini": 20, "m_sun": 0.8, "m_true": 35} assert prepare_mass_params(params, only_msini=only_msini)["msini_flag"] == only_msini