File size: 1,764 Bytes
caa4bd5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | from __future__ import annotations
from collections import Counter
from pathlib import Path
import h5py
import numpy as np
from src.t4_structural_dynamics_v1 import (
CASE_DIR,
case_config,
configuration_design,
load_config,
valid_case_file,
)
def test_t4_v1_design_has_grouped_splits_and_explicit_ood_roles():
rows = configuration_design()
assert len(rows) == 128
assert len({row["case_id"] for row in rows}) == 128
assert Counter(row["split"] for row in rows) == {
"train": 96,
"validation": 16,
"test": 16,
}
assert Counter(row["protocol_role"] for row in rows) == {
"id": 120,
"excitation_ood": 4,
"parameter_ood": 4,
}
assert all(len(row["excitations"]) == 4 for row in rows)
def test_t4_v1_case_configuration_scales_sensors_with_geometry():
global_config = load_config()
row = configuration_design(global_config)[0]
config = case_config(global_config, row)
length = config["geometry"]["length_m"]
height = config["geometry"]["height_m"]
assert np.allclose(
config["sensors"],
[[fraction * length, 0.5 * height] for fraction in (0.2, 0.4, 0.6, 0.8, 1.0)],
)
def test_t4_v1_first_production_case_is_complete_and_finite():
path = CASE_DIR / "config_0000.h5"
assert valid_case_file(path)
with h5py.File(path, "r") as h5:
assert h5.attrs["split"] == "train"
assert len(h5["trajectories"]) == 4
for trajectory in h5["trajectories"].values():
assert trajectory["sensor_displacement_m"].shape == (4001, 5)
assert trajectory["fields/displacement_m"].shape == (201, 245, 3)
assert np.all(np.isfinite(trajectory["sensor_displacement_m"][...]))
|