Skip to content

pyflightstream.post.corrections (provisional)

Generated from the docstrings at build time: every one of the 17 names in the __all__ of pyflightstream.post.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 corrected products and its diagnostic (P0310-CAL).

The one applicator of the correction routes a pproc's [qsteady_correction] table names (:mod:pyflightstream.cases.corrections), run by the post stage for every qsteady_rotor WHEEL point of a simulation whose pproc names a route, and needing no new run: everything here reads the files the post has just written, as a user holds them.

NOTHING HERE IS VALIDATED, and nothing is written over a raw product. Each corrected product is a new file beside its raw file, <name>_corrected.csv:

  • the rotor group's RCOEF file (polars/P<POL>-<ALIAS>-RCOEF.csv) and the average table (polars/P<sim>-<ALIAS>_qs_avg.csv): a 0P quantity q a component names becomes GAIN_0P q + OFFSET_0P (an in-plane component in the R axes with the sign of :data:_ROTOR_TABLE_COMPONENTS);
  • the harmonic product (sections/<point>_harmonics.csv), per station: H0' = GAIN_0P H0 + OFFSET_0P, A1' = GAIN_1P A1, PHI1' = PHI1 + PHASE_1P_DEG, A2 unchanged;
  • the sections (sections/<point>_sections.csv), each row of each blade at each clocking at its own azimuth psi (its AZIMUTH)::

    load' = load + (H0' - H0) + [A1' cos(psi - PHI1') - A1 cos(psi - PHI1)]

the raw row plus the change of its 0P and 1P terms, so what the fit does not explain is kept.

A column derived from a corrected one that this module does not derive again (CP, ETA and ETAW from CT and CQ; the rotor state from the thrust; a strip's integrated load from its load) is NA in the corrected file and named in its products.json entry, never carried raw beside a corrected neighbour. Every corrected file ends with :data:PROVENANCE_COLUMNS, and its entry names the raw file, the route, the calibration and its sha256, the grid cells used and the words "not validated". A point outside the calibration's grid is never extrapolated: its corrected cells are NA, named under skipped and a WARNING line of post.log. Nothing blocks.

The Theodorsen and Sears functions (route 1) are a DIAGNOSTIC only, sections/<point>_theodorsen.csv: :func:theodorsen and :func:sears of each station's 1P reduced frequency beside the measured 1P amplitude and phase of the harmonic product. They are computed from their closed forms with the Bessel functions of the first and second kind of orders 0 and 1, implemented here (:func:bessel_j, :func:bessel_y) because scipy is not a core dependency of this package: a power series summed in decimal arithmetic at a precision that grows with the argument, and Hankel's asymptotic expansion above 30.

:func:sector_offset_calibration builds a route 2 file from a recorded wheel point and a recorded axial sector point at the same J.

Used in the guides

pyflightstream.post.corrections.sector_offset_calibration

sector_offset_calibration(
    workspace: Any,
    *,
    wheel_run_id: str,
    sector_run_id: str,
    calibration_id: str,
    rotor: str | None = None,
    matrix_stem: str | None = None,
    j_tolerance: float = 0.0001,
    overwrite: bool = False,
) -> Path

Write a route 2 calibration from a recorded wheel point and a recorded sector point.

Both points must be rows of a rotor's RCOEF file the post wrote (the sector's row of an unsteady_rotor point with a window is its window average, the wheel's the mean of its clockings), both at zero angle of attack and sideslip (axial), and at the same advance ratio J<id> within j_tolerance (the files print J at five decimals, or at six significant digits where that states it more closely). The file, inputs/calibrations/<calibration_id>.toml, states route sector_offset, the two run ids, and one row per component THRUST, TORQUE, CT and CQ at the wheel's J with

OFFSET_0P = sector - wheel,  GAIN_0P = 1,  GAIN_1P = 1,  PHASE_1P_DEG = 0

THRUST = CT rho n^2 D^4 and TORQUE = CQ rho n^2 D^5 of each row's own RHO, RPM<id> and D<id>, each stated in the sense of the rotor's declared axis as every calibration is: the RCOEF difference times the sense of the rotor frame the wheel's quasi-steady record gives (+1 for a wheel without a readable record). Each component's grid is one node, constant on every axis, so it applies at every J, ALPHA and K_1P: the offset measured in axial flow, applied at incidence, is what route 2 is. Refused with :class:CalibrationError when a run is not in runs.json, when the sector's record does not prove whole-rotor loads (its script, hashed as recorded, solves a symmetry other than NONE without SET_ANALYSIS_SYMMETRY_LOADS ENABLE, or cannot be read), not a row of one rotor's RCOEF file, not axial, at another J, or when the file exists and overwrite is False. The route is NOT VALIDATED. Returns the file written.

Parameters:

Name Type Description Default
workspace CampaignWorkspace

The workspace whose runs.json and products are read.

required
wheel_run_id str

The run id of the quasi-steady wheel point.

required
sector_run_id str

The run id of the axial unsteady sector point.

required
calibration_id str

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

required
rotor str

The rotor alias whose table is read, where a run is a row of more than one.

None
matrix_stem str

The matrix whose products folder holds the rotor tables.

None
j_tolerance float

The largest difference in advance ratio the two points may have.

0.0001
overwrite bool

Replace an existing file of that id.

False

Returns:

Type Description
Path

The calibration file written.

Raises:

Type Description
CalibrationError

If a run is not in runs.json, the sector's record does not prove whole-rotor loads, a run is not a row of exactly one rotor table, is not axial, the two points are at different advance ratios, or the file exists and overwrite is False.

Advanced

pyflightstream.post.corrections.CALIBRATION_SHA256_COLUMN module-attribute

CALIBRATION_SHA256_COLUMN = 'CALIBRATION_SHA256'

pyflightstream.post.corrections.CORRECTED_KIND module-attribute

CORRECTED_KIND = 'corrected'

pyflightstream.post.corrections.CORRECTED_SUFFIX module-attribute

CORRECTED_SUFFIX = '_corrected'

pyflightstream.post.corrections.CORRECTION_ROUTE_COLUMN module-attribute

CORRECTION_ROUTE_COLUMN = 'CORRECTION_ROUTE'

pyflightstream.post.corrections.NOT_VALIDATED module-attribute

NOT_VALIDATED = 'not validated'

pyflightstream.post.corrections.PROVENANCE_COLUMNS module-attribute

PROVENANCE_COLUMNS: tuple[str, ...] = (
    CORRECTION_ROUTE_COLUMN,
    CALIBRATION_SHA256_COLUMN,
)

pyflightstream.post.corrections.THEODORSEN_COLUMNS module-attribute

THEODORSEN_COLUMNS: tuple[str, ...] = tuple(
    "ROTOR QUANTITY STATION_R_M R_OVER_R K_1P C_ABS C_PHASE_DEG S_ABS S_PHASE_DEG H1_AMP H1_PHASE_DEG".split()
)

pyflightstream.post.corrections.THEODORSEN_KIND module-attribute

THEODORSEN_KIND = 'theodorsen'

pyflightstream.post.corrections.THEODORSEN_SUFFIX module-attribute

THEODORSEN_SUFFIX = '_theodorsen.csv'

pyflightstream.post.corrections.WheelPointRef dataclass

WheelPointRef(
    name: str, run_id: str, rotor_alias: str, sense: int = 1
)

A quasi-steady wheel point of the simulation: its name, run id and rotor alias.

sense is its rotor frame's sense (+1, or -1 where the sense rule turned the declared axis), the sign the RCOEF file's components are read with against a calibration stated in the declared axis's sense.

of_record classmethod

of_record(
    name: str, run_id: str, record: Any
) -> WheelPointRef

Return the point of a quasi-steady record, its sense from the record's shaft.

A shaft naming no finite direction has no frame and is read with +1.

pyflightstream.post.corrections.bessel_j

bessel_j(order: int, x: float) -> float

Return the Bessel function of the first kind J_n(x), n in (0, 1), x > 0.

Parameters:

Name Type Description Default
order int

The order n, 0 or 1.

required
x float

The argument, positive.

required

Returns:

Type Description
float

J_n(x).

Examples:

>>> round(bessel_j(0, 1.0), 12), round(bessel_j(1, 1.0), 12)
(0.765197686558, 0.440050585745)

pyflightstream.post.corrections.bessel_y

bessel_y(order: int, x: float) -> float

Return the Bessel function of the second kind Y_n(x), n in (0, 1), x > 0.

Parameters:

Name Type Description Default
order int

The order n, 0 or 1.

required
x float

The argument, positive.

required

Returns:

Type Description
float

Y_n(x).

Examples:

>>> round(bessel_y(0, 1.0), 12), round(bessel_y(1, 1.0), 12)
(0.088256964216, -0.7812128213)

pyflightstream.post.corrections.corrected_name

corrected_name(relative: str) -> str

Return the corrected file's name beside a raw file's.

Parameters:

Name Type Description Default
relative str

The raw file's path, relative to the products folder.

required

Returns:

Type Description
str

The path with _corrected before its extension.

Examples:

>>> corrected_name("polars/P7001-PROP-RCOEF.csv")
'polars/P7001-PROP-RCOEF_corrected.csv'

pyflightstream.post.corrections.sears

sears(k: float) -> complex

Sears's function S(k) at the reduced frequency k, the gust referred to mid-chord.

S(k) = (J0(k) - i J1(k)) C(k) + i J1(k); S(0) = 1.

Parameters:

Name Type Description Default
k float

The reduced frequency, a finite number >= 0.

required

Returns:

Type Description
complex

S(k).

Examples:

>>> round(abs(sears(0.0)), 12)
1.0

pyflightstream.post.corrections.theodorsen

theodorsen(k: float) -> complex

Theodorsen's lift deficiency function C(k) at the reduced frequency k.

C(k) = H1(k) / (H1(k) + i H0(k)), with Hn = Jn - i Yn the Hankel function of the second kind; C(0) = 1. Its phase is a lag (negative).

Parameters:

Name Type Description Default
k float

The reduced frequency, a finite number >= 0.

required

Returns:

Type Description
complex

C(k).

Raises:

Type Description
ProductError

If k is not a finite number >= 0.

Examples:

>>> value = theodorsen(1.0)
>>> round(value.real, 4), round(value.imag, 4)
(0.5394, -0.1003)

pyflightstream.post.corrections.write_qsteady_corrections

write_qsteady_corrections(
    spec: QsteadyCorrectionSpec,
    *,
    sim_id: str,
    inputs_dir: Path,
    out: Path,
    wheel_points: Sequence[WheelPointRef],
    written_names: Mapping[str, Mapping[str, object]],
    known_runs: Collection[str] | None,
    target: Callable[[Path], Path],
    skipped: dict[str, str],
    sections_dir: str = "sections",
    reductions_dir: str = "reductions",
    overwrite: bool = True,
) -> list[tuple[Path, dict[str, object]]]

Write the corrected products and the diagnostic of one simulation's wheel points.

written_names is the simulation's manifest entries so far, keyed by the file's path relative to out; the raw files are read back from out and never rewritten. Returns each file written with its entry. What is not written for a refused calibration or an unreadable input is named in skipped and warned; a file-system failure while writing a table (an OSError) is not caught.

Parameters:

Name Type Description Default
spec QsteadyCorrectionSpec

The row's [qsteady_correction] choice.

required
sim_id str

The simulation, named in the warnings.

required
inputs_dir Path

The workspace's inputs folder, where the calibration files are.

required
out Path

The products folder the raw files are read from and the corrected ones written to.

required
wheel_points sequence of WheelPointRef

The simulation's quasi-steady wheel points.

required
written_names mapping of str to mapping

The simulation's manifest entries so far, by path relative to out.

required
known_runs collection of str, or None

The run ids of the workspace's runs.json; a sector-offset calibration naming another source run is warned. None skips that check.

required
target callable

Prepare a destination path, applying the caller's archive policy.

required
skipped dict of str to str

Mutable mapping of product names to skip reasons.

required
sections_dir str

The folder under out that holds the sections tables.

'sections'
reductions_dir str

The folder under out that holds the harmonics.

'reductions'
overwrite bool

Replace a file that already exists, as the writer always did (the default). False refuses an existing file, naming it, before it is replaced.

True

Returns:

Type Description
list of tuple of (Path, dict)

Each file written with its manifest entry.