ocf-data-sampler 0.0.25__py3-none-any.whl → 0.0.27__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ocf-data-sampler might be problematic. Click here for more details.
- ocf_data_sampler/config/model.py +85 -122
- ocf_data_sampler/load/load_dataset.py +6 -6
- ocf_data_sampler/select/find_contiguous_time_periods.py +40 -75
- ocf_data_sampler/select/select_time_slice.py +24 -33
- ocf_data_sampler/select/spatial_slice_for_dataset.py +4 -4
- ocf_data_sampler/select/time_slice_for_dataset.py +18 -17
- ocf_data_sampler/torch_datasets/process_and_combine.py +13 -14
- ocf_data_sampler/torch_datasets/pvnet_uk_regional.py +1 -1
- ocf_data_sampler/torch_datasets/site.py +10 -10
- ocf_data_sampler/torch_datasets/valid_time_periods.py +20 -12
- ocf_data_sampler/{time_functions.py → utils.py} +1 -2
- {ocf_data_sampler-0.0.25.dist-info → ocf_data_sampler-0.0.27.dist-info}/METADATA +1 -1
- {ocf_data_sampler-0.0.25.dist-info → ocf_data_sampler-0.0.27.dist-info}/RECORD +22 -22
- {ocf_data_sampler-0.0.25.dist-info → ocf_data_sampler-0.0.27.dist-info}/WHEEL +1 -1
- tests/config/test_config.py +23 -14
- tests/conftest.py +7 -5
- tests/select/test_find_contiguous_time_periods.py +8 -8
- tests/select/test_select_time_slice.py +31 -43
- tests/torch_datasets/test_pvnet_uk_regional.py +4 -4
- tests/torch_datasets/test_site.py +2 -2
- {ocf_data_sampler-0.0.25.dist-info → ocf_data_sampler-0.0.27.dist-info}/LICENSE +0 -0
- {ocf_data_sampler-0.0.25.dist-info → ocf_data_sampler-0.0.27.dist-info}/top_level.txt +0 -0
|
@@ -55,31 +55,19 @@ def test_select_time_slice(da_sat_like, t0_str):
|
|
|
55
55
|
|
|
56
56
|
# Slice parameters
|
|
57
57
|
t0 = pd.Timestamp(f"2024-01-02 {t0_str}")
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
interval_start = pd.Timedelta(-0, "min")
|
|
59
|
+
interval_end = pd.Timedelta(60, "min")
|
|
60
60
|
freq = pd.Timedelta("5min")
|
|
61
61
|
|
|
62
62
|
# Expect to return these timestamps from the selection
|
|
63
|
-
expected_datetimes = pd.date_range(t0
|
|
63
|
+
expected_datetimes = pd.date_range(t0 +interval_start, t0 + interval_end, freq=freq)
|
|
64
64
|
|
|
65
|
-
# Make the selection
|
|
65
|
+
# Make the selection
|
|
66
66
|
sat_sample = select_time_slice(
|
|
67
|
-
|
|
67
|
+
da_sat_like,
|
|
68
68
|
t0=t0,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
sample_period_duration=freq,
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
# Check the returned times are as expected
|
|
75
|
-
assert (sat_sample.time_utc == expected_datetimes).all()
|
|
76
|
-
|
|
77
|
-
# Make the selection using the `interval_[x]` parameters
|
|
78
|
-
sat_sample = select_time_slice(
|
|
79
|
-
ds=da_sat_like,
|
|
80
|
-
t0=t0,
|
|
81
|
-
interval_start=-history_duration,
|
|
82
|
-
interval_end=forecast_duration,
|
|
69
|
+
interval_start=interval_start,
|
|
70
|
+
interval_end=interval_end,
|
|
83
71
|
sample_period_duration=freq,
|
|
84
72
|
)
|
|
85
73
|
|
|
@@ -93,8 +81,8 @@ def test_select_time_slice_out_of_bounds(da_sat_like, t0_str):
|
|
|
93
81
|
|
|
94
82
|
# Slice parameters
|
|
95
83
|
t0 = pd.Timestamp(f"2024-01-02 {t0_str}")
|
|
96
|
-
|
|
97
|
-
|
|
84
|
+
interval_start = pd.Timedelta(-30, "min")
|
|
85
|
+
interval_end = pd.Timedelta(60, "min")
|
|
98
86
|
freq = pd.Timedelta("5min")
|
|
99
87
|
|
|
100
88
|
# The data is available between these times
|
|
@@ -102,14 +90,14 @@ def test_select_time_slice_out_of_bounds(da_sat_like, t0_str):
|
|
|
102
90
|
max_time = da_sat_like.time_utc.max()
|
|
103
91
|
|
|
104
92
|
# Expect to return these timestamps from the selection
|
|
105
|
-
expected_datetimes = pd.date_range(t0
|
|
93
|
+
expected_datetimes = pd.date_range(t0 + interval_start, t0 + interval_end, freq=freq)
|
|
106
94
|
|
|
107
95
|
# Make the partially out of bounds selection
|
|
108
96
|
sat_sample = select_time_slice(
|
|
109
|
-
|
|
97
|
+
da_sat_like,
|
|
110
98
|
t0=t0,
|
|
111
|
-
|
|
112
|
-
|
|
99
|
+
interval_start=interval_start,
|
|
100
|
+
interval_end=interval_end,
|
|
113
101
|
sample_period_duration=freq,
|
|
114
102
|
fill_selection=True
|
|
115
103
|
)
|
|
@@ -138,8 +126,8 @@ def test_select_time_slice_nwp_basic(da_nwp_like, t0_str):
|
|
|
138
126
|
|
|
139
127
|
# Slice parameters
|
|
140
128
|
t0 = pd.Timestamp(f"2024-01-02 {t0_str}")
|
|
141
|
-
|
|
142
|
-
|
|
129
|
+
interval_start = pd.Timedelta(-6, "h")
|
|
130
|
+
interval_end = pd.Timedelta(3, "h")
|
|
143
131
|
freq = pd.Timedelta("1h")
|
|
144
132
|
|
|
145
133
|
# Make the selection
|
|
@@ -147,8 +135,8 @@ def test_select_time_slice_nwp_basic(da_nwp_like, t0_str):
|
|
|
147
135
|
da_nwp_like,
|
|
148
136
|
t0,
|
|
149
137
|
sample_period_duration=freq,
|
|
150
|
-
|
|
151
|
-
|
|
138
|
+
interval_start=interval_start,
|
|
139
|
+
interval_end=interval_end,
|
|
152
140
|
dropout_timedeltas = None,
|
|
153
141
|
dropout_frac = 0,
|
|
154
142
|
accum_channels = [],
|
|
@@ -156,7 +144,7 @@ def test_select_time_slice_nwp_basic(da_nwp_like, t0_str):
|
|
|
156
144
|
)
|
|
157
145
|
|
|
158
146
|
# Check the target-times are as expected
|
|
159
|
-
expected_target_times = pd.date_range(t0
|
|
147
|
+
expected_target_times = pd.date_range(t0 + interval_start, t0 + interval_end, freq=freq)
|
|
160
148
|
assert (da_slice.target_time_utc==expected_target_times).all()
|
|
161
149
|
|
|
162
150
|
# Check the init-times are as expected
|
|
@@ -172,8 +160,8 @@ def test_select_time_slice_nwp_with_dropout(da_nwp_like, dropout_hours):
|
|
|
172
160
|
"""Test the functionality of select_time_slice_nwp with dropout"""
|
|
173
161
|
|
|
174
162
|
t0 = pd.Timestamp("2024-01-02 12:00")
|
|
175
|
-
|
|
176
|
-
|
|
163
|
+
interval_start = pd.Timedelta(-6, "h")
|
|
164
|
+
interval_end = pd.Timedelta(3, "h")
|
|
177
165
|
freq = pd.Timedelta("1h")
|
|
178
166
|
dropout_timedelta = pd.Timedelta(f"-{dropout_hours}h")
|
|
179
167
|
|
|
@@ -181,8 +169,8 @@ def test_select_time_slice_nwp_with_dropout(da_nwp_like, dropout_hours):
|
|
|
181
169
|
da_nwp_like,
|
|
182
170
|
t0,
|
|
183
171
|
sample_period_duration=freq,
|
|
184
|
-
|
|
185
|
-
|
|
172
|
+
interval_start=interval_start,
|
|
173
|
+
interval_end=interval_end,
|
|
186
174
|
dropout_timedeltas = [dropout_timedelta],
|
|
187
175
|
dropout_frac = 1,
|
|
188
176
|
accum_channels = [],
|
|
@@ -190,7 +178,7 @@ def test_select_time_slice_nwp_with_dropout(da_nwp_like, dropout_hours):
|
|
|
190
178
|
)
|
|
191
179
|
|
|
192
180
|
# Check the target-times are as expected
|
|
193
|
-
expected_target_times = pd.date_range(t0
|
|
181
|
+
expected_target_times = pd.date_range(t0 + interval_start, t0 + interval_end, freq=freq)
|
|
194
182
|
assert (da_slice.target_time_utc==expected_target_times).all()
|
|
195
183
|
|
|
196
184
|
# Check the init-times are as expected considering the delay
|
|
@@ -207,9 +195,9 @@ def test_select_time_slice_nwp_with_dropout_and_accum(da_nwp_like, t0_str):
|
|
|
207
195
|
|
|
208
196
|
# Slice parameters
|
|
209
197
|
t0 = pd.Timestamp(f"2024-01-02 {t0_str}")
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
freq = pd.Timedelta("
|
|
198
|
+
interval_start = pd.Timedelta(-6, "h")
|
|
199
|
+
interval_end = pd.Timedelta(3, "h")
|
|
200
|
+
freq = pd.Timedelta("1H")
|
|
213
201
|
dropout_timedelta = pd.Timedelta("-2h")
|
|
214
202
|
|
|
215
203
|
t0_delayed = (t0 + dropout_timedelta).floor(NWP_FREQ)
|
|
@@ -218,8 +206,8 @@ def test_select_time_slice_nwp_with_dropout_and_accum(da_nwp_like, t0_str):
|
|
|
218
206
|
da_nwp_like,
|
|
219
207
|
t0,
|
|
220
208
|
sample_period_duration=freq,
|
|
221
|
-
|
|
222
|
-
|
|
209
|
+
interval_start=interval_start,
|
|
210
|
+
interval_end=interval_end,
|
|
223
211
|
dropout_timedeltas=[dropout_timedelta],
|
|
224
212
|
dropout_frac=1,
|
|
225
213
|
accum_channels=["dswrf"],
|
|
@@ -227,7 +215,7 @@ def test_select_time_slice_nwp_with_dropout_and_accum(da_nwp_like, t0_str):
|
|
|
227
215
|
)
|
|
228
216
|
|
|
229
217
|
# Check the target-times are as expected
|
|
230
|
-
expected_target_times = pd.date_range(t0
|
|
218
|
+
expected_target_times = pd.date_range(t0 + interval_start, t0 + interval_end, freq=freq)
|
|
231
219
|
assert (da_slice.target_time_utc==expected_target_times).all()
|
|
232
220
|
|
|
233
221
|
# Check the init-times are as expected considering the delay
|
|
@@ -254,7 +242,7 @@ def test_select_time_slice_nwp_with_dropout_and_accum(da_nwp_like, t0_str):
|
|
|
254
242
|
init_time_utc=t0_delayed,
|
|
255
243
|
channel="dswrf",
|
|
256
244
|
).diff(dim="step", label="lower")
|
|
257
|
-
.sel(step=slice(t0-t0_delayed
|
|
245
|
+
.sel(step=slice(t0-t0_delayed + interval_start, t0-t0_delayed + interval_end))
|
|
258
246
|
)
|
|
259
247
|
|
|
260
248
|
# Check the values are the same
|
|
@@ -275,7 +263,7 @@ def test_select_time_slice_nwp_with_dropout_and_accum(da_nwp_like, t0_str):
|
|
|
275
263
|
init_time_utc=t0_delayed,
|
|
276
264
|
channel="t",
|
|
277
265
|
)
|
|
278
|
-
.sel(step=slice(t0-t0_delayed
|
|
266
|
+
.sel(step=slice(t0-t0_delayed + interval_start, t0-t0_delayed + interval_end))
|
|
279
267
|
)
|
|
280
268
|
|
|
281
269
|
# Check the values are the same
|
|
@@ -11,9 +11,9 @@ def pvnet_config_filename(tmp_path, config_filename, nwp_ukv_zarr_path, uk_gsp_z
|
|
|
11
11
|
|
|
12
12
|
# adjust config to point to the zarr file
|
|
13
13
|
config = load_yaml_configuration(config_filename)
|
|
14
|
-
config.input_data.nwp['ukv'].
|
|
15
|
-
config.input_data.satellite.
|
|
16
|
-
config.input_data.gsp.
|
|
14
|
+
config.input_data.nwp['ukv'].zarr_path = nwp_ukv_zarr_path
|
|
15
|
+
config.input_data.satellite.zarr_path = sat_zarr_path
|
|
16
|
+
config.input_data.gsp.zarr_path = uk_gsp_zarr_path
|
|
17
17
|
|
|
18
18
|
filename = f"{tmp_path}/configuration.yaml"
|
|
19
19
|
save_yaml_configuration(config, filename)
|
|
@@ -60,7 +60,7 @@ def test_pvnet_no_gsp(pvnet_config_filename):
|
|
|
60
60
|
# load config
|
|
61
61
|
config = load_yaml_configuration(pvnet_config_filename)
|
|
62
62
|
# remove gsp
|
|
63
|
-
config.input_data.gsp.
|
|
63
|
+
config.input_data.gsp.zarr_path = ''
|
|
64
64
|
|
|
65
65
|
# save temp config file
|
|
66
66
|
with tempfile.NamedTemporaryFile() as temp_config_file:
|
|
@@ -13,8 +13,8 @@ def site_config_filename(tmp_path, config_filename, nwp_ukv_zarr_path, sat_zarr_
|
|
|
13
13
|
|
|
14
14
|
# adjust config to point to the zarr file
|
|
15
15
|
config = load_yaml_configuration(config_filename)
|
|
16
|
-
config.input_data.nwp["ukv"].
|
|
17
|
-
config.input_data.satellite.
|
|
16
|
+
config.input_data.nwp["ukv"].zarr_path = nwp_ukv_zarr_path
|
|
17
|
+
config.input_data.satellite.zarr_path = sat_zarr_path
|
|
18
18
|
config.input_data.site = data_sites
|
|
19
19
|
config.input_data.gsp = None
|
|
20
20
|
|
|
File without changes
|
|
File without changes
|