Skip to content

pyflightstream.cases.corrections (provisional)

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

The quasi-steady wheel's correction routes: the pproc's choice and the calibration file.

A quasi-steady WHEEL solves every blade once per clocking and reads its unsteady content (0P, 1P) off the samples. Its loads carry no wake lag, so The package ships the MACHINE that applies a correction beside the raw products, and no correction of its own: every route is OFF by default, NOT VALIDATED, and the choice of a recommended route and of its numbers is research's.

The routes, as the pproc's [qsteady_correction] table names them:

  • route = "none", the default: nothing is corrected and nothing is written.
  • route = "table" (route 4): a calibration TABLE, a discrepancy surface the user fitted, over the axes J, ALPHA and K_1P.
  • route = "sector_offset" (route 2): a 0P offset calibrated from an axial unsteady SECTOR run at the same J; the file names that run (source_run_id).
  • The Theodorsen and Sears lift deficiency (route 1) is refused as a route and offered only as a DIAGNOSTIC (diagnostic = "theodorsen"): it is not validated against the unsteady solver, so the package writes it beside the harmonics and applies it to nothing.
  • A skewed-wake or dynamic-inflow model (route 3: dynamic_inflow, skewed_wake, pitt_peters, coleman) is refused: its double counting with the solver's own wake is unmeasured.

The calibration file is inputs/calibrations/<id>.toml::

route = "table"

[[rows]]
COMPONENT = "THRUST"
J = 0.6
ALPHA = 0.0
K_1P = 0.05
OFFSET_0P = 0.0
GAIN_0P = 1.0
GAIN_1P = 1.0
PHASE_1P_DEG = 0.0

Each row names a COMPONENT (:data:COMPONENTS), its place on the three axes (:data:AXES) and the four coefficients (:data:COEFFICIENT_COLUMNS). The rows of one component form a TENSOR GRID over the axes whose values vary; an axis with one value is constant, and constrains nothing. Inside the grid the coefficients are interpolated multilinearly; a point OUTSIDE it is never extrapolated (:meth:Calibration.lookup says so and the post names the skip).

A file that cannot be read is refused WHOLE at load by :class:CalibrationError, naming the line: an unknown route, an unknown component or column, a missing column, a duplicate row, a set of rows that is not a grid, a number that is not finite. The model lives in the cases row so the plan validates the file a row's pproc names before the run, and the post, which applies it, reads the same model.

This module imports nothing from the package but the floor.

Advanced

pyflightstream.cases.corrections.AXES module-attribute

AXES: tuple[str, ...] = ('J', 'ALPHA', 'K_1P')

pyflightstream.cases.corrections.CALIBRATIONS_DIR module-attribute

CALIBRATIONS_DIR = 'calibrations'

pyflightstream.cases.corrections.CALIBRATION_ROUTES module-attribute

CALIBRATION_ROUTES: tuple[str, ...] = (
    "table",
    "sector_offset",
)

pyflightstream.cases.corrections.COEFFICIENT_COLUMNS module-attribute

COEFFICIENT_COLUMNS: tuple[str, ...] = (
    "OFFSET_0P",
    "GAIN_0P",
    "GAIN_1P",
    "PHASE_1P_DEG",
)

pyflightstream.cases.corrections.COMPONENTS module-attribute

COMPONENTS: tuple[str, ...] = (
    *ROTOR_COMPONENTS,
    *SECTION_COMPONENTS,
)

pyflightstream.cases.corrections.CORRECTION_ROUTES module-attribute

CORRECTION_ROUTES: tuple[str, ...] = (
    "none",
    "table",
    "sector_offset",
)

pyflightstream.cases.corrections.Calibration dataclass

Calibration(
    calibration_id: str,
    route: str,
    rows: tuple[CalibrationRow, ...],
    grids: Mapping[str, ComponentGrid],
    sha256: str,
    path: Path | None = None,
    source_run_id: str | None = None,
    wheel_run_id: str | None = None,
    description: str | None = None,
    notes: tuple[str, ...] = (),
)

A calibration file as read: its route, its runs, its rows and each component's grid.

components property

components: tuple[str, ...]

The components the file corrects, in the order of :data:COMPONENTS.

lookup

lookup(
    component: str, at: Mapping[str, float | None]
) -> Lookup | None

Return the grid's coefficients for component at at; None where it has no rows.

Examples:

>>> text = calibration_text("table", [
...     CalibrationRow("THRUST", 0.5, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0),
...     CalibrationRow("THRUST", 0.7, 0.0, 0.0, 3.0, 1.0, 1.0, 0.0),
... ])
>>> found = parse_calibration(text).lookup("THRUST", {"J": 0.6})
>>> round(found.coefficients[0], 12), found.cell["J"]
(2.0, [0.5, 0.7])

pyflightstream.cases.corrections.CalibrationError

CalibrationError(
    message: str,
    *,
    path: Path | None = None,
    line: int | None = None,
)

Bases: PyflightstreamError, ValueError

A calibration file cannot be read, or cannot be built from the runs it names.

Raised whole at load, naming the file and the line: nothing of a file that is refused is applied. (The pproc's [qsteady_correction] table is refused by its own model, as every pproc table is.) path is the file (None for text parsed with no file) and line the 1-based line the refusal points at, None where the whole file is at fault.

pyflightstream.cases.corrections.CalibrationRow dataclass

CalibrationRow(
    component: str,
    j: float,
    alpha_deg: float,
    k_1p: float,
    offset_0p: float,
    gain_0p: float,
    gain_1p: float,
    phase_1p_deg: float,
    line: int | None = None,
)

One row of a calibration file: a component, its place on the axes, its coefficients.

axis

axis(name: str) -> float

Return the row's value on the axis name of :data:AXES.

coefficients

coefficients() -> tuple[float, float, float, float]

Return (OFFSET_0P, GAIN_0P, GAIN_1P, PHASE_1P_DEG).

pyflightstream.cases.corrections.ComponentGrid dataclass

ComponentGrid(
    component: str,
    values: Mapping[str, tuple[float, ...]],
    nodes: Mapping[tuple[float, ...], CalibrationRow],
)

The tensor grid of one component: the values of each axis and a row at every node.

varying property

varying: tuple[str, ...]

The axes with more than one value, in the order of :data:AXES.

lookup

lookup(at: Mapping[str, float | None]) -> Lookup

Interpolate the coefficients multilinearly at at, never outside the grid.

pyflightstream.cases.corrections.DIAGNOSTICS module-attribute

DIAGNOSTICS: tuple[str, ...] = ('none', 'theodorsen')

pyflightstream.cases.corrections.Lookup dataclass

Lookup(
    coefficients: tuple[float, float, float, float] | None,
    cell: Mapping[str, list[float]],
    reason: str | None = None,
    outside: bool = False,
)

What a grid gives at one point: the coefficients and the cell, or why it gives none.

coefficients is (OFFSET_0P, GAIN_0P, GAIN_1P, PHASE_1P_DEG), None where the point is outside the grid or states no value on an axis that varies; cell maps each axis to the grid values bracketing the point ([low, high]) or to the one value of a constant axis; reason says why there are no coefficients.

pyflightstream.cases.corrections.QsteadyCorrectionSpec

Bases: BaseModel

The [qsteady_correction] table: which correction a quasi-steady wheel's post applies.

Every route is off by default and NOT VALIDATED. A route names a calibration file of inputs/calibrations/; the post writes each corrected product beside its raw file as <name>_corrected.csv and never over it. Read again by pyfs-matrix post, so choosing or changing a route needs no new run. The Theodorsen lift deficiency is a diagnostic and never a route; a skewed-wake or dynamic-inflow route is refused.

Examples:

>>> QsteadyCorrectionSpec().route, QsteadyCorrectionSpec().diagnostic
('none', 'none')
>>> QsteadyCorrectionSpec(route="table", file="c001").file
'c001'
>>> QsteadyCorrectionSpec(route="table", file="c001.toml").file
'c001'

pyflightstream.cases.corrections.ROTOR_COMPONENTS module-attribute

ROTOR_COMPONENTS: tuple[str, ...] = (
    "THRUST",
    "TORQUE",
    "FX",
    "FY",
    "FZ",
    "MX",
    "MY",
    "MZ",
    "CT",
    "CQ",
    "CT_ROTOR",
    "CN",
    "CS",
    "CMN",
    "CMS",
)

pyflightstream.cases.corrections.ROUTE1_WORDS module-attribute

ROUTE1_WORDS: tuple[str, ...] = (
    "theodorsen",
    "sears",
    "lift_deficiency",
    "route_1",
    "route1",
)

pyflightstream.cases.corrections.ROUTE3_NAMES module-attribute

ROUTE3_NAMES: tuple[str, ...] = (
    "dynamic_inflow",
    "skewed_wake",
    "pitt_peters",
    "coleman",
)

pyflightstream.cases.corrections.ROW_COLUMNS module-attribute

ROW_COLUMNS: tuple[str, ...] = (
    "COMPONENT",
    *AXES,
    *COEFFICIENT_COLUMNS,
)

pyflightstream.cases.corrections.SECTION_COMPONENTS module-attribute

SECTION_COMPONENTS: tuple[str, ...] = ("Fx", "Fz", "Moment")

pyflightstream.cases.corrections.calibration_path

calibration_path(
    inputs_dir: str | Path, calibration_id: str
) -> Path

Return <inputs_dir>/calibrations/<id>.toml.

Parameters:

Name Type Description Default
inputs_dir str or Path

The workspace's inputs folder.

required
calibration_id str

The calibration's id, its file name without the suffix.

required

Returns:

Type Description
Path

<inputs_dir>/calibrations/<calibration_id>.toml.

pyflightstream.cases.corrections.calibration_text

calibration_text(
    route: str,
    rows: Sequence[CalibrationRow],
    *,
    source_run_id: str | None = None,
    wheel_run_id: str | None = None,
    description: str | None = None,
) -> str

Return a calibration file's text, which :func:parse_calibration reads back unchanged.

Parameters:

Name Type Description Default
route str

The calibration's route, one of :data:CALIBRATION_ROUTES.

required
rows sequence of CalibrationRow

The rows, written in the order given.

required
source_run_id str

The run id of the axial unsteady sector run the offsets were taken from; a sector_offset calibration names it.

None
wheel_run_id str

The run id of the quasi-steady wheel run, written where given.

None
description str

Free text written into the file where given.

None

Returns:

Type Description
str

The TOML text, ending in a newline.

Examples:

>>> row = CalibrationRow("CT", 0.6, 0.0, 0.0, 0.001, 1.0, 1.0, 0.0)
>>> text = calibration_text("table", [row])
>>> parse_calibration(text).rows[0].offset_0p
0.001
>>> text = calibration_text("table", [row], description="line1\nline2")
>>> parse_calibration(text).description == "line1\nline2"
True

pyflightstream.cases.corrections.parse_calibration

parse_calibration(
    text: str,
    *,
    path: Path | None = None,
    calibration_id: str = "<text>",
    sha256: str | None = None,
) -> Calibration

Parse and validate a calibration file's text; refuse it whole, naming the line.

Parameters:

Name Type Description Default
text str

The file's text, TOML.

required
path Path

Where the text was read from, named in a refusal.

None
calibration_id str

The calibration's id; <text> where the text has no file.

'<text>'
sha256 str

The text's SHA-256 where the caller already has it; computed from text otherwise.

None

Returns:

Type Description
Calibration

The validated calibration: its id, route, rows, grids and digest.

Raises:

Type Description
CalibrationError

If the text is not TOML, states an unknown key or route, no rows, a row that does not validate, or a sector_offset route without its source_run_id, naming the line.

pyflightstream.cases.corrections.read_calibration

read_calibration(path: str | Path) -> Calibration

Read and validate a calibration file; refuse it whole with :class:CalibrationError.

Parameters:

Name Type Description Default
path str or Path

The calibration file.

required

Returns:

Type Description
Calibration

The validated calibration, its id the file's stem and its digest that of the file's text.

Raises:

Type Description
CalibrationError

If the file cannot be read, is not UTF-8 text, or its text is refused by :func:parse_calibration.

pyflightstream.cases.corrections.unoffered_route

unoffered_route(route: str) -> str | None

Return why route is not offered as a correction, or None where it may be.

Route 1 in any spelling that names Theodorsen, Sears or the lift deficiency, and route 3 by any of its four names, each with the reason.

Parameters:

Name Type Description Default
route str

A correction route as a row or a calibration states it.

required

Returns:

Type Description
str or None

The reason the route is not offered, naming it; None where it may be.

Examples:

>>> unoffered_route("table") is None
True
>>> "DIAGNOSTIC only" in unoffered_route("Theodorsen")
True
>>> "double counting" in unoffered_route("pitt-peters")
True