Skip to content

pyflightstream.results.tables (stable)

Generated from the docstrings at build time: every one of the 9 names in the __all__ of pyflightstream.results.tables has an entry below. The names a guide or an example uses come first; the others follow under Advanced.

Tabular views of parsed FlightStream results, on named NumPy columns.

Pipeline role: turns the typed parser outputs of :mod:pyflightstream.results (and, when the optional [fsi] extra is installed, the sectional loads report of :mod:pyflightstream.fsi.loads) into tidy :class:Table tables, then assembles run-level and sweep-level tables by joining the campaign manifest records with the parsed coefficient tables. Tables and the far field rest on NumPy. The explicit Table.to_pandas() adapter requires the optional [pandas] extra. Downstream code should depend on the documented column schema (SRS NFR-19), not on the library holding the values.

Three steps of one ladder:

  1. :func:to_table / :func:to_csv tabulate any single parsed result.
  2. :func:run_table joins one manifest :class:RunRecord (identity, sweep point, versions, outcome) with the run's parsed loads into one wide row; :func:parse_run_loads resolves and parses that loads spreadsheet from the managed workspace through the record's collected outputs.
  3. :func:sweep_table reads a whole campaign manifest and returns the tidy sweep table, one row per run; Table.to_csv then writes the final csv.

EVERY TABLE SAYS WHAT PRODUCED ITS NUMBERS (PFS-2014.05). Each frame these functions build carries data_origin and reduction, and the writer behind :func:to_csv refuses to write one that does not. They are constant columns for a single parsed result and genuinely PER ROW in the sweep table, which is the one file here that mixes provenances: a steady point's coefficients are a direct integration and an unsteady point's are the last time step (RPT-053, "what an unsteady export states, and at which step", 2026-09-19), one instant of a cycle, printed under the same names. The vocabulary and its integer codes live in :mod:pyflightstream.results, one layer below the writers that publish them.

Column names carry units the way the source dataclasses document them: printed coefficient names (Cx .. CMz) with the force_units / moment_units metadata alongside for the loads spreadsheet, dimensionless residuals for the solver log, printed column names for the probe export (X, Y, Z in simulation length units), and unit-suffixed names (offset_m, fx_n_per_m, ...) for the sectional loads, matching :class:SectionalLoadsReport.

The manifest is read only through the public API of :mod:pyflightstream.workspace, and this module imports that layer NOWHERE at runtime: :func:parse_run_loads and :func:sweep_table take a :class:~pyflightstream.workspace.CampaignWorkspace the caller has already constructed. (GEO-060 B1) the module does not name the workspace layer even for the type checker: the annotations read two structural protocols defined HERE, :class:_ManifestRecord and :class:_ManifestWorkspace, which state the handful of attributes this module reads. A TYPE_CHECKING import never executes, but it still records an upward dependency in the type checker's graph, and the matrix reader was held to the same rule (OPS-2007.02.02).

Callers construct CampaignWorkspace(root) and pass that object. Constructing a workspace from a bare path here would introduce an upward dependency from the parsing layer into the execution layer (AD-01).

Used in the guides

pyflightstream.results.tables.sweep_table

sweep_table(
    workspace: _ManifestWorkspace,
    *,
    loads_file: str | None = None,
    require_loads: bool = True,
    matrix_stem: str | None = None,
) -> Table

Assemble the tidy table of a whole campaign sweep.

One row per manifest record, in manifest order: the run identity, sweep point, versions, and outcome of :func:run_table, joined with the Total coefficients of each run's loads spreadsheet resolved through :func:parse_run_loads. Runs without a loads spreadsheet (failed points) keep their identity row with NaN coefficients, so the sweep table always accounts for every executed point. Table.to_csv then writes the final csv; the table states its provenance in its own columns.

Parameters:

Name Type Description Default
workspace CampaignWorkspace

The managed campaign workspace, already constructed. A bare root path is NOT accepted, for the reason :func:parse_run_loads states: pass CampaignWorkspace(root).

required
loads_file str

Exact loads file name per run, forwarded to :func:parse_run_loads; needed when the recipes export more than one file that parses as a loads spreadsheet.

None
require_loads bool

Whether a sweep in which NO run yielded coefficients is an error. True by default, which is the historical behaviour and the right answer for a caller asking for a polar. Pass False where the table is being written as the record of what ran (PFS-2014.03): a campaign whose every point failed still has to leave a file a colleague can open, and raising here would leave nothing to write. The condition is warned about instead, and the identity rows are returned; per-record misses are already tolerated either way, as NaN coefficient rows. A record whose loads cannot be read for another reason (an output no longer on disk, an ambiguous, truncated or wrong-point spreadsheet) raises that error when True and, when False, keeps its NaN row and is warned about by run id.

True
matrix_stem str

The stem of one run matrix of the workspace; the table then holds the records that name it and no other's (PFS-2031.04). A record that names no matrix, written before the field existed or by a campaign authored in Python, is left out rather than counted in every matrix's table. None, the default, tabulates the whole manifest.

None

Returns:

Type Description
Table

The sweep table; sweep point axes are in their sweep units (alpha and beta in deg, advance_ratio dimensionless) and the coefficient columns follow each run's printed units, exposed in the force_units / moment_units columns. Every row also carries data_origin and reduction (PFS-2014.05), which is what lets a mixed steady and unsteady sweep be read without opening another file.

Raises:

Type Description
MalformedOutputError

When the manifest holds no records, or when workspace is a path rather than a constructed :class:~pyflightstream.workspace.CampaignWorkspace.

LoadsNotFoundError

When no successful run yields a coefficient table (which points at a wrong loads_file name) and require_loads is True.

Warns:

Type Description
UserWarning

In the same condition when require_loads is False, and once per record whose loads could not be read.

Examples:

>>> from pyflightstream.results import sweep_table
>>> from pyflightstream.workspace import CampaignWorkspace
>>> table = sweep_table(CampaignWorkspace("campaign"))
>>> table[["run_id", "alpha", "CL"]]

pyflightstream.results.tables.to_table

to_table(result: object) -> Table

Tabulate one parsed FlightStream result as a tidy NumPy-backed table.

Dispatches on the parsed result type:

  • :class:LoadsReport (:func:parse_loads): one row per surface plus the Total row, columns surface, the printed coefficient names (Cx, Cy, Cz, CL, CDi, CDo, CMx, CMy, CMz), and the constant force_units / moment_units metadata columns; force and moment values follow those printed units, in the analysis frame named by the report.
  • list of :class:ResidualSample (:func:parse_residual_history): columns iteration, velocity_residual, pressure_residual (dimensionless), velocity_overflowed and pressure_overflowed (bool, True where the solver printed that residual as asterisks).
  • :class:ProbePointsReport (:func:parse_probe_points): the printed columns, starting with X, Y, Z in simulation length units in the analysis reference frame.
  • :class:UnsteadyPlotsReport (:func:parse_unsteady_plots): one row per time step and one column per plot, under the plot names exactly as printed. Units are per column and the export declares none, so nothing is converted here; the time column is in the unit the run's time increment is stated in.
  • :class:ForceDistributionReport (:func:~pyflightstream.results.parse_force_distributions): one row per panel, columns :data:~pyflightstream.results.FORCE_DISTRIBUTION_COLUMNS with Boundary as an integer index, plus the constant force_units / moment_units metadata.
  • :class:OffBodyStreamlinesReport (:func:~pyflightstream.results.parse_off_body_streamlines): one row per point of every streamline, keyed by a leading streamline column, then :data:~pyflightstream.results.OFF_BODY_STREAMLINE_COLUMNS.
  • :class:SurfaceSectionsReport (:func:~pyflightstream.results.parse_surface_sections, for both surface-section commands): one row per cut point of every section, keyed by a leading section column, then :data:~pyflightstream.results.SURFACE_SECTION_COLUMNS.
  • :class:SweepSpreadsheetReport (:func:~pyflightstream.results.parse_sweep_spreadsheet): one row per sweep point, columns :data:~pyflightstream.results.SWEEP_COLUMNS plus the printed units.
  • :class:SolverAnalysisCsvReport (:func:~pyflightstream.results.parse_solver_analysis_csv): x, y, z, scalar and scalar_field, the last naming what the scalar is, because that export prints no header and the file cannot say.

Those five carry PINNED columns: the layout is the solver's rather than the run's, so a report whose columns have moved is refused here as well as at parse time, instead of being tabulated with each value under its neighbour's label.

  • SectionalLoadsReport (:mod:pyflightstream.results.sectional_loads, re-exported by :mod:pyflightstream.fsi.loads): unit-suffixed columns offset_m, chord_m, x_qc_m, z_qc_m [m], fx_n_per_m, fz_n_per_m [N/m], moment_qc_nm_per_m [N m / m, the export's Moment, whose point the definitions page states], in the cut-plane axes the FSI parser documents.

Every one of them also carries the three provenance columns (PFS-2014.05, PFS-2014.03): data_origin, raw for anything read off a solver export; reduction_window, not_applicable where nothing was averaged, last_time_step on an unsteady export, and unknown where the mode itself never printed; and reduction, which is none where nothing was averaged, last_step on an unsteady export, which states the last time step only, and unknown where the file printed no solver mode to decide it by. time_average with not_printed is what files written in legacy releases carry on an unsteady export.

Parameters:

Name Type Description Default
result object

One parsed result of the kinds above.

required

Returns:

Type Description
Table

Tidy table, one observation per row; write it with :func:to_csv.

Raises:

Type Description
MalformedOutputError

If a report with pinned columns carries other columns than the solver's layout.

UnsupportedResultTypeError

If result is not one of the kinds above.

Examples:

>>> from pyflightstream.results import ResidualSample, to_table
>>> table = to_table([ResidualSample(1, 0.01, 0.02)])
>>> table["iteration"].tolist()
[1]

Advanced

pyflightstream.results.tables.AmbiguousLoadsError

Bases: PyflightstreamError, ValueError

Several collected outputs of one run parse as loads spreadsheets.

The resolver refuses to guess which table is the run's coefficient evidence; pass loads_file with the exact exported file name.

pyflightstream.results.tables.LoadsNotFoundError

Bases: PyflightstreamError, ValueError

No collected output of a run yields its loads spreadsheet.

Expected for failed points: a run that stopped before EXPORT_SOLVER_ANALYSIS_SPREADSHEET leaves no coefficient table behind, and :func:sweep_table turns this into a row without coefficient columns instead of dropping the run.

pyflightstream.results.tables.Table

Table(data=None, columns=None)

Ordered, equal-length named NumPy columns of parsed results.

Select a column by name, several columns by a list of names, or rows by a boolean mask. to_dict('records') returns plain row dictionaries. to_csv writes CSV without an optional dependency; to_pandas is the explicit adapter provided by the [pandas] extra.

Parameters:

Name Type Description Default
data mapping, sequence of mappings or two-dimensional array

Column values, row records or a numeric matrix.

None
columns sequence of str

Column order, required for a matrix.

None

columns property

columns

Column names in insertion order.

shape property

shape

Number of rows and columns.

empty property

empty

Whether either dimension is empty.

iloc property

iloc

Positional row selection; a scalar row is a mapping.

loc property

loc

Boolean row selection, optionally followed by a column: loc[mask, "CL"].

assign

assign(**columns)

Return a copy with the supplied columns.

rename

rename(*, columns)

Return a copy with column names mapped by a dict or transformed by a callable.

map

map(function)

Return a copy with a callable applied to every cell.

to_numpy

to_numpy()

Return the columns as a two-dimensional array.

to_dict

to_dict(orient='records')

Return plain row dictionaries in table order (records orientation).

to_pandas

to_pandas() -> pd.DataFrame

Return the equivalent DataFrame, requiring the optional pandas extra.

to_csv

to_csv(
    path_or_buf=None,
    *,
    index=True,
    lineterminator=_textio.LINE_END,
    na_rep="",
    header=True,
)

Write CSV to a path or text stream, or return CSV text when no path is given.

pyflightstream.results.tables.parse_run_loads

parse_run_loads(
    workspace: _ManifestWorkspace,
    record: _ManifestRecord | str,
    *,
    loads_file: str | None = None,
) -> LoadsReport

Resolve and parse the loads spreadsheet of one recorded run.

The record's collected outputs (paths relative to its managed simulation folder) are the only search space: run evidence lives where the manifest says it does, never where a folder name suggests. Without loads_file every collected output is tried and exactly one must parse as a loads spreadsheet. The parsed conditions are cross-checked against the record's sweep point (alpha and beta in deg), so a same-named export overwritten by a later point of the same simulation is refused instead of silently standing in for this run's coefficients.

Parameters:

Name Type Description Default
workspace CampaignWorkspace

The managed campaign workspace, already constructed. A bare root path is NOT accepted: taking one made this layer import the layer above it to build the workspace, which is the upward dependency AD-01 forbids. Pass CampaignWorkspace(root).

required
record RunRecord or str

The manifest record, or its run_id to look up in the manifest.

required
loads_file str

File name of the loads spreadsheet among the collected outputs, or the recorded path of one of them when several share the name; required when several outputs parse as loads tables.

None

Returns:

Type Description
LoadsReport

The parsed spreadsheet; the version printed in its footer is cross-checked against the version the run requested (FR-18).

Raises:

Type Description
LoadsNotFoundError

When no collected output yields a loads spreadsheet (the normal outcome of a failed point).

AmbiguousLoadsError

When several collected outputs parse as loads spreadsheets and loads_file does not single one out, or when loads_file names several outputs.

MalformedOutputError or IncompleteOutputError

When an output that opens as a loads spreadsheet (its Surface, header within its first kilobytes) is malformed or truncated: it is refused with that reason, never skipped as another file.

FileNotFoundError

When a recorded output is no longer on disk, for example after the simulation folder was archived.

MalformedOutputError

When workspace is a path rather than a constructed :class:~pyflightstream.workspace.CampaignWorkspace.

pyflightstream.results.tables.run_table

run_table(
    record: _ManifestRecord,
    *,
    loads: LoadsReport | None = None,
) -> Table

Join one manifest record with its parsed loads into one wide row.

The row carries the run identity and conditions from the manifest (POL first, the polar the run belongs to under the name the run matrix gives its polar column, then run_id, sim_id, the data_origin and reduction pair of PFS-2014.05, the sweep point axes in their sweep units: alpha and beta in deg, advance_ratio dimensionless), the recorded versions and outcome (fs_version_requested, fs_version_reported, fs_build, package_version, status, iterations, residual, wall_time_s in s), and, when loads is given, the analysis frame, the force_units / moment_units metadata, and the Total row coefficients under their printed names in those printed units.

Parameters:

Name Type Description Default
record RunRecord

One manifest record, read through :meth:pyflightstream.workspace.CampaignWorkspace.read_manifest.

required
loads LoadsReport

The run's parsed loads spreadsheet, for example from :func:parse_run_loads; None keeps the identity and outcome columns only, which is how failed points appear in a sweep.

None

Returns:

Type Description
Table

One row; missing numeric outcomes are NaN.

pyflightstream.results.tables.superseded_by_a_continuation

superseded_by_a_continuation(
    records: Iterable[_ManifestRecord],
) -> dict[str, str]

Return the runs a later run CONTINUED, each mapped to the run that continued it.

A continuation archives the contents of the point's folder and writes into that same folder, and a record is never rewritten, so the stopped run's outputs go on naming files its continuation wrote. Read through that record, the point appears twice with the continuation's numbers. The continuation states which run it continues (continues) and that statement is the ONLY thing read here: two runs that merely resemble each other are both kept. A record written in legacy releases states nothing and is never dropped.

Parameters:

Name Type Description Default
records iterable of manifest records

The run records of a workspace, each with a run_id and, for a continuation, the continues it states.

required

Returns:

Type Description
dict of str to str

Each continued run's id mapped to the id of the run that continued it.

pyflightstream.results.tables.to_csv

to_csv(
    result: object,
    path: str | Path,
    *,
    overwrite: bool = False,
) -> Path

Write one parsed FlightStream result as a csv file.

The tidy table of :func:to_table is written without the positional index, so the csv holds exactly the documented columns in their documented units, plus the data_origin and reduction columns every file this package writes carries (PFS-2014.05). It is the one write path of a parsed result, so a table that cannot say what produced its numbers is refused here too.

Parameters:

Name Type Description Default
result object

One parsed result of the kinds :func:to_table covers.

required
path str or Path

Target csv file; its parent folder must exist.

required
overwrite bool

Whether an existing file may be replaced; False by default, so a product is never replaced by accident.

False

Returns:

Type Description
Path

The written file.

Examples:

>>> import tempfile
>>> from pathlib import Path
>>> from pyflightstream.results import parse_unsteady_plots
>>> text = "Time (sec), CL\n.000, +2.3500000E-3,\n.004, +2.1000000E-3,\n"
>>> text += "------------\nSoftware : Flightstream version 26.1, build #7012026\n"
>>> report = parse_unsteady_plots(text)
>>> with tempfile.TemporaryDirectory() as folder:
...     written = to_csv(report, Path(folder) / "plots.csv")
...     header = written.read_text(encoding="utf-8").splitlines()[0]
>>> header.split(',')[:2]
['Time (sec)', 'CL']