|
|
import torch
|
|
|
from torch.utils.data import Dataset
|
|
|
import numpy as np
|
|
|
from pathlib import Path
|
|
|
from typing import List, Tuple, Optional
|
|
|
|
|
|
|
|
|
from load_volumes import process_fluent_export_sparse, VolumeSpec
|
|
|
from load_planes import process_plane_export, PlaneSpec
|
|
|
|
|
|
class WAKESETDataset(Dataset):
|
|
|
def __init__(self, root_dir: str, subset: str = 'train', augment: bool = False):
|
|
|
"""
|
|
|
Args:
|
|
|
root_dir: Path to WAKESET folder.
|
|
|
subset: 'train', 'val', or 'test'.
|
|
|
augment: If True, applies the rotation/flipping described in the paper.
|
|
|
"""
|
|
|
self.root = Path(root_dir) / "Volumes"
|
|
|
self.files = sorted(list(self.root.glob("Forward_*_CUBE_128.csv")))
|
|
|
self.augment = augment
|
|
|
|
|
|
|
|
|
|
|
|
n = len(self.files)
|
|
|
if subset == 'train': self.files = self.files[:int(0.8*n)]
|
|
|
elif subset == 'val': self.files = self.files[int(0.8*n):int(0.9*n)]
|
|
|
else: self.files = self.files[int(0.9*n):]
|
|
|
|
|
|
def __len__(self):
|
|
|
|
|
|
return len(self.files) * 4 if self.augment else len(self.files)
|
|
|
|
|
|
def __getitem__(self, idx):
|
|
|
|
|
|
if self.augment:
|
|
|
file_idx = idx // 4
|
|
|
aug_mode = idx % 4
|
|
|
else:
|
|
|
file_idx = idx
|
|
|
aug_mode = 0
|
|
|
|
|
|
|
|
|
path = self.files[file_idx]
|
|
|
npz_path = path.with_suffix('.npz')
|
|
|
|
|
|
if npz_path.exists():
|
|
|
data = np.load(npz_path)
|
|
|
vol = data['velocity_magnitude']
|
|
|
else:
|
|
|
|
|
|
raw = process_fluent_export_sparse(path, fill_value=0.0)
|
|
|
vol = raw['velocity_magnitude']
|
|
|
|
|
|
|
|
|
tensor = torch.from_numpy(vol).float().unsqueeze(0)
|
|
|
|
|
|
|
|
|
if aug_mode == 1:
|
|
|
|
|
|
tensor = torch.flip(tensor, dims=[2])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spec = VolumeSpec.from_filename(path)
|
|
|
speed = float(spec.velocity) / 1000.0
|
|
|
angle = float(spec.angle)
|
|
|
|
|
|
kinematics = torch.tensor([speed, angle], dtype=torch.float32)
|
|
|
|
|
|
return tensor, kinematics |