Exemple #1
0
def test_run_persistence_fx_too_short(session, site_metadata, obs_5min_begin):
    forecast = default_forecast(site_metadata,
                                issue_time_of_day=dt.time(hour=23),
                                lead_time_to_start=pd.Timedelta('1h'),
                                interval_length=pd.Timedelta('1min'),
                                run_length=pd.Timedelta('3min'),
                                interval_label='beginning')
    issue_time = pd.Timestamp('20190423T2300Z')
    run_time = pd.Timestamp('20190422T1945Z')
    with pytest.raises(ValueError) as excinfo:
        main.run_persistence(session, obs_5min_begin, forecast, run_time,
                             issue_time)
    assert 'requires observation.interval_length' in str(excinfo.value)
Exemple #2
0
def test_run_persistence_incompatible_instant_fx(session, site_metadata,
                                                 obs_5min_begin):
    forecast = default_forecast(site_metadata,
                                issue_time_of_day=dt.time(hour=23),
                                lead_time_to_start=pd.Timedelta('1h'),
                                interval_length=pd.Timedelta('1h'),
                                run_length=pd.Timedelta('1h'),
                                interval_label='instantaneous')
    issue_time = pd.Timestamp('20190423T2300Z')
    run_time = pd.Timestamp('20190422T1945Z')
    with pytest.raises(ValueError) as excinfo:
        main.run_persistence(session, obs_5min_begin, forecast, run_time,
                             issue_time)
    assert 'instantaneous forecast' in str(excinfo.value).lower()
Exemple #3
0
def test_run_persistence_interval_not_midnight_to_midnight(
        session, site_metadata, obs_5min_begin):
    # not midnight to midnight
    forecast = default_forecast(site_metadata,
                                issue_time_of_day=dt.time(hour=22),
                                lead_time_to_start=pd.Timedelta('1h'),
                                interval_length=pd.Timedelta('1h'),
                                run_length=pd.Timedelta('24h'),
                                interval_label='beginning')
    issue_time = pd.Timestamp('20190423T2200Z')
    run_time = pd.Timestamp('20190422T1945Z')
    with pytest.raises(ValueError) as excinfo:
        main.run_persistence(session, obs_5min_begin, forecast, run_time,
                             issue_time)
    assert 'midnight to midnight' in str(excinfo.value)
Exemple #4
0
def test_run_persistence_interval_index(session, site_metadata,
                                        obs_5min_begin):
    # index=True not supported for day ahead
    forecast = default_forecast(
        site_metadata,
        issue_time_of_day=dt.time(hour=23),
        lead_time_to_start=pd.Timedelta('1h'),
        interval_length=pd.Timedelta('1h'),
        run_length=pd.Timedelta('24h'),
        interval_label='beginning')
    issue_time = pd.Timestamp('20190423T2300Z')
    run_time = pd.Timestamp('20190422T1945Z')
    with pytest.raises(ValueError) as excinfo:
        main.run_persistence(session, obs_5min_begin, forecast, run_time,
                             issue_time, index=True)
    assert 'index=True not supported' in str(excinfo.value)
Exemple #5
0
def test_run_persistence_scalar(session, site_metadata, obs_5min_begin,
                                interval_label, mocker):
    run_time = pd.Timestamp('20190101T1945Z')
    # intraday, index=False
    forecast = default_forecast(site_metadata,
                                issue_time_of_day=dt.time(hour=23),
                                lead_time_to_start=pd.Timedelta('1h'),
                                interval_length=pd.Timedelta('1h'),
                                run_length=pd.Timedelta('1h'),
                                interval_label=interval_label)
    issue_time = pd.Timestamp('20190101T2300Z')
    mocker.spy(main.persistence, 'persistence_scalar')
    out = main.run_persistence(session, obs_5min_begin, forecast, run_time,
                               issue_time)
    assert isinstance(out, pd.Series)
    assert len(out) == 1
    assert main.persistence.persistence_scalar.call_count == 1
Exemple #6
0
def test_run_persistence_weekahead(session, site_metadata, mocker):
    variable = 'net_load'
    observation = default_observation(site_metadata,
                                      variable=variable,
                                      interval_length=pd.Timedelta('5min'),
                                      interval_label='beginning')

    run_time = pd.Timestamp('20190110T1945Z')
    forecast = default_forecast(site_metadata,
                                variable=variable,
                                issue_time_of_day=dt.time(hour=23),
                                lead_time_to_start=pd.Timedelta('1h'),
                                interval_length=pd.Timedelta('1h'),
                                run_length=pd.Timedelta('1d'),
                                interval_label='beginning')
    issue_time = pd.Timestamp('20190111T2300Z')
    mocker.spy(main.persistence, 'persistence_interval')
    out = main.run_persistence(session, observation, forecast, run_time,
                               issue_time)
    assert isinstance(out, pd.Series)
    assert len(out) == 24
    assert main.persistence.persistence_interval.call_count == 1