pyflightstream.post.acoustics (provisional)¶
Generated from the docstrings at build time: every one of the 13 names in the __all__ of pyflightstream.post.acoustics has an entry below. The names a guide or an example uses come first; the others follow under Advanced.
The acoustic signals product of a point: reading the solver's acoustic export.
Pipeline role: the post row. Work package E1 fills it (FR-260 to FR-264): it
reads the file a point's EXPORT_ACOUSTIC_SIGNALS wrote (named by
:data:pyflightstream.cases.acoustics.ACOUSTIC_SIGNALS_SUFFIX) into one
:class:~pyflightstream.cases.acoustics.AcousticSignal per observer, the
contract :mod:pyflightstream.cases.acoustics states, and writes from them,
per observer, the pressure against time, the spectrum, the OASPL and the
blade-passage harmonics, and the directivity on an arc when the observers
form one. The definitions of every number are in
docs/post-processing-definitions.md, the one home of them.
THE FILE, as measured on build 26.124 (licensed round 1, probe A1): one block
per observer, a line Observer: <name> (the name may hold spaces), a line
Position: x,y,z in Fortran style (.00,10.0,.00), a line
Columns: Observer time (sec), PL (Pa), PT (Pa), PO (Pa) and one row of four
numbers per sample. The signal the package reads is the PO column. The
manual pages of the toolbox (FSM-26.120 pp.374 and 380) do not define PL, PT and
PO; the probe shows PO equal to PL plus PT in every row (PT was
zero in the probe) and the package reads PO as the overall pressure, PL as
the loading part and PT as the thickness part, which is the customary split
and is not a vendor statement. The length unit of the position is not stated
by the file and is read as the contract's metre.
RE-EXPORT, deliberate: the contract (:class:~pyflightstream.cases.acoustics.AcousticSignal
and :data:~pyflightstream.cases.acoustics.ACOUSTIC_SIGNALS_SUFFIX) has ONE
home, :mod:pyflightstream.cases.acoustics; this module re-exports both in
__all__ for the readers of the product, who import the reader and the
record it returns from one place. The objects are the same, never copies.
Nothing here blocks a post (invariant 12): the writers return the lines the
post log carries and a value that cannot be computed is NA.
Advanced¶
pyflightstream.post.acoustics.ACOUSTIC_SIGNALS_SUFFIX
module-attribute
¶
ACOUSTIC_SIGNALS_SUFFIX = '_acoustic_signals.txt'
pyflightstream.post.acoustics.AcousticProducts
dataclass
¶
AcousticProducts(
files: list[Path] = list(), notes: list[str] = list()
)
What :func:write_acoustic_products wrote and the post-log lines it owes.
pyflightstream.post.acoustics.AcousticSignal
dataclass
¶
AcousticSignal(
observer: str,
x_m: float,
y_m: float,
z_m: float,
time_s: tuple[float, ...],
pressure_pa: tuple[float, ...],
)
One observer's acoustic pressure signal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observer
|
str
|
The observer's name, as its creation named it. |
required |
x_m
|
float
|
The observer's position in the reference coordinate system, in metres. |
required |
y_m
|
float
|
The observer's position in the reference coordinate system, in metres. |
required |
z_m
|
float
|
The observer's position in the reference coordinate system, in metres. |
required |
time_s
|
tuple of float
|
The observer's time samples, in seconds. |
required |
pressure_pa
|
tuple of float
|
The acoustic pressure at each time sample, in pascals. |
required |
pyflightstream.post.acoustics.ArcFit
dataclass
¶
ArcFit(
center: tuple[float, float, float],
radius_m: float,
angle_deg: tuple[float, ...],
)
Observers on a circular arc: its centre, radius and each observer's angle.
angle_deg is each observer's angle about the centre, measured from the
first observer and increasing toward the second, in [0, 360).
pyflightstream.post.acoustics.REFERENCE_PRESSURE_PA
module-attribute
¶
REFERENCE_PRESSURE_PA = 2e-05
pyflightstream.post.acoustics.Spectrum
dataclass
¶
Spectrum(
frequency_hz: tuple[float, ...],
amplitude_pa: tuple[float, ...],
sample_rate_hz: float,
df_hz: float,
samples: int,
)
The one-sided spectrum of one observer's pressure.
frequency_hz and amplitude_pa have samples // 2 + 1 entries;
sample_rate_hz is the reciprocal of the constant step, df_hz the bin
width sample_rate_hz / samples.
pyflightstream.post.acoustics.arc_of
¶
arc_of(signals: Sequence[AcousticSignal]) -> ArcFit | None
Return the arc the observers lie on, or None when they do not form one (FR-264).
They form an arc when there are at least :data:MINIMUM_ARC_OBSERVERS, they
are coplanar and lie on one circle, both to a relative tolerance of
1e-3 (of the extent, and of the radius).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signals
|
sequence of AcousticSignal
|
The point's observers, with their positions. |
required |
Returns:
| Type | Description |
|---|---|
ArcFit or None
|
The arc's centre, its radius and each observer's angle on it; None when the observers form no arc. |
pyflightstream.post.acoustics.blade_passage_harmonics
¶
blade_passage_harmonics(
spectrum: Spectrum,
*,
blades: int,
rpm: float,
harmonics: int = DEFAULT_HARMONICS,
) -> list[_Harmonic]
Return the blade-passage harmonics read from a spectrum (FR-263).
The blade-passage frequency is blades * |rpm| / 60 hertz (the sign of the
speed only states the sense of rotation) and harmonic
n is n times it. Each row is (n, frequency_hz, bin_hz,
amplitude_pa, level_db) read at the nearest bin; the bin, amplitude and
level are None (NA) when the frequency is above the Nyquist frequency
of the record or below its bin width (the record holds less than one
period of it).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spectrum
|
Spectrum
|
The observer's spectrum, from :func: |
required |
blades
|
int
|
The rotor's blade count. |
required |
rpm
|
float
|
The rotor's speed in rev/min; its sign is left out. |
required |
harmonics
|
int
|
How many harmonics are read. |
DEFAULT_HARMONICS
|
Returns:
| Type | Description |
|---|---|
list of tuple
|
One row per harmonic, |
Raises:
| Type | Description |
|---|---|
ProductError
|
If |
pyflightstream.post.acoustics.oaspl_db
¶
oaspl_db(signal: AcousticSignal) -> float | None
Return the overall sound pressure level of a signal in dB re 20 uPa (FR-262).
20 log10(p_rms / 20e-6 Pa), p_rms the root mean square of the
pressure about its mean over the whole record (the fluctuation). None for
a silent record (p_rms zero), which the caller states as NA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
AcousticSignal
|
One observer's record: its time [s] and pressure [Pa] samples. |
required |
Returns:
| Type | Description |
|---|---|
float or None
|
The level in dB re 20 uPa, or None for a silent record. |
pyflightstream.post.acoustics.read_acoustic_signals
¶
read_acoustic_signals(
path: str | Path,
) -> tuple[AcousticSignal, ...]
Read a point's acoustic export into one signal per observer (FR-260).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
The exported file, |
required |
Returns:
| Type | Description |
|---|---|
tuple of AcousticSignal
|
One per observer, in the order the file holds them. The pressure is
the |
Raises:
| Type | Description |
|---|---|
ProductError
|
The file cannot be read, holds no observer, or a block lacks its
position, its columns or its samples, states no |
pyflightstream.post.acoustics.spectrum_of
¶
spectrum_of(signal: AcousticSignal) -> Spectrum
Return the one-sided amplitude spectrum of a signal's pressure (FR-261).
The samples are transformed as they are (no window, no mean removal) with
the real FFT. For N samples, bin 0 is |X0| / N (the mean), a bin
below the Nyquist bin is 2 |Xk| / N and the Nyquist bin of an even
N is |Xk| / N, so a cosine of amplitude A on a bin reads A.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
AcousticSignal
|
One observer's record: its time [s] and pressure [Pa] samples. |
required |
Returns:
| Type | Description |
|---|---|
Spectrum
|
The frequencies [Hz] and amplitudes [Pa], the sampling rate, the bin width and the sample count. |
Raises:
| Type | Description |
|---|---|
ProductError
|
The record has fewer than two samples, or its time step is not
constant (relative spread above |
pyflightstream.post.acoustics.write_acoustic_products
¶
write_acoustic_products(
signals: Sequence[AcousticSignal],
out_dir: str | Path,
*,
stem: str,
rotors: Mapping[str, tuple[int | None, float | None]]
| None = None,
harmonics: int = DEFAULT_HARMONICS,
target: Callable[[Path], Path] | None = None,
overwrite: bool = True,
) -> AcousticProducts
Write a point's acoustic products under out_dir and return them (FR-261 to FR-264).
Per observer <stem>_<n>_<name>_pressure.csv (time, pressure) and
<stem>_<n>_<name>_spectrum.csv (frequency, amplitude, level); per point
<stem>_acoustics_summary.csv (position, samples, sampling, OASPL),
<stem>_acoustics_bpf.csv (blade-passage harmonics per rotor and observer)
and, when the observers form an arc, <stem>_acoustics_directivity.csv.
The BPF table retains nearest-bin amplitudes. BIN_OFFSET_BINS is
(selected bin frequency minus requested harmonic frequency) divided by bin
spacing. Nonzero offsets are noted: an unwindowed off-bin tone can be
underestimated by about 3.9 dB.
Nothing blocks: an observer whose spectrum cannot be read keeps its pressure table and its OASPL, and is named in the notes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signals
|
sequence of AcousticSignal
|
The point's observer signals, numbered in this order in the file names. |
required |
out_dir
|
str or Path
|
The folder the products are written into. |
required |
stem
|
str
|
The point's file stem every product name starts with. |
required |
rotors
|
mapping
|
Rotor alias to |
None
|
harmonics
|
int
|
How many blade-passage harmonics are tabled per rotor and observer. |
DEFAULT_HARMONICS
|
target
|
callable
|
Maps a path to the path to write (the archive-or-refuse rule of the other products). |
None
|
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 |
|---|---|
AcousticProducts
|
The files written and the notes the post log owes. |
Raises:
| Type | Description |
|---|---|
ProductError
|
If |