pyflightstream.post.equations (stable)¶
Generated from the docstrings at build time: every one of the 3 names in the __all__ of pyflightstream.post.equations has an entry below. The names a guide or an example uses come first; the others follow under Advanced.
The [equations] of a pproc, evaluated into the rows of a product.
An equation is arithmetic over the columns a row ALREADY holds. It is about one
alias, so the column it adds is <NAME>_<alias>; it may name another
equation, and the order is the pproc's own
(:meth:pyflightstream.cases.PprocSpec.equation_order). The expression is
parsed and walked by :mod:pyflightstream._expressions and never executed.
HOW A SYMBOL FINDS ITS COLUMN, which is :func:resolve_symbol and nothing
else. A plotted column is named <parameter>_<group>, and the group of a
rotor is named by the pproc, usually for the alias and the frame. So a symbol
S of an equation about alias A in frame F is, first match wins:
- another equation named
S: its value on that row; S_A_F, thenS_F_A, where the equation states a frame;- condition and reference scalars such as
RHOandSREF; - only without a frame,
S_Athen the exact columnS.
Native setup coefficient columns are never equation inputs. A stated frame never falls back to an unqualified plotted column.
THE ALIAS COMES BEFORE THE EXACT NAME because the equation is ABOUT the alias:
the setup of a row carries the native export's own CL and Cx, one instant
of the last step, and CL of an equation about WING means CL_WING.
A symbol none of them answers REFUSES THE BLOCK, naming the equation, the symbol,
the spellings tried and the columns there are. It is never a column of NA:
a name that matched nothing is a mistake in the artifact, and a column of NA
is how such a mistake is published.
Advanced¶
pyflightstream.post.equations.apply_equations
¶
apply_equations(
rows: Sequence[Mapping[str, object]],
equations: Mapping[str, object],
order: Sequence[str],
*,
columns: Sequence[str],
where: str,
notes: list[str] | None = None,
resolved_columns: dict[str, dict[str, str]]
| None = None,
) -> tuple[list[str], list[dict[str, float | None]]]
Evaluate every equation on every row; return the columns added and their values.
equations maps a name to an object stating expression,
meshes_alias and frame (:class:pyflightstream.cases.EquationSpec);
order is the order to evaluate them in. columns is the header of the
table, which is what a symbol is resolved against, ONCE, so a symbol reads the
same column on every row. where names the file, for the refusal.
A row that holds no number under a column an equation reads (NA on a point
the quantity does not apply to) gets no number from that equation either, and
neither does a row where the arithmetic has no answer, a division by zero or
the root of a negative; notes receives one sentence per such equation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
sequence of mapping of str to object
|
The table's rows. |
required |
equations
|
mapping of str to object
|
Equation name to its specification. |
required |
order
|
sequence of str
|
The order the equations are evaluated in. |
required |
columns
|
sequence of str
|
The table's header, which the symbols are resolved against. |
required |
where
|
str
|
The file, named in the refusal. |
required |
notes
|
list of str
|
Receives one sentence per equation a row got no number from. |
None
|
resolved_columns
|
dict
|
Receives the column each symbol reads, by equation, after resolution succeeds. |
None
|
Returns:
| Type | Description |
|---|---|
tuple of (list of str, list of dict)
|
The columns added, and per row the value of each, None where there is none. |
Raises:
| Type | Description |
|---|---|
ProductError
|
If a symbol is no equation and no column, a symbol names an equation
that |
Examples:
>>> from types import SimpleNamespace as Equation
>>> table = [{"RHO": 1.2, "FX_PUSHER": -30.0}]
>>> added, values = apply_equations(
... table,
... {"T": Equation(expression="-FX", meshes_alias="PUSHER", frame=None),
... "T2": Equation(expression="T * 2 / RHO", meshes_alias="PUSHER", frame=None)},
... ["T", "T2"], columns=["RHO", "FX_PUSHER"], where="polars/P1_x_uns_avg.csv",
... )
>>> added, values
(['T_PUSHER', 'T2_PUSHER'], [{'T_PUSHER': 30.0, 'T2_PUSHER': 50.0}])
pyflightstream.post.equations.derived_column
¶
derived_column(name: str, alias: str) -> str
Return the column an equation adds: its own name, then the alias it is about.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The equation's name. |
required |
alias
|
str
|
The alias it is about. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Examples:
>>> derived_column("CTX", "PUSHER")
'CTX_PUSHER'
pyflightstream.post.equations.resolve_symbol
¶
resolve_symbol(
symbol: str,
*,
alias: str,
frame: str | None,
columns: Sequence[str],
) -> str | None
Return the column symbol reads, or None where no spelling of it is a column.
The order is the module's: <symbol>_<alias>_<frame> and
<symbol>_<frame>_<alias> where a frame is stated, plus condition and
reference scalars. Without a frame, try <symbol>_<alias> then the exact
name. Native setup coefficients are excluded from exact-name fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The symbol an expression reads. |
required |
alias
|
str
|
The equation's alias. |
required |
frame
|
str or None
|
The equation's frame, where it states one. |
required |
columns
|
sequence of str
|
The table's columns. |
required |
Returns:
| Type | Description |
|---|---|
str or None
|
The column read, or None where no spelling is a column. |
Examples:
>>> held = ["RHO", "FX", "FX_PUSHER", "FX_PUSHER_SMRP"]
>>> resolve_symbol("FX", alias="PUSHER", frame="SMRP", columns=held)
'FX_PUSHER_SMRP'
>>> resolve_symbol("FX", alias="PUSHER", frame=None, columns=held)
'FX_PUSHER'
>>> resolve_symbol("RHO", alias="PUSHER", frame=None, columns=held)
'RHO'
>>> resolve_symbol("CT", alias="PUSHER", frame=None, columns=held) is None
True