Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 3b7e0a2

Browse files
Merge pull request #721 from openclimatefix/issue/gsp-live-update
Issue/gsp live update
2 parents 55cbd51 + 3e96549 commit 3b7e0a2

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

nowcasting_dataset/data_sources/gsp/live.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_gsp_power_from_database(
3636
logger.debug(f"{history_duration=}")
3737

3838
extra_duration = timedelta(minutes=load_extra_minutes)
39-
now = pd.to_datetime(datetime.now(tz=timezone.utc)).floor("30T")
39+
now = pd.to_datetime(datetime.now(tz=timezone.utc)).ceil("30T")
4040
start_utc = now - history_duration
4141
start_utc_extra = start_utc - extra_duration
4242

tests/data_sources/gsp/test_gsp_live.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def test_get_example_and_batch(gsp_yields):
8585
)
8686

8787
location = locations[0]
88-
location.t0_datetime_utc = datetime(2022, 1, 1, 3, tzinfo=timezone.utc)
88+
location.t0_datetime_utc = datetime(2022, 1, 1, 3, 0, 5, tzinfo=timezone.utc)
8989

9090
example = gsp_data_source.get_example(location=location)
91-
example.time.values[-1] == datetime(2022, 1, 1, 3)
91+
assert len(example.time) == 5
92+
assert example.time.values[-1] == pd.to_datetime(datetime(2022, 1, 1, 3, 30))

tests/manager/test_manager_live.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def test_batches(test_configuration_filename, sat, gsp):
105105

106106
manager = ManagerLive()
107107
manager.load_yaml_configuration(filename=test_configuration_filename)
108+
manager.config.input_data.gsp.is_live = True
109+
gsp.forecast_minutes = 0
108110

109111
with tempfile.TemporaryDirectory() as local_temp_path, tempfile.TemporaryDirectory() as dst_path: # noqa 101
110112

@@ -218,7 +220,9 @@ def test_run_just_gsp(test_configuration_filename, gsp_yields_and_systems):
218220
gsp = xr.load_dataset(f"{local_temp_path_save}/gsp/000000.nc", engine="h5netcdf")
219221
gsp = GSP(gsp)
220222
assert len(gsp.time.values[0]) == 5
221-
assert pd.to_datetime(gsp.time.values[0, -1]) == floor_minutes_dt(datetime.utcnow())
223+
assert pd.to_datetime(gsp.time.values[0, -1]) == pd.Timestamp(datetime.utcnow()).ceil(
224+
"30T"
225+
)
222226

223227

224228
def test_run(test_configuration_filename, gsp_yields_and_systems):

0 commit comments

Comments
 (0)