"""Minimal NIfTI-1 writer (.nii.gz), dependency-free. Fallback for when SimpleITK/nibabel are unavailable. Pairs with read_nifti.read_nii.""" import gzip import struct import numpy as np def write_nii(path, vol, spacing=(1.0, 1.0, 1.0)): vol = np.asarray(vol, dtype=np.float32) assert vol.ndim == 3, "expected a 3D volume" nx, ny, nz = vol.shape hdr = bytearray(348) struct.pack_into("