コード例 #1
0
ファイル: call.py プロジェクト: jkehm/REISE.jl
    def __init__(self, start_date, end_date, interval, input_dir):
        """Constructor."""
        # extract time limits from 'demand.csv'
        with open(os.path.join(input_dir, "demand.csv")) as profile:
            min_ts, max_ts, freq = extract_date_limits(profile)

        dates = pd.date_range(start=min_ts, end=max_ts, freq=freq)

        start_ts = validate_time_format(start_date)
        end_ts = validate_time_format(end_date, end_date=True)

        # make sure the dates are within the time frame we have data for
        validate_time_range(start_ts, min_ts, max_ts)
        validate_time_range(end_ts, min_ts, max_ts)

        if start_ts > end_ts:
            raise InvalidDateArgument(
                f"The start date ({start_ts}) cannot be after the end date ({end_ts})."
            )

        # Julia starts at 1
        start_index = dates.get_loc(start_ts) + 1
        end_index = dates.get_loc(end_ts) + 1

        # Calculate number of intervals
        ts_range = end_index - start_index + 1
        if ts_range % interval > 0:
            raise InvalidInterval(
                "This interval does not evenly divide the given date range.")
        self.start_index = start_index
        self.interval = interval
        self.n_interval = int(ts_range / interval)
        self.input_dir = input_dir
        print("Validation complete!")
コード例 #2
0
def _update_outputs_labels(outputs, start_date, end_date, freq, matfile):
    """Updates outputs with the correct date index and column names

    :param dict outputs: dictionary of pandas.DataFrames outputted by extract_data
    :param str start_date: start date used for the simulation
    :param str end_date: end date used for the simulation
    :param str freq: the frequency of timestamps in the input profiles as a pandas frequency alias
    :param dict matfile: dictionary representing the converted input.mat file outputted by REISE.jl
    """
    # Set index of data frame
    start_ts = validate_time_format(start_date)
    end_ts = validate_time_format(end_date, end_date=True)

    date_range = pd.date_range(start_ts, end_ts, freq=freq)

    outputs_id = _get_outputs_from_converted(matfile)

    for k in outputs:
        outputs[k].index = date_range
        outputs[k].index.name = "UTC"

        outputs[k].columns = outputs_id[k]
コード例 #3
0
def test_validate_time_format_end_date():
    date = "2016-01-01"
    assert validate_time_format(
        date, end_date=True) == pd.Timestamp("2016-01-01 23:00:00")
コード例 #4
0
def test_validate_time_format_sec():
    date = "2016-01-01 12:30:30"
    assert validate_time_format(date) == pd.Timestamp("2016-01-01 12:30:30")
コード例 #5
0
def test_validate_time_format_hours():
    date = "2016-01-01 12"
    assert validate_time_format(date) == pd.Timestamp("2016-01-01 12:00:00")
コード例 #6
0
def test_validate_time_format_day():
    date = "2016-01-01"
    assert validate_time_format(date) == pd.Timestamp("2016-01-01 00:00:00")
コード例 #7
0
def test_validate_time_format_type():
    date = "2016/01/01"
    with pytest.raises(InvalidDateArgument):
        validate_time_format(date)