Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
default_language_version:
python: python3.9

ci:
skip: [pydocstyle, flake8]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
Expand Down
2 changes: 1 addition & 1 deletion tests/data/gsp/test.zarr/.zattrs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
2 changes: 1 addition & 1 deletion tests/data/gsp/test.zarr/.zgroup
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"zarr_format": 2
}
}
2 changes: 1 addition & 1 deletion tests/data/nwp_data/test.zarr/.zattrs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
2 changes: 1 addition & 1 deletion tests/data/nwp_data/test.zarr/.zgroup
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"zarr_format": 2
}
}
2 changes: 1 addition & 1 deletion tests/data/nwp_data/test.zarr/UKV/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"y",
"x"
]
}
}
2 changes: 1 addition & 1 deletion tests/data/nwp_data/test.zarr/init_time/.zarray
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
9
],
"zarr_format": 2
}
}
2 changes: 1 addition & 1 deletion tests/data/nwp_data/test.zarr/init_time/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"long_name": "initial time of forecast",
"standard_name": "forecast_reference_time",
"units": "hours since 2018-01-01"
}
}
2 changes: 1 addition & 1 deletion tests/data/nwp_data/test.zarr/step/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"long_name": "time since forecast_reference_time",
"standard_name": "forecast_period",
"units": "hours"
}
}
2 changes: 1 addition & 1 deletion tests/data/nwp_data/test.zarr/variable/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"_ARRAY_DIMENSIONS": [
"variable"
]
}
}
2 changes: 1 addition & 1 deletion tests/data/nwp_data/test.zarr/x/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"_ARRAY_DIMENSIONS": [
"x"
]
}
}
2 changes: 1 addition & 1 deletion tests/data/nwp_data/test.zarr/y/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"_ARRAY_DIMENSIONS": [
"y"
]
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/.zattrs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/.zgroup
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"zarr_format": 2
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/.zmetadata
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@
}
},
"zarr_consolidated_format": 1
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/stacked_eumetsat_data/.zarray
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
1
],
"zarr_format": 2
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/stacked_eumetsat_data/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"x",
"variable"
]
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/time/.zarray
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
72
],
"zarr_format": 2
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/time/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
],
"calendar": "proleptic_gregorian",
"units": "minutes since 2018-05-31T00:04:00"
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/variable/.zarray
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
1
],
"zarr_format": 2
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/variable/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"_ARRAY_DIMENSIONS": [
"variable"
]
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/x/.zarray
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
548
],
"zarr_format": 2
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/x/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"_ARRAY_DIMENSIONS": [
"x"
]
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/y/.zarray
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
704
],
"zarr_format": 2
}
}
2 changes: 1 addition & 1 deletion tests/data/sat_data.zarr/y/.zattrs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"_ARRAY_DIMENSIONS": [
"y"
]
}
}
32 changes: 32 additions & 0 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
from datetime import datetime
from pathlib import Path

import numpy as np
import pandas as pd

import nowcasting_dataset
from nowcasting_dataset.data_sources.gsp.gsp_data_source import GSPDataSource
from nowcasting_dataset.data_sources.satellite.satellite_data_source import SatelliteDataSource
from nowcasting_dataset.manager import Manager


Expand Down Expand Up @@ -44,4 +48,32 @@ def test_load_yaml_configuration(): # noqa: D103
assert isinstance(manager.data_source_which_defines_geospatial_locations, GSPDataSource)


def test_get_daylight_datetime_index():
""" Check that 'manager' gets the correct t0 datetime over nighttime"""
filename = Path(nowcasting_dataset.__file__).parent.parent / "tests" / "data" / "sat_data.zarr"

sat = SatelliteDataSource(
zarr_path=filename,
history_minutes=30,
forecast_minutes=60,
image_size_pixels=64,
meters_per_pixel=2000,
)

manager = Manager()
manager.data_sources = {"sat": sat}
manager.data_source_which_defines_geospatial_locations = sat
t0_datetimes = manager.get_t0_datetimes_across_all_data_sources(freq="5T")

# The testing sat_data.zarr has contiguous data from 12:05 to 18:00.
# nowcasting_datamodule.history_minutes = 30
# nowcasting_datamodule.forecast_minutes = 60
# Daylight ends at 16:20.
# So the expected t0_datetimes start at 12:35 (12:05 + 30 minutes)
# and end at 15:20 (16:20 - 60 minutes)

correct_t0_datetimes = pd.date_range("2019-01-01 12:35", "2019-01-01 15:20", freq="5 min")
np.testing.assert_array_equal(t0_datetimes, correct_t0_datetimes)


# TODO: Issue #322: Test the other Manager methods!