Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

add if statement #295

Merged
merged 4 commits into from
Mar 26, 2024
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
15 changes: 9 additions & 6 deletions ocf_datapipes/training/windnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,15 @@ def __iter__(self):
for filename in self.filenames:
dataset = xr.open_dataset(filename)
datasets = uncombine_from_single_dataset(dataset)
# print(datasets)
datasets["nwp"]["ecmwf"] = potentially_coarsen(datasets["nwp"]["ecmwf"])
# Select the specific keys desired
datasets["nwp"]["ecmwf"] = datasets["nwp"]["ecmwf"].sel(
channel=["u10", "u100", "u200", "v10", "v100", "v200"]
)

if "ecmwf" in datasets["nwp"]:
datasets["nwp"]["ecmwf"] = potentially_coarsen(datasets["nwp"]["ecmwf"])

# Select the specific keys desired
datasets["nwp"]["ecmwf"] = datasets["nwp"]["ecmwf"].sel(
channel=["u10", "u100", "u200", "v10", "v100", "v200"]
)

# Yield a dictionary of the data, using the keys in self.keys
# print(datasets)
dataset_dict = {}
Expand Down
21 changes: 8 additions & 13 deletions tests/batch/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@
import torch

from ocf_datapipes.batch import BatchKey, NumpyBatch, TensorBatch
from ocf_datapipes.batch import copy_batch_to_device, batch_to_tensor
from ocf_datapipes.batch.utils import copy_batch_to_device, batch_to_tensor
import pytest


def _create_test_batch() -> NumpyBatch:
@pytest.fixture()
def sample_numpy_batch():
sample: NumpyBatch = {}
sample[BatchKey.satellite_actual] = np.full((12, 10, 24, 24), 0)
return sample


def test_batch_to_tensor() -> None:
batch: NumpyBatch = _create_test_batch()
tensor_batch = batch_to_tensor(batch)
def test_batch_to_tensor(sample_numpy_batch):
tensor_batch = batch_to_tensor(sample_numpy_batch)
assert isinstance(tensor_batch[BatchKey.satellite_actual], torch.Tensor)


def test_copy_batch_to_device() -> None:
batch = _create_test_batch()
tensor_batch = batch_to_tensor(batch)
def test_copy_batch_to_device(sample_numpy_batch):
tensor_batch = batch_to_tensor(sample_numpy_batch)
device = torch.device("cpu")
batch_copy: TensorBatch = copy_batch_to_device(tensor_batch, device)
assert batch_copy[BatchKey.satellite_actual].device == device # type: ignore


if __name__ == "__main__":
test_batch_to_tensor()
test_copy_batch_to_device()
Empty file added tests/utils/__init__.py
Empty file.