"""Write HDF5 and NetCDF-4 test files with h5py/netCDF4, and what libhdf5 reads back from them, for the clawhdf5-wasm tests. python make_fixture.py OUT_DIR writes OUT_DIR/fixture.h5, OUT_DIR/fixture.nc and OUT_DIR/expected.json. Both the Rust test (crates/clawhdf5-wasm/tests/h5py_interop.rs, native) and the Node test (test.mjs, the built wasm package) compare against the same expected.json, so the two check the same values. Every expected value comes from h5py reading the file back (numpy slicing for hyperslabs), never from the arrays that were written. Integers are encoded as strings so JSON.parse keeps 64-bit values exact. """ import json import sys import warnings from pathlib import Path import h5py import netCDF4 import numpy as np # netCDF4 1.7 trips numpy 2.5's shape-setting deprecation on assignment. warnings.filterwarnings("ignore", category=DeprecationWarning) out = Path(sys.argv[1]) out.mkdir(parents=True, exist_ok=True) h5 = out / "fixture.h5" nc = out / "fixture.nc" rng = np.random.default_rng(7) with h5py.File(h5, "w") as f: f.attrs["title"] = "wasm fixture" f.attrs["version"] = np.int64(3) f.attrs["scale"] = np.array([0.5, 2.0]) f.attrs["big"] = np.uint64(2**63 + 5) f.attrs.create("vlen_note", "héllo", dtype=h5py.string_dtype()) f.create_dataset( "grid", data=np.arange(60, dtype="f4")) f.create_dataset("f16", data=np.array([0.5, -1.25, 65504], dtype=" 2 else 1] + [2] * (obj.ndim - 1) count = [min(c, (n - s - 1) // st + 1) for c, s, st, n in zip(count, start, stride, obj.shape)] return (start, count, stride) json.dump({"fixture.h5": describe(h5), "fixture.nc": describe(nc)}, open(out / "expected.json", "w"), indent=1, ensure_ascii=False)