Skip to content

pyflightstream.post.settings_table (stable)

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

The optional all-numeric projection of a solver-setup snapshot.

Pipeline role: a projection FOR TOOLS, never the record. The settings record PFS-2012.11 writes beside every result is strings and mixed types, which a plotting script or a spreadsheet cannot treat as data. This module turns one or more snapshots into a table holding nothing but numbers, so those tools can read it, and it is lossy by construction, which is why it is optional and never replaces the full record.

THE MEASUREMENT THE LAYOUT RESTS ON. Across the sixty-five flags of a bare snapshot on 26.120 the value field holds FIVE Python types: fifty-seven None, two int, four float, one str and one list. One column cannot carry that and stay numeric.

THE RULE: A SENTINEL MAY ONLY APPEAR IN A COLUMN WHOSE DOMAIN WE CONTROL. The code columns are assigned here, densely from 1, so 999 is free in them by construction. The value columns are not ours: they carry iteration counts, angles and boundary indices, any of which can legitimately be 999. Carrying the value AND whether we know it in one cell is the collision; separating them is the whole fix, and unknown stops being a magic number and becomes the provenance code it always was.

THE CODEBOOK IS FROZEN AND ITS HOME IS THE PAGE. docs/settings-codebook.md carries the flag ids, the provenance and kind codes and the per-flag enumerations, and tests/tier1_offline/test_settings_codebook.py reads that page and fails when this module disagrees with it. That direction is deliberate: if the only thing holding the encoding still were a page describing the code, the two would drift the first time a flag gained a state, and every file written in between would be misread from then on.

FLAG IDS ARE APPENDED, NEVER DERIVED. FLAG_SPECS grows whenever a registered build adds a settings command, and it grows in the MIDDLE: its order is the helper's emission order, not an arrival order. An id read off a position there would renumber half the codebook on the next build. So the order below is frozen literally, and a new flag takes the next unused id in the same commit that moves the page.

Advanced

pyflightstream.post.settings_table.CODEBOOK_VERSION module-attribute

CODEBOOK_VERSION = 1

pyflightstream.post.settings_table.ENUMERATIONS module-attribute

ENUMERATIONS: Mapping[str, tuple[str, ...]] = (
    MappingProxyType(
        {
            "SET_BOUNDARY_LAYER_TYPE": (
                "LAMINAR",
                "TRANSITIONAL",
                "TURBULENT",
            ),
            "SET_SOLVER_MODEL": (
                "INCOMPRESSIBLE",
                "SUBSONIC",
                "TRANSONIC",
                "LOW_ORDER_SUPERSONIC",
            ),
            "AEROELASTIC_RBF_TYPE": (
                "WENDLAND_C2",
                "GAUSSIAN",
                "THIN_PLATE_SPLINE",
                "MULTI_QUADRATIC",
                "INV_MULTI_QUADRATIC",
            ),
            "SET_VISCOUS_EXCLUDED_BOUNDARIES": ("all",),
            "SET_THIN_BOUNDARIES": ("all",),
            "SET_AXIAL_SEPARATION_BOUNDARIES": ("all",),
            "SET_VALAREZO_SEPARATION_BOUNDARIES": ("all",),
            "SET_CROSSFLOW_SEPARATION_BOUNDARIES": ("all",),
            "SET_VORTICITY_DRAG_BOUNDARIES": ("all",),
            "DELETE_SEPARATION": ("all",),
        }
    )
)

pyflightstream.post.settings_table.FLAG_IDS module-attribute

FLAG_IDS: Mapping[str, int] = MappingProxyType(
    {
        name: index
        for index, name in enumerate(_FROZEN_ORDER, start=1)
    }
)

pyflightstream.post.settings_table.LOSSY_KINDS module-attribute

LOSSY_KINDS: tuple[str, ...] = ('list', 'mapping')

pyflightstream.post.settings_table.PROVENANCE_CODES module-attribute

PROVENANCE_CODES: Mapping[str, int] = MappingProxyType(
    {"explicit": 1, "default": 2, "unknown": 3}
)

pyflightstream.post.settings_table.TIDY_COLUMNS module-attribute

TIDY_COLUMNS: tuple[str, ...] = (
    "codebook_version",
    "run_index",
    "flag_id",
    "provenance_code",
    "emitted",
    "value_kind",
    "value_num",
    "value_code",
    "value_count",
)

pyflightstream.post.settings_table.VALUE_KINDS module-attribute

VALUE_KINDS: Mapping[str, int] = MappingProxyType(
    {
        "bool": 1,
        "int": 2,
        "float": 3,
        "enumerated": 4,
        "list": 5,
        "mapping": 6,
    }
)

pyflightstream.post.settings_table.codebook

codebook() -> dict[str, object]

Return the legend written beside every table.

The file has to be readable alone, so its legend travels with it rather than living only on the documentation page. The page is still the contract, and the test that compares the two is what keeps this dictionary from becoming a second opinion.

Returns:

Type Description
dict

codebook_version, flag_ids, provenance_codes, value_kinds, enumerations, lossy_kinds and tidy_columns.

pyflightstream.post.settings_table.read_settings_table

read_settings_table(path: str | Path) -> list[Row]

Read a numeric settings table, refusing another codebook.

Parameters:

Name Type Description Default
path str or Path

A file written by :func:write_settings_table.

required

Returns:

Type Description
list of dict

The rows, with every cell that does not apply as None and every other cell of the codebook's columns as a number (a key column that write_settings_table was given, POL for one, stays text). A cell does not apply when it reads NA, which is what this writer emits; an EMPTY cell and the literal "NA" are both accepted and both come back as None, so a table written by any earlier release still reads.

Raises:

Type Description
MalformedOutputError

If the file carries no codebook_version column, or names a codebook other than :data:CODEBOOK_VERSION. It is REFUSED rather than resolved, because the one thing a reader must never do with an older encoding is reinterpret it silently: an id that moved makes every row of the file describe a different flag. Also if the header names a column twice, or a numeric cell is not a finite number.

pyflightstream.post.settings_table.settings_table

settings_table(
    setups: Sequence[SolverSetup],
    *,
    wide: bool = False,
    fill: int | None = None,
    fill_values: bool = False,
) -> list[Row]

Project solver-setup snapshots into an all-numeric table.

Parameters:

Name Type Description Default
setups sequence of SolverSetup

One snapshot per run, in the order the runs are to be indexed. run_index is the 0-based position in this sequence.

required
wide (bool, keyword - only)

One row per run instead of one row per run and flag. Each flag contributes f<id>_value, f<id>_prov and f<id>_kind. The kind distinguishes enumeration codes from list lengths for boundary flags that accept either all or a list of boundaries. The code meanings remain those of codebook version 1.

False
fill int

NUMERIC value written into a CODE column that does not apply, for a tool that needs a number there rather than a token. 999 is the conventional choice and is free by construction, because the code columns are assigned densely from 1. Default None, which writes :data:~pyflightstream.post.products.NOT_APPLICABLE.

Use fill when a tool requires numeric code columns rather than NA. The wide form fills only an absent f<id>_kind, never f<id>_value.

None
fill_values (bool, keyword - only)

Ask for the VALUE columns to be filled too. Always refused, naming the flags whose legal range contains the fill value.

False

Returns:

Type Description
list of dict

Rows keyed by column label. Every cell is an int, a float or None; no cell is a string.

Raises:

Type Description
ProductError

If fill_values is asked for, or fill is not a whole number or equals a code the codebook assigns.

MalformedOutputError

If a flag holds a token the frozen codebook does not code, or a type this projection has no kind for.

Examples:

>>> from pyflightstream.post.settings_table import FLAG_IDS, settings_table
>>> from pyflightstream.script import Script, helpers
>>> setup = helpers.solver_settings(Script(version="26.120"), velocity=30.0)
>>> rows = {row["flag_id"]: row for row in settings_table([setup])}
>>> rows[FLAG_IDS["SOLVER_SET_VELOCITY"]]["value_num"]
30.0
>>> rows[FLAG_IDS["SOLVER_SET_AOA"]]["provenance_code"]
3

pyflightstream.post.settings_table.write_settings_table

write_settings_table(
    path: str | Path,
    setups: Sequence[SolverSetup],
    *,
    wide: bool = False,
    fill: int | None = None,
    fill_values: bool = False,
    overwrite: bool = False,
    legend: str | Path | None = None,
    keys: Sequence[Mapping[str, str]] | None = None,
) -> tuple[Path, Path]

Write the numeric table and its legend, and return the pair.

Parameters:

Name Type Description Default
path str or Path

Destination CSV file. The legend is written beside it as <name>.codebook.json, <name> being the file name with its extension, unless legend names it.

required
setups sequence of SolverSetup

One snapshot per run.

required
wide see :func:`settings_table`

Passed through unchanged.

False
fill see :func:`settings_table`

Passed through unchanged.

False
fill_values see :func:`settings_table`

Passed through unchanged.

False
overwrite (bool, keyword - only)

Replace existing files. Default False, the same refusal the flow-visualization writers take.

False
legend str or Path

Where the legend is written, when it is not <name>.codebook.json beside the table (the campaign post names it <matrix>_settings.codebook.json).

None
keys sequence of mapping

One mapping of text cells per run, in the order of setups, all with the same keys (for the campaign post, POL and RUN_ID). Their columns OPEN the table, before codebook_version, because the numeric columns say nothing of which run a row is; None writes the table as it was. It needs wide=True, since a long-form row is a setting of a run rather than a run.

None

Returns:

Type Description
tuple of pathlib.Path

(table, legend).

Raises:

Type Description
OutputExistsError

If either file exists and overwrite is False.

ProductError

As :func:settings_table; also if keys is given without wide, does not hold one mapping per run, or holds mappings of different keys, or if the legend path is the table path.

MalformedOutputError

As :func:settings_table.