pyflightstream.post.writers (stable)¶
Generated from the docstrings at build time: every one of the 9 names in the __all__ of pyflightstream.post.writers has an entry below. The names a guide or an example uses come first; the others follow under Advanced.
Flow-visualization writers: probe data to VTK and Tecplot files.
Pipeline role: turns probe positions plus sampled fields into files
ParaView (VTK legacy ASCII polydata) and Tecplot (ASCII POINT zone)
open directly, so any probe survey (planar grid, cylindrical
lattice, or parsed solver export) becomes inspectable flow-vis data.
The writers are deterministic (fixed %.9e formatting, fixed field
order) so outputs are diffable and goldens are exact, the same policy
as the STL writer of the QA geometry.
Scalars are (n,) arrays; a (n, 3) array is written as a
vector field. Field units are whatever the caller sampled; the
writers never rescale.
EVERY FILE CARRIES WHAT PRODUCED IT (PFS-2012.11). Coordinates, field
blocks and a title alone cannot identify the settings that produced the
numbers. Carry that context with the export so it remains interpretable
apart from the campaign's runs.json.
Neither format has a place for a sixty-five-flag record, so the record
goes BESIDE the file, named after it, as
<name>.provenance.json, and each writer returns the PAIR. The pair
is the deliverable: a data file without its record is half of one, which
is why provenance is a required keyword rather than an option.
The record is complete rather than tidy. Every flag of
:data:~pyflightstream.script.solver_setup.FLAG_SPECS appears, and a
flag nobody has established for that build appears with provenance
unknown and a null value rather than being left out. On a bare
26.120 call that is fifty-seven of sixty-five, which looks like a poor
record and is an honest one: "no evidence exists for this build" and
"this flag does not exist" are different facts, and a reader has to be
able to tell which one the file means (FR-22c, FR-31).
Advanced¶
pyflightstream.post.writers.OutputExistsError
¶
Bases: ProductExistsError, FileExistsError
A flow-visualization file would be overwritten (PFS-2011.02).
Both writers ended in an unconditional write_text, so a second
call with the same destination replaced the first silently. That is
the same class as the campaign defect PYFS-005 records: one point of
a run overwrote another's output while the record listed both
complete, which cost licensed solver time and could have published a
report from one point counted twice.
overwrite=True is the only way through and each writer's
docstring says so.
It keeps FileExistsError as its second base for the reason FR-39
gives for every catalogued class: an existing except
FileExistsError around a write catches exactly what it caught
before, and it is the handler a caller writing a file already has.
The evidence writers under qa raise the BUILTIN for the same
situation, deliberately, because that predates the catalogue's reach;
a new raise site takes the catalogued type.
It is also a :class:~pyflightstream._errors.ProductExistsError, the class the
product writers raise for the same situation, so one handler catches both
(the decision of PFS-2124.037: the two classes signal one condition).
pyflightstream.post.writers.OutputProvenance
¶
Bases: BaseModel
Where one post-processing file's numbers came from.
The minimum a reader needs to say what produced a file, with the
file in hand and nothing else: which run wrote it, which campaign
that run belongs to, and the complete solver-flag snapshot of the
script that ran (:class:~pyflightstream.script.solver_setup.SolverSetup).
The FlightStream version is not a field of its own: it is
setup.fs_version, the version the per-version defaults in the
snapshot were resolved against, and a second copy could disagree
with it.
Attributes:
| Name | Type | Description |
|---|---|---|
run_id |
str
|
Identity of the run, in the campaign's own vocabulary
( |
campaign |
(str, optional)
|
Campaign name, when the file belongs to one. None for a standalone survey written outside a campaign, which is a real case and not a missing value. |
setup |
SolverSetup
|
The solver-flag snapshot of the script that produced the data. |
Examples:
>>> from pyflightstream.post import OutputProvenance
>>> from pyflightstream.script import Script, helpers
>>> script = Script(version="26.120")
>>> setup = helpers.solver_settings(script, velocity=30.0)
>>> provenance = OutputProvenance(run_id="polar/sim_1/a+00.0", setup=setup)
>>> provenance.fs_version
'26.120'
fs_version
property
¶
fs_version: str
Canonical FlightStream version the snapshot was resolved against.
pyflightstream.post.writers.PROVENANCE_SCHEMA
module-attribute
¶
PROVENANCE_SCHEMA = 'pyfs-output-provenance/1'
pyflightstream.post.writers.PROVENANCE_SUFFIX
module-attribute
¶
PROVENANCE_SUFFIX = '.provenance.json'
pyflightstream.post.writers.provenance_path
¶
provenance_path(destination: str | Path) -> Path
Return the settings record that describes destination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destination
|
str or Path
|
A file one of this module's writers wrote or will write. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The record beside it, its full name plus
:data: |
Examples:
>>> from pyflightstream.post.writers import provenance_path
>>> provenance_path("survey/ring.vtk").name
'ring.vtk.provenance.json'
pyflightstream.post.writers.settings_records
¶
settings_records(setup: SolverSetup) -> list[FlagRecord]
Return one record per snapshot flag, in FLAG_SPECS order.
Completeness is enforced here rather than trusted: a snapshot that
carries fewer flags than the library knows about is completed with
unknown records, so the written file names every flag. Silence
about a flag is the one thing this record may not do, because a
reader cannot distinguish silence from absence.
A flag the snapshot carries and FLAG_SPECS does not know about is
appended after the known set rather than dropped: it means the
snapshot was written by a newer library, and dropping it would make
this reader the thing that lost the fact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup
|
SolverSetup
|
The snapshot to render. |
required |
Returns:
| Type | Description |
|---|---|
list of FlagRecord
|
One record per flag, known flags first in emission order. |
pyflightstream.post.writers.write_output_pair
¶
write_output_pair(
destination: Path,
text: str,
provenance: OutputProvenance,
*,
overwrite: bool,
) -> tuple[Path, Path]
Write the data file and its settings record, or neither.
Both destinations are tested BEFORE either is written, so a refusal never leaves half a pair behind: a data file whose record belongs to a different run is worse than no file at all. The folders of both are created after those checks, as every writer of this package does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destination
|
Path
|
The data file. |
required |
text
|
str
|
The data file's text. |
required |
provenance
|
OutputProvenance
|
The settings record written beside it. |
required |
overwrite
|
bool
|
Replace files that exist. |
required |
Returns:
| Type | Description |
|---|---|
tuple of (Path, Path)
|
The data file and its record. |
Raises:
| Type | Description |
|---|---|
OutputExistsError
|
If either file exists and |
pyflightstream.post.writers.write_tecplot_points
¶
write_tecplot_points(
path: str | Path,
points: ndarray,
fields: Mapping[str, ndarray] | None = None,
*,
provenance: OutputProvenance,
title: str = "pyflightstream probe data",
zone: str = "probes",
overwrite: bool = False,
) -> tuple[Path, Path]
Write probe data as a Tecplot ASCII ordered POINT zone.
Vector fields expand into three variables with _x/_y/_z
suffixes, following the Cartesian axis naming of the writers'
coordinate columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Destination |
required |
points
|
ndarray
|
Probe positions, shape |
required |
fields
|
mapping of str to numpy.ndarray
|
Per-probe data: |
None
|
provenance
|
(OutputProvenance, keyword - only)
|
Run identity and the solver-flag snapshot that produced the
numbers, written beside the output as
|
required |
title
|
str
|
TITLE record. |
'pyflightstream probe data'
|
zone
|
str
|
Zone name. |
'probes'
|
overwrite
|
(bool, keyword - only)
|
Replace an existing destination. Default False, for the same
reason as its sibling: this writer also ended in an
unconditional |
False
|
Returns:
| Type | Description |
|---|---|
tuple of pathlib.Path
|
|
Raises:
| Type | Description |
|---|---|
OutputExistsError
|
If either the destination or its record exists and
|
ValueError
|
If |
ProductError
|
If two variables would carry the same name. It is a |
pyflightstream.post.writers.write_vtk_points
¶
write_vtk_points(
path: str | Path,
points: ndarray,
fields: Mapping[str, ndarray] | None = None,
*,
provenance: OutputProvenance,
title: str = "pyflightstream probe data",
overwrite: bool = False,
) -> tuple[Path, Path]
Write probe data as a VTK legacy ASCII polydata file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Destination |
required |
points
|
ndarray
|
Probe positions, shape |
required |
fields
|
mapping of str to numpy.ndarray
|
Per-probe data: |
None
|
provenance
|
(OutputProvenance, keyword - only)
|
Run identity and the solver-flag snapshot that produced the
numbers. REQUIRED, and required rather than defaulted for the
reason PFS-2012.11 gives: an optional record is absent exactly
where it matters, on the run nobody thought about while writing
the call. It is written beside the output as
|
required |
title
|
str
|
VTK header title line. |
'pyflightstream probe data'
|
overwrite
|
(bool, keyword - only)
|
Replace an existing destination. Default False, and the default
is the point: this writer ended in an unconditional
|
False
|
Returns:
| Type | Description |
|---|---|
tuple of pathlib.Path
|
|
Raises:
| Type | Description |
|---|---|
OutputExistsError
|
If either the destination or its record exists and
|
ValueError
|
If |
Examples:
>>> import numpy as np
>>> from pyflightstream.post import OutputProvenance, write_vtk_points
>>> from pyflightstream.script import Script, helpers
>>> script = Script(version="26.120")
>>> setup = helpers.solver_settings(script, velocity=30.0)
>>> points = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]])
>>> import tempfile, pathlib
>>> folder = pathlib.Path(tempfile.mkdtemp())
>>> output, record = write_vtk_points(
... folder / "probes.vtk",
... points,
... {"cp": np.array([1.0, -0.5])},
... provenance=OutputProvenance(run_id="polar/sim_1/a+00.0", setup=setup),
... )
>>> record.name
'probes.vtk.provenance.json'