def get_scenario_start_index(base_times, scenario_start_time):
    """
    Returns the index of the closest time step that is at, or before the scenario start time.
    """
    indices_after_start_index = [
        idx for idx, time in enumerate(base_times) if time > scenario_start_time
    ]
    if not indices_after_start_index:
        raise ValueError(
            f"Scenario start time {scenario_start_time} is set after the baseline time range."
        )

    index_after_start_index = min(indices_after_start_index)
    start_index = max([0, index_after_start_index - 1])
    return start_index