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

Commit 2bd47ca

Browse files
Merge pull request #662 from openclimatefix/issue/save-batch
add option to save batches to differnt location for manager live
2 parents f1ad254 + 25668e6 commit 2bd47ca

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

nowcasting_dataset/manager/manager_live.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
SpaceTimeLocation,
2020
load_from_csv,
2121
)
22+
from nowcasting_dataset.dataset.batch import Batch
2223
from nowcasting_dataset.filesystem import utils as nd_fs_utils
2324
from nowcasting_dataset.manager.base import ManagerBase
2425
from nowcasting_dataset.manager.utils import callback, error_callback
@@ -251,3 +252,23 @@ def create_batches(self, use_async: Optional[bool] = True) -> None:
251252
)
252253

253254
logger.info(f"Finished creating batches for {split_name}!")
255+
256+
def save_batch(self, batch_idx, path: str):
257+
"""
258+
Option to save batch to a differnt location
259+
260+
Args:
261+
path: the path to save the file to
262+
batch_idx: the batch index
263+
264+
"""
265+
266+
# load batch
267+
batch = Batch.load_netcdf(
268+
batch_idx=batch_idx,
269+
data_sources_names=self.data_sources,
270+
local_netcdf_path=self.config.output_data.filepath / "live",
271+
)
272+
273+
# save batch
274+
batch.save_netcdf(batch_i=batch_idx, path=path)

tests/manager/test_manager_live.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,7 @@ def test_run(test_configuration_filename):
199199
t0_datetime=datetime(2020, 4, 1, 15)
200200
) # noqa 101
201201
manager.create_batches()
202+
203+
with tempfile.TemporaryDirectory() as local_temp_path_save:
204+
manager.save_batch(batch_idx=0, path=local_temp_path_save)
205+
assert os.path.exists(f"{local_temp_path_save}/gsp/000000.nc")

0 commit comments

Comments
 (0)