Download load_t4_structural_dynamics.py from HaomingLuo/AgentFEM-Structural-Dynamics-Virtual-Sensing: direct link, hf CLI and curl.
- Browser
- Download file 2.01 kB
-
https://huggingface.co/datasets/HaomingLuo/AgentFEM-Structural-Dynamics-Virtual-Sensing/resolve/main/load_t4_structural_dynamics.py
- Command line
-
hf download hf://datasets/HaomingLuo/AgentFEM-Structural-Dynamics-Virtual-Sensing/load_t4_structural_dynamics.py
-
curl -L -o load_t4_structural_dynamics.py https://huggingface.co/datasets/HaomingLuo/AgentFEM-Structural-Dynamics-Virtual-Sensing/resolve/main/load_t4_structural_dynamics.py
2.01 kB
| """Lightweight NumPy/h5py reader for the T4 structural-dynamics pilot.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| import h5py | |
| import numpy as np | |
| DEFAULT_PATH = ( | |
| Path(__file__).resolve().parents[1] | |
| / "data" | |
| / "t4_structural_dynamics_pilot" | |
| / "pilot.h5" | |
| ) | |
| def trajectory_ids(path: str | Path = DEFAULT_PATH) -> tuple[str, ...]: | |
| with h5py.File(path, "r") as h5: | |
| return tuple(sorted(h5["trajectories"])) | |
| def load_trajectory( | |
| trajectory_id: str, | |
| path: str | Path = DEFAULT_PATH, | |
| *, | |
| include_fields: bool = True, | |
| ) -> dict[str, object]: | |
| with h5py.File(path, "r") as h5: | |
| group = h5[f"trajectories/{trajectory_id}"] | |
| arrays = { | |
| name: np.asarray(dataset) | |
| for name, dataset in group.items() | |
| if isinstance(dataset, h5py.Dataset) | |
| } | |
| if include_fields: | |
| arrays["field_time_s"] = np.asarray(group["fields/time_s"]) | |
| arrays["displacement_m"] = np.asarray(group["fields/displacement_m"]) | |
| arrays["velocity_m_per_s"] = np.asarray(group["fields/velocity_m_per_s"]) | |
| arrays["acceleration_m_per_s2"] = np.asarray( | |
| group["fields/acceleration_m_per_s2"] | |
| ) | |
| arrays["reference_geometry_m"] = np.asarray( | |
| h5["common/reference_geometry_m"] | |
| ) | |
| arrays["topology"] = np.asarray(h5["common/topology"]) | |
| arrays["sensor_coordinates_m"] = np.asarray( | |
| h5["common/sensor_coordinates_m"] | |
| ) | |
| return { | |
| "trajectory_id": trajectory_id, | |
| "spec": json.loads(group.attrs["spec_json"]), | |
| "attributes": {name: group.attrs[name] for name in group.attrs}, | |
| "arrays": arrays, | |
| } | |
| if __name__ == "__main__": | |
| ids = trajectory_ids() | |
| sample = load_trajectory(ids[0], include_fields=False) | |
| print(ids) | |
| print({name: value.shape for name, value in sample["arrays"].items()}) | |