def test_julian_date_to_and_frm_str_starting_from_str(input, format):
    assert JulianDate.from_str(input, format).to_str(format) == input
Exemple #2
0
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_JulianDate_from_str_to_datetime(datestr, dtime):
    jd = JulianDate.from_str(datestr)
    assert abs(jd.to_datetime() -
               datetime.datetime(*dtime)) < datetime.timedelta(seconds=1)
def test_julian_date_to_and_frm_str_starting_from_jd(input):
    assert JulianDate.from_str(JulianDate(input).to_str()).jd == input
def test_JulianDate_from_str(date, expected):
    jd = JulianDate.from_str(date)
    assert np.allclose(jd.jd, expected)
    assert np.allclose(jd.jd, ephem.julian_date(date))
def test_julian_date_to_and_frm_str_starting_from_str(input, format):
    assert JulianDate.from_str(input, format).to_str(format) == input
def test_julian_date_to_and_frm_str_starting_from_jd(input):
    assert JulianDate.from_str(JulianDate(input).to_str()).jd == input
def test_JulianDate_from_str_to_datetime(datestr, dtime):
    jd = JulianDate.from_str(datestr)
    assert abs(jd.to_datetime() - datetime.datetime(*dtime)) < datetime.timedelta(seconds=1)
def test_JulianDate_from_str(date, expected):
    jd = JulianDate.from_str(date)
    assert np.allclose(jd.jd, expected)
    assert np.allclose(jd.jd, ephem.julian_date(date))