def test_get_data_start_end_labels_obs_longer_than_1h(site_metadata): observation = default_observation( site_metadata, interval_length=pd.Timedelta('2h')) forecast = default_forecast( site_metadata, run_length=pd.Timedelta('5min')) run_time = pd.Timestamp('20190422T1945Z') # obs interval cannot be longer than 1 hr with pytest.raises(ValueError) as excinfo: main.get_data_start_end(observation, forecast, run_time) assert 'observation.interval_length <= 1h' in str(excinfo.value)
def test_get_data_start_end_labels_obs_avg_fx_instant(site_metadata): run_time = pd.Timestamp('20190422T1945Z') observation = default_observation( site_metadata, interval_length=pd.Timedelta('5min'), interval_label='ending') forecast = default_forecast( site_metadata, issue_time_of_day=dt.time(hour=5), lead_time_to_start=pd.Timedelta('1h'), interval_length=pd.Timedelta('5min'), run_length=pd.Timedelta('1d'), interval_label='instant') with pytest.raises(ValueError) as excinfo: main.get_data_start_end(observation, forecast, run_time) assert 'made from interval average obs' in str(excinfo.value)
def test_get_data_start_end_labels_obs_fx_instant_mismatch(site_metadata): observation = default_observation( site_metadata, interval_length=pd.Timedelta('5min'), interval_label='instant') forecast = default_forecast( site_metadata, issue_time_of_day=dt.time(hour=5), lead_time_to_start=pd.Timedelta('1h'), interval_length=pd.Timedelta('1h'), # interval_length must be equal run_length=pd.Timedelta('1d'), interval_label='instant') # if interval_label also instant run_time = pd.Timestamp('20190422T1945Z') with pytest.raises(ValueError) as excinfo: main.get_data_start_end(observation, forecast, run_time) assert 'with identical interval length' in str(excinfo.value)
def test_get_data_start_end_labels_subhourly_window_limit(site_metadata): observation = default_observation( site_metadata, interval_length=pd.Timedelta('5min'), interval_label='beginning') forecast = default_forecast( site_metadata, run_length=pd.Timedelta('5min'), # test subhourly limit on window interval_label='beginning') run_time = pd.Timestamp('20190422T1945Z') data_start, data_end = main.get_data_start_end(observation, forecast, run_time) assert data_start == pd.Timestamp('20190422T1940Z') assert data_end == pd.Timestamp('20190422T1945Z')
def test_get_data_start_end_labels_1h_window_limit(site_metadata): observation = default_observation( site_metadata, interval_length=pd.Timedelta('5min'), interval_label='beginning') forecast = default_forecast( site_metadata, run_length=pd.Timedelta('12h'), # test 1 hr limit on window interval_label='beginning') # ensure data no later than run time run_time = pd.Timestamp('20190422T1945Z') data_start, data_end = main.get_data_start_end(observation, forecast, run_time) assert data_start == pd.Timestamp('20190422T1845Z') assert data_end == pd.Timestamp('20190422T1945Z')
def test_get_data_start_end_labels_obs_instant_fx_avg_intraday(site_metadata): run_time = pd.Timestamp('20190422T1945Z') observation = default_observation( site_metadata, interval_length=pd.Timedelta('5min'), interval_label='instant') forecast = default_forecast( site_metadata, issue_time_of_day=dt.time(hour=5), lead_time_to_start=pd.Timedelta('1h'), interval_length=pd.Timedelta('5min'), run_length=pd.Timedelta('15min'), interval_label='ending') data_start, data_end = main.get_data_start_end(observation, forecast, run_time) assert data_start == pd.Timestamp('20190422T193001Z') assert data_end == pd.Timestamp('20190422T1945Z')
def test_get_data_start_end_labels_obs_fx_instant(site_metadata): observation = default_observation( site_metadata, interval_length=pd.Timedelta('5min'), interval_label='instant') forecast = default_forecast( site_metadata, issue_time_of_day=dt.time(hour=5), lead_time_to_start=pd.Timedelta('1h'), interval_length=pd.Timedelta('5min'), # interval_length must be equal run_length=pd.Timedelta('1d'), interval_label='instant') # if interval_label also instant run_time = pd.Timestamp('20190422T1945Z') data_start, data_end = main.get_data_start_end(observation, forecast, run_time) assert data_start == pd.Timestamp('20190421T0000Z') assert data_end == pd.Timestamp('20190421T235959Z')
def test_get_data_start_end_labels_obs_longer_than_1h_day_ahead(site_metadata): observation = default_observation( site_metadata, interval_length=pd.Timedelta('2h'), interval_label='beginning') forecast = default_forecast( site_metadata, issue_time_of_day=dt.time(hour=5), lead_time_to_start=pd.Timedelta('1h'), interval_length=pd.Timedelta('1h'), run_length=pd.Timedelta('1d'), # day ahead interval_label='beginning') run_time = pd.Timestamp('20190422T1945Z') # day ahead doesn't care about obs interval length data_start, data_end = main.get_data_start_end(observation, forecast, run_time) assert data_start == pd.Timestamp('20190421T0000Z') assert data_end == pd.Timestamp('20190422T0000Z')