Writers (ParaView export)

flowtracks.writers exports run results to ParaView-readable formats via pyvista/vtk. It replaces the removed vtk_export module: the grid-type rule — vtp for trajectories, vti for uniform Eulerian volumes, vtr for non-uniform volumes, pvd for time series — is applied here.

flowtracks.writers.write_pvd() writes a .pvd time-series file. flowtracks.writers.write_trajectories_vtp() writes trajectory polydata (.vtp). flowtracks.writers.write_eulerian_series() writes a sequence of Eulerian volume files plus a .pvd — the single entry point for “export a run”. flowtracks.writers.export_run_to_paraview() does the same from a run.zarr store, reading it with ZarrScene.

Unified pyvista-based ParaView writers.

Lagrangian trajectories -> VTK PolyData (.vtp, polylines per trajid). Eulerian grids -> VTK ImageData (.vti, uniform axis spacing) or RectilinearGrid (.vtr, non-uniform), each written as a per-timestep series plus one .pvd Collection.

See WRITERS_PLAN.md for the design rationale and the writers this module replaces (vtk_export.py, eulerian.export_vtk, eulerian.export_vtk_rectilinear_series).

flowtracks.writers.write_pvd(path: Path, entries: list[tuple[float, Path | str]]) → Path[source]

Write a ParaView Collection (.pvd) indexing time-series files.

entries is a list of (timestep, file_path). Paths are stored relative to path so the output directory stays portable.

flowtracks.writers.trajectory_units(source) → dict[source]

Units recorded on a trajectories store ({pos, vel, time, …} units).

Zarr paths report what the writer recorded; anything else reports {} – the caller then labels without units rather than guessing.

flowtracks.writers.trajectory_polydata(source, trajids=None, units=None)[source]

Lagrangian trajectories as VTK PolyData: points + one polyline per trajid.

source as for write_trajectories_vtp(). trajids optionally keeps only those trajectories. Point data: trajid, time, velocity, speed. units (e.g. {"pos": "m"}) is stored as field data (units:<name>); when omitted and source is a Zarr path, whatever the writer recorded is carried over. Shared by the .vtp writer and flowtracks.graphics.plot_trajectories_3d().

flowtracks.writers.write_trajectories_vtp(source, out_path: Path) → Path[source]

Write Lagrangian trajectories as VTK PolyData (points + polylines per trajid).

source is a zarr path holding a trajectories/ group with pos/vel/time/trajid arrays (a flowtracks Zarr export or an openptv2 RunStore – no conversion needed, see ZarrScene), or any object exposing .collect(["pos", "velocity", "time", "trajid"]) (ZarrScene/Scene).

flowtracks.writers.write_eulerian_series(ds: Dataset, out_dir: Path, prefix: str = 'phase', time_dim: str = 'phase', dt: float = 1.0, units: dict | None = None, vectors: dict | None = None, tensors: dict | None = None, keep_nan: bool = False) → Path[source]

Write one Eulerian grid file per time_dim step plus a .pvd series.

Grid type is chosen from axis spacing: vtkImageData (.vti) when x, y and z are each uniformly spaced, vtkRectilinearGrid (.vtr) otherwise. Vector fields named by VEL_VARS are combined into a single “velocity” array; every other data variable is written as a scalar.

vectors maps extra output names to three component variables ({"velocity_pooled": [u, v, w]}); tensors maps output names to six variables of a symmetric tensor in VTK’s order xx, yy, zz, xy, yz, xz ({"reynolds_stress": [uu, vv, ww, uv, vw, uw]}), written as one 6-component array ParaView recognises. Grouped variables are not also written as scalars; a group with a missing variable is skipped. Boolean variables (e.g. valid) are written as 0/1 uint8.

keep_nan: write NaN (no data) as NaN — ParaView shows it in the NaN colour and Threshold/Contour skip it — instead of the default 0.0, which is indistinguishable from a measured zero. ±Inf becomes NaN too.

units maps array name to unit string (e.g. {"velocity": "m s-1"}) and is stored as grid field data (units:<name>); when omitted, the dataset’s own units attrs are carried over where present. VTK has no unit system, so this is annotation, not enforcement — but the reader no longer has to guess.

flowtracks.writers.export_run_to_paraview(zarr_path: Path, out_dir: Path, grid_params: dict | None = None, eulerian_ds: Dataset | None = None, **eulerian_grid_kwargs) → dict[str, Path][source]

Convenience wrapper: write trajectories, and optionally an Eulerian grid series, for one run into out_dir.

Pass eulerian_ds directly if you already built it (e.g. via eulerian_grid() or xr.open_zarr); pass grid_params (plus eulerian_grid’s other required kwargs: first, last, cycletime, …) to have this function build it from zarr_path.