Migration guide: from prm.dataset to the lazy API#
Version 1.5.0 introduces a lazy, Dask-backed way to read and write the raw binary files of XCompact3d, built on xarray-binfile. The on-demand loader prm.dataset keeps working in the 1.x series but emits a FutureWarning, and it will be removed in version 2.0. This page maps every call to its replacement.
Why#
Lazy and parallel.
prm.open_dataset()describes the whole simulation at once; values are read only when needed, one file per Dask task, so larger-than-memory workflows and parallel evaluation come for free.One description of the files. Naming, byte order, dtype, mesh, time and the stacked
u/phiare declared once, inXcompact3dConvention, and reused for reading, writing and discovery.Standard xarray. The same convention is registered as the xarray engine
xcompact3d, soxarray.open_mfdatasetworks out of the box.Less toolbox-specific code. The file mechanics now live in xarray-binfile, which is shared with other solvers.
What is deprecated#
Access to prm.dataset itself, and therefore all of its methods and settings. The two APIs are independent: the lazy API never reads prm.dataset.filename_properties, data_path, drop_coords, snapshot_step, stack_velocity or stack_scalar. Configure one or the other, never both.
Call by call#
On-demand loader (deprecated) |
Lazy API |
|---|---|
|
pass |
|
|
|
|
|
|
|
always stacked; |
|
|
|
still the default dtype; override per call with |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
not migrated yet; keep calling |
|
not migrated yet; keep calling it on |
len(prm.dataset), which guessed the number of snapshots from ilast and ioutput, has no equivalent: the lazy dataset lists what is on disk, prm.open_dataset().sizes["t"].
It is a plain xarray.Dataset#
prm.open_dataset() returns an ordinary, lazy xarray.Dataset. The toolbox cannot anticipate every case, so when the defaults do not fit, open with stack=False or with xr.open_mfdataset(..., engine="xcompact3d", prm=prm) and shape the result with xarray itself: xr.concat to stack components along a new dimension, xr.merge and xr.combine_by_coords to join folders or runs, Dataset.stack, rename, assign_coords, chunk, isel/sel, and so on. Everything stays lazy until you compute.
Files in sub-folders#
XCompact3d versions and user cases lay files out differently, so no folder tree is assumed. Declare the ones you have:
ds = prm.open_dataset(
folders={
"xy_planes": {"drop_coords": "z"},
"3d": {},
"geometry": {"static": True},
}
)
Each entry is built from the same parameters with the given overrides, or it can be a ready xarray-binfile convention. On write, an array named geometry/epsilon (through its file_name attribute) goes to that folder.
Static planes from the sandbox#
init_dataset produces inflow planes such as bxx1 on (y, z). prm.write_dataset writes them as static files, like the old writer did, but prm.open_dataset never lists 2D static files: it is a reader for the simulation output. Read a plane with xr.open_dataset(path, engine="xcompact3d", prm=prm, drop_coords="x").
Sandbox and genepsi#
init_epsi, init_dataset and gene_epsi_3d now write through the lazy API and accept an explicit data_path. Without it they default to prm.default_data_path, or to a changed prm.dataset.data_path while that setting exists.
Known differences#
Output names. The old writer accepted any file_prefix and appended the extension when missing, so prm.dataset.write(vort, "w3-mean") or "ux-000.bin" worked. The lazy API derives the separator, step counter and extension from the filename pattern, so a name is a word made of letters, digits and underscores, optionally under sub-folders ("geometry/epsilon"). Other names are rejected with a message saying so: use w3_mean instead of w3-mean, and never include the counter or extension yourself.
Assigning prm.dataset. Still possible (prm.dataset = Dataset(...)), with the same deprecation warning as reading it.
The old writer computed the step of a snapshot as int(t / dt), which truncates (0.3 / 0.1 is 2.999...) and could make two snapshots overwrite each other. The lazy API rounds and refuses values that are not within tolerance of an integer step.