pyflightstream.post.harmonics (provisional)¶
Generated from the docstrings at build time: every one of the 20 names in the __all__ of pyflightstream.post.harmonics has an entry below. The names a guide or an example uses come first; the others follow under Advanced.
The per-station harmonic product of a rotor point (P0310-HARMONICS).
For each rotor of a point, each blade station and each sectional load quantity of the sections export, the least-squares fit
load(psi) = H0 + A1 cos(psi - PHI1) + A2 cos(2 psi - PHI2)
over every sample of that station, psi being the sample's blade azimuth
as the WRITTEN sections table states it. The samples are:
- on a quasi-steady WHEEL, every blade at every clocking of the point, read
from
sections/<point>_sections.csv, whoseAZIMUTHis each block's own blade at its clocking (the wheel's premise is identical blades); - on an
unsteady_rotorpoint, every blade at every step of the last complete revolution of that rotor, read fromseries/<point>_sections_series.csv, whoseAZIMUTHis each block's own blade's (the writer places blade n through :func:pyflightstream.post.axes.placed_blade_azimuth_deg).
No azimuth is computed here: every angle is the table's own or comes from
:mod:pyflightstream.post.axes, the one home of where a blade is.
PHI_k is the phase of the k-th harmonic in degrees in [0, 360): the kP
term peaks where k psi = PHI_k, so the 1P peak is at the azimuth
PHI1 and the 2P peaks at PHI2 / 2 and PHI2 / 2 + 180. A harmonic
whose station holds fewer distinct azimuths than it needs (1P needs 3, 2P
needs 5, the unknowns of the fit up to it), or whose samples do not go round
the circle (:func:fit_harmonics), is NA. The definitions page,
docs/post-processing-definitions.md, is the definition of record.
Advanced¶
pyflightstream.post.harmonics.AZIMUTH_TOLERANCE_DEG
module-attribute
¶
AZIMUTH_TOLERANCE_DEG = 1e-06
pyflightstream.post.harmonics.HARMONICS_COLUMNS
module-attribute
¶
HARMONICS_COLUMNS: tuple[str, ...] = (
POLAR_ID_COLUMN,
*CONTEXT_COLUMNS,
*HARMONIC_COLUMNS,
)
pyflightstream.post.harmonics.HARMONICS_SUFFIX
module-attribute
¶
HARMONICS_SUFFIX = '_harmonics.csv'
pyflightstream.post.harmonics.HARMONIC_COLUMNS
module-attribute
¶
HARMONIC_COLUMNS: tuple[str, ...] = (
"ROTOR",
"QUANTITY",
"STATION_R_M",
"R_OVER_R",
"SAMPLES",
"DISTINCT_AZIMUTHS",
"H0",
"H1_AMP",
"H1_PHASE_DEG",
"H2_AMP",
"H2_PHASE_DEG",
"RESIDUAL_RMS",
)
pyflightstream.post.harmonics.HarmonicFit
dataclass
¶
HarmonicFit(
samples: int,
distinct: int,
h0: float,
h1_amp: float | None,
h1_phase_deg: float | None,
h2_amp: float | None,
h2_phase_deg: float | None,
residual_rms: float,
reason: str | None = None,
)
The fit of one station and quantity; a harmonic that cannot be fitted is None.
reason says why a harmonic was left out, None where both were fitted.
pyflightstream.post.harmonics.HarmonicRotor
dataclass
¶
HarmonicRotor(
alias: str,
blades: tuple[tuple[str, ...], ...],
diameter_m: float | None,
azimuth_is_blade_one: bool,
hub_m: Sequence[float] | None = None,
axis_vector: Sequence[float] | None = None,
section_frames: Mapping[tuple[str, str], str | None]
| None = None,
moment_point_m: Sequence[float] | None = None,
)
What the product needs of one rotor.
blades holds, for blade n (from 1), the section families a block of
that blade may state; a block is blade n's when every family it states
is one of them, and a block of any other families is not a sample.
azimuth_is_blade_one says what the table's AZIMUTH is: blade one's
(a table written in legacy releases states it for every block), so a block of
blade n is placed at its own blade, or the block's own blade's (a wheel's
sections table and an unsteady sections series).
pyflightstream.post.harmonics.MINIMUM_DISTINCT_AZIMUTHS
module-attribute
¶
MINIMUM_DISTINCT_AZIMUTHS: Mapping[int, int] = {1: 3, 2: 5}
pyflightstream.post.harmonics.SOURCE_UNSTEADY
module-attribute
¶
SOURCE_UNSTEADY = 'unsteady last revolution'
pyflightstream.post.harmonics.STATION_MATCH_TOLERANCE
module-attribute
¶
STATION_MATCH_TOLERANCE = STATION_TOLERANCE
pyflightstream.post.harmonics.StationHarmonics
dataclass
¶
StationHarmonics(
rows: list[
tuple[
str,
str,
float | None,
float | None,
HarmonicFit,
]
] = list(),
samples: dict[str, int] = dict(),
skipped: dict[str, str] = dict(),
notes: list[str] = list(),
)
The fits of one point and what could not be fitted, for the stage to say.
rows are (rotor, quantity, radius, r / R, fit). samples counts
the blade samples of each rotor fitted. skipped maps a marker
(#rotor=<alias> or #rotor=<alias>#station=<j>) to why nothing of it
is a row. notes are the post-log lines, one per rotor and harmonic
that is NA somewhere.
pyflightstream.post.harmonics.blade_of
¶
blade_of(
families: Sequence[str], rotor: HarmonicRotor
) -> int | None
Return the blade of rotor (from 1) whose families include every one given, or None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
families
|
sequence of str
|
The families of one block of the table. |
required |
rotor
|
HarmonicRotor
|
The rotor, with its blades' families. |
required |
Returns:
| Type | Description |
|---|---|
int or None
|
The blade's number, from 1, or None where no blade carries every family. |
pyflightstream.post.harmonics.distinct_azimuths
¶
distinct_azimuths(azimuths_deg: Sequence[float]) -> int
Return how many distinct azimuths the samples hold, around the circle.
Two azimuths within :data:AZIMUTH_TOLERANCE_DEG of each other, 360 and 0
included, are one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
azimuths_deg
|
sequence of float
|
The samples' azimuths, in degrees. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of distinct azimuths; 0 for no sample. |
Examples:
>>> distinct_azimuths([0.0, 360.0, 90.0, 90.0, 180.0])
3
pyflightstream.post.harmonics.fit_harmonics
¶
fit_harmonics(
azimuths_deg: Sequence[float], values: Sequence[float]
) -> HarmonicFit
Fit H0 + A1 cos(psi - PHI1) + A2 cos(2 psi - PHI2) by least squares.
The fit holds the harmonics the samples can carry: 2P with five distinct
azimuths or more, 1P with three or more, H0 alone below that; a
harmonic left out is None. RESIDUAL_RMS is the root mean square of
the samples less the fit that was made.
THE SAMPLES MUST GO ROUND THE CIRCLE, not only be distinct (the angular
coverage criterion). The kP term is fitted only where the angles
k psi of the samples leave no gap larger than 180 deg around the
circle, and every lower term is fitted too: samples crowded inside a half
circle determine a sinusoid only through differences at the round-off of
their values, and five samples 0.1 deg apart gave amplitudes of 1e5 on a
constant load. A harmonic left out for either reason is None, and the
fit's reason says which.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
azimuths_deg
|
sequence of float
|
The samples' azimuths, in degrees. |
required |
values
|
sequence of float
|
The value at each azimuth. |
required |
Returns:
| Type | Description |
|---|---|
HarmonicFit
|
The sample counts, |
Raises:
| Type | Description |
|---|---|
ProductError
|
When a sample is non-finite, there is not one value per azimuth, or no sample. It is
a |
Examples:
>>> psi = [0.0, 90.0, 180.0, 270.0]
>>> fit = fit_harmonics(psi, [2.0 + math.cos(math.radians(p - 90.0)) for p in psi])
>>> round(fit.h0, 9), round(fit.h1_amp, 9), round(fit.h1_phase_deg, 9), fit.h2_amp
(2.0, 1.0, 90.0, None)
pyflightstream.post.harmonics.last_complete_revolution
¶
last_complete_revolution(
first_step: int,
last_step: int,
steps_per_revolution: float,
) -> tuple[int, int] | None
Return the first and last step of the last complete revolution, or None.
Revolution k is steps first + (k - 1) N to first + k N - 1, counted
from the history's first step as the per-revolution product counts from
its first row, with N an integral number of steps per revolution.
Fractional clocks are refused rather than rounded to another period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first_step
|
int
|
The history's first step. |
required |
last_step
|
int
|
The history's last step. |
required |
steps_per_revolution
|
float
|
The rotor's clock, in steps per revolution. |
required |
Returns:
| Type | Description |
|---|---|
tuple of (int, int) or None
|
The first and last step of that revolution, or None where no revolution is complete. |
Raises:
| Type | Description |
|---|---|
ProductError
|
If |
Examples:
>>> last_complete_revolution(3, 13, 4.0)
(7, 10)
>>> last_complete_revolution(3, 5, 4.0) is None
True
pyflightstream.post.harmonics.load_quantities
¶
load_quantities(columns: Sequence[str]) -> list[str]
Return the sectional load columns of a sections table, in its order.
Every column of the export after the condition that is not a station's
place (Offset, Chord, X_QC, Z_QC) nor one the post adds
(the clocking, the reduced frequency, the validity, the integrated
strips): Fx, Fz and Moment in the sectional export measured by
RPT-005 finding 4 (26.120 build 7012026, WP1 dry run), retained in
tests/tier1_offline/fixtures/fsi/FS_SurfaceSection_Loads_call0002.txt.
This names that measured schema, not a guarantee for every solver build.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
sequence of str
|
The sections table's columns. |
required |
Returns:
| Type | Description |
|---|---|
list of str
|
The load columns, in the table's order. |
pyflightstream.post.harmonics.sample_blocks
¶
sample_blocks(
rows: Sequence[Mapping[str, str]], sample_column: str
) -> list[list[Mapping[str, str]]]
Split the table into its blocks: consecutive rows of one sample and one distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
sequence of mapping of str to str
|
The table's rows as :func: |
required |
sample_column
|
str
|
The column that tells one sample from the next, |
required |
Returns:
| Type | Description |
|---|---|
list of list of mapping
|
The blocks, each the consecutive rows of one sample and one distribution, in table order. |
pyflightstream.post.harmonics.station_harmonics
¶
station_harmonics(
columns: Sequence[str],
rows: Sequence[Mapping[str, str]],
rotors: Mapping[str, HarmonicRotor],
*,
sample_column: str,
) -> StationHarmonics
Fit every station of every rotor in one written sections table.
A rotor whose blade samples span multiple planes is skipped with their names; distinct distributions are never pooled into one station fit.
rows are the table's rows as :func:~pyflightstream.post.products.read_csv_table
reads them, already cut to the samples wanted (an unsteady point's last
complete revolution); sample_column tells one sample from the next
(CLOCKING on a wheel, STEP on a series). A block is the consecutive
rows of one sample, family, plane and rotor; a block of one blade of a
rotor in rotors is a sample of that rotor, at its blade's azimuth.
Station j of a rotor is the j-th row of each of its blade blocks. Its
radius is measured from the hub using the recorded frame; a geometry
cut that cannot be placed has NA radius columns and a note. Legacy
calls without frame metadata use |Offset|. A rotor whose blocks hold different numbers of
stations, or states no azimuth, is skipped by name; a station whose
radius differs from the first sample's by more than
:data:STATION_MATCH_TOLERANCE of the first sample's largest radius is
skipped by name, and the others are fitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
sequence of str
|
The sections table's columns. |
required |
rows
|
sequence of mapping of str to str
|
The table's rows as :func: |
required |
rotors
|
mapping of str to HarmonicRotor
|
The rotors to fit, by alias. |
required |
sample_column
|
str
|
The column that tells one sample from the next, |
required |
Returns:
| Type | Description |
|---|---|
StationHarmonics
|
The fit of every station of every rotor fitted, and what was skipped and why. |
pyflightstream.post.harmonics.write_harmonics_table
¶
write_harmonics_table(
path: Path,
*,
pol: str,
context: Sequence[object],
result: StationHarmonics,
overwrite: bool = True,
) -> Path
Write the harmonic product: POL, the condition, then :data:HARMONIC_COLUMNS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The table to write. |
required |
pol
|
str
|
The polar the point belongs to, written as |
required |
context
|
sequence of object
|
The point's condition values, written after |
required |
result
|
StationHarmonics
|
The fits of :func: |
required |
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 |
|---|---|
Path
|
The written table. |