|
2 | 2 | from datetime import datetime |
3 | 3 | from pathlib import Path |
4 | 4 |
|
| 5 | +import numpy as np |
| 6 | +import pandas as pd |
| 7 | + |
5 | 8 | import nowcasting_dataset |
6 | 9 | from nowcasting_dataset.data_sources.gsp.gsp_data_source import GSPDataSource |
| 10 | +from nowcasting_dataset.data_sources.satellite.satellite_data_source import SatelliteDataSource |
7 | 11 | from nowcasting_dataset.manager import Manager |
8 | 12 |
|
9 | 13 |
|
@@ -44,4 +48,32 @@ def test_load_yaml_configuration(): # noqa: D103 |
44 | 48 | assert isinstance(manager.data_source_which_defines_geospatial_locations, GSPDataSource) |
45 | 49 |
|
46 | 50 |
|
| 51 | +def test_get_daylight_datetime_index(): |
| 52 | + """ Check that 'manager' gets the correct t0 datetime over nighttime""" |
| 53 | + filename = Path(nowcasting_dataset.__file__).parent.parent / "tests" / "data" / "sat_data.zarr" |
| 54 | + |
| 55 | + sat = SatelliteDataSource( |
| 56 | + zarr_path=filename, |
| 57 | + history_minutes=30, |
| 58 | + forecast_minutes=60, |
| 59 | + image_size_pixels=64, |
| 60 | + meters_per_pixel=2000, |
| 61 | + ) |
| 62 | + |
| 63 | + manager = Manager() |
| 64 | + manager.data_sources = {"sat": sat} |
| 65 | + manager.data_source_which_defines_geospatial_locations = sat |
| 66 | + t0_datetimes = manager.get_t0_datetimes_across_all_data_sources(freq="5T") |
| 67 | + |
| 68 | + # The testing sat_data.zarr has contiguous data from 12:05 to 18:00. |
| 69 | + # nowcasting_datamodule.history_minutes = 30 |
| 70 | + # nowcasting_datamodule.forecast_minutes = 60 |
| 71 | + # Daylight ends at 16:20. |
| 72 | + # So the expected t0_datetimes start at 12:35 (12:05 + 30 minutes) |
| 73 | + # and end at 15:20 (16:20 - 60 minutes) |
| 74 | + |
| 75 | + correct_t0_datetimes = pd.date_range("2019-01-01 12:35", "2019-01-01 15:20", freq="5 min") |
| 76 | + np.testing.assert_array_equal(t0_datetimes, correct_t0_datetimes) |
| 77 | + |
| 78 | + |
47 | 79 | # TODO: Issue #322: Test the other Manager methods! |
0 commit comments