Ir al contenido

environment.assessment.impulsive_sound

La referencia de la API se publica en inglés en los dos idiomas: se genera a partir de los docstrings del código, que son su texto original.

Prominence of impulsive sounds and the LAeq adjustment (NT ACOU 112:2002, ISO/PAS 1996-3:2022).

Noise with prominent impulses is more annoying than a steady sound of the same equivalent level, so both methods add an adjustment KI to the measured LAeq. They share the prominence and adjustment formulae, which both take from Pedersen’s method, and differ in what the caller supplies.

NT ACOU 112:2002 is the closed form: the caller brings the onset rate and the level difference of the impulse, and the predicted prominence

follows (clause 7). From the impulse with the highest prominence over a 30-minute period, a graduated adjustment follows (clause 8):

and the rating level over a reference time interval combines the adjusted sub-interval levels (clause 8, Note 1). An impulse qualifies when its onset rate exceeds 10 dB/s (clauses 4.5-4.7); non-qualifying level rises receive no adjustment (clause 8 applies only “for sounds with onset rates larger than 10 dB/s”).

ISO/PAS 1996-3:2022 is the measurement chain that reads those same two quantities from a calibrated time signal, and categorises the source by the adjustment it earns (typically 0.0 dB to 9.0 dB):

  • the A frequency-weighted, F time-weighted sound pressure level LpAF is computed from the signal and sampled at 10-25 ms intervals (Clause 4);
  • an onset is a contiguous part of the positive slope of LpAF where the gradient exceeds 10 dB/s; its starting and end points are found from procedures a) to d) of Clause 4, merging events separated by less than 50 ms (Clause 3.3, Figure 2);
  • for each onset the level difference and the onset rate OR (the least-squares slope over the onset) are measured (Clauses 3.4, 3.5, Figures 1 and 2);
  • the prominence (Clause 5, Formula 2) and the adjustment dB for (Clause 6, Formula 3) are the NT ACOU 112 formulae above;
  • the source is categorised (Clause 7) as not impulsive (), regular impulsive () or highly impulsive ().

The ISO/PAS method for determining KI is not sensitive to the absolute calibration of the equipment (Clause 8): onset rate and level difference are level differences, so the adjustment is unchanged by a constant offset. Only the reported LAeq and the adjusted LAeq depend on calibration.

Auto-generated from the source docstrings by scripts/generate_api_docs.py (make api-docs). Do not edit by hand.

detect_onsets(
levels: ArrayLike,
dt: float,
*,
onset_rate_method: _OnsetRateMethod = 'least_squares',
) -> tuple[ImpulseOnset, ...]

Detect the onsets in an LpAF level history (Clause 4).

Applies procedures a) to d) of the standard: the starting point is the first sample where the gradient exceeds 10 dB/s, the end point the first later sample where it drops below 10 dB/s, and onsets separated by less than 50 ms are merged. Each onset carries its level difference (3.4), its onset rate (3.5) and its prominence P.

Parameters

NameDescription
levelsA-weighted, F time-weighted level history LpAF, in dB, uniformly sampled with interval dt.
dtSampling interval of levels, in seconds (must be positive).
onset_rate_method"least_squares" (default) fits the whole onset; "upper_half" fits the upper half of the slope, the variant for pass-bys of road vehicles, trains or aircraft (3.5, Note 1).

Returns: The detected onsets, ordered in time (empty when none is found).

Raises

ExceptionWhen
ValueErrorfor a non-positive dt or fewer than two samples.
impulse_adjustment(prominence: ArrayLike) -> np.ndarray

Adjustment KI to LAeq from the prominence (clause 8, Formula 2).

dB for , else 0 dB. The adjustment is made to LAeq,30min on the basis of the single impulse with the highest P. This helper applies the bare Formula 2; the clause 8 onset-rate qualification (> 10 dB/s, clause 4.5) is enforced by impulse_prominence.

Parameters

NameDescription
prominencePredicted prominence P.

Returns: The adjustment KI, in dB, clamped at zero.

impulse_prominence(
onset_rates: ArrayLike,
level_differences: ArrayLike,
*,
assessment_period_min: float = 30.0,
) -> ImpulseProminenceResult

Governing prominence and adjustment of a set of impulses (clauses 7-8).

Evaluates the predicted prominence of each candidate impulse (Formula 1), takes the highest among the qualifying impulses as the governing prominence (clause 7) and derives its LAeq adjustment (Formula 2). An event qualifies as an impulse only when its onset rate exceeds 10 dB/s (clause 4.5); clause 8 applies the adjustment “for sounds with onset rates larger than 10 dB/s” only, so non-qualifying events cannot produce a KI (an ImpulseProminenceWarning reports them and the adjustment is 0 dB when no event qualifies).

Parameters

NameDescription
onset_ratesOnset rate of each impulse, in dB/s (> 0).
level_differencesLevel difference of each impulse, in dB (> 0).
assessment_period_minThe assessment time interval the impulses were selected over, in minutes; the standard’s default is 30 min (Clause 5), and the value is carried through to the fiche.

Returns: An ImpulseProminenceResult with the per-impulse and governing values and .plot().

Raises

ExceptionWhen
ValueErrorfor empty input, mismatched lengths, a non-positive onset rate or level difference, or an assessment period that is not positive and finite.
ImpulseOnset(
index_start: int,
index_end: int,
time_start: float,
time_end: float,
level_start: float,
level_end: float,
level_difference: float,
onset_rate: float,
prominence: float,
qualifies: bool,
)

A single detected onset of LpAF (ISO/PAS 1996-3, Clause 3).

Attributes

NameDescription
index_startSample index of the starting point s.
index_endSample index of the end point e.
time_startTime of the starting point, in seconds.
time_endTime of the end point, in seconds.
level_startLevel Ls at the starting point, in dB.
level_endLevel Le at the end point, in dB.
level_differenceLevel difference , in dB (3.4).
onset_rateOnset rate OR, in dB/s, the least-squares slope over the onset (3.5).
prominencePredicted prominence P of this onset (Formula 2).
qualifiesWhether the onset rate exceeds 10 dB/s, so the onset can contribute an adjustment (Clause 6).
ImpulseProminenceResult(
onset_rates: np.ndarray,
level_differences: np.ndarray,
per_impulse: np.ndarray,
qualifies: np.ndarray,
prominence: float,
adjustment: float,
assessment_period_min: float = 30.0,
)

Prominence of a set of candidate impulses (NT ACOU 112:2002).

Attributes

NameDescription
onset_ratesOnset rate of each impulse, in dB/s.
level_differencesLevel difference of each impulse, in dB.
per_impulsePredicted prominence P of each impulse (Formula 1).
qualifiesWhether each event qualifies as an impulse: onset rate above 10 dB/s (clause 4.5; clause 8 applies the adjustment “for sounds with onset rates larger than 10 dB/s” only).
prominenceThe governing prominence: the highest P among the qualifying impulses (clause 7), or the highest overall (informational) when none qualifies.
adjustmentThe LAeq adjustment KI, in dB, of the governing qualifying impulse (Formula 2); 0 dB when no event qualifies.
assessment_period_minThe assessment time interval the impulses were selected over, in minutes (Clause 5; 30 min by default).
ImpulseProminenceResult.plot(
ax: Axes | None = None,
*,
language: str = 'en',
**kwargs: Any,
) -> Axes

Plot the adjustment curve KI(P) with the impulses marked.

Requires matplotlib (pip install phonometry[plot]); returns the Axes.

ImpulseProminenceResult.report(
path: str,
*,
metadata: ReportMetadata | None = None,
engine: str = 'reportlab',
verbose: bool = False,
language: str = 'en',
) -> str

Render an impulsive-sound prominence assessment fiche to a PDF.

Writes a one-page assessment report following NT ACOU 112:2002 (carried into ISO/PAS 1996-3:2022): the standard-basis line, an optional metadata header (source/situation, client, measurement position, instrumentation and date, always followed by this result’s assessment_period_min), a full-width per-impulse table (onset rate, level difference, predicted prominence P and whether the onset qualifies as an impulse) above the adjustment-curve plot KI(P) with the candidate impulses marked, the boxed governing prominence P and the derived LAeq adjustment KI (Formula 2), an optional verdict row and a prominence-category note, and a footer with the fixed disclaimer.

Parameters

NameDescription
pathDestination path of the PDF file.
metadataOptional ReportMetadata; None produces a bare assessment fiche (body, result and disclaimer only). A supplied requirement is read as the maximum acceptable governing prominence P (a lower prominence passes).
engineRendering back end; only "reportlab" is supported.
verboseAccepted for signature parity with the other fiches; the per-impulse table already shows every candidate, so it has no effect.
languageFiche language: "en" (default, English) or "es" (Spanish, with a comma decimal separator).

Returns: The written path as a str.

Raises

ExceptionWhen
ValueErrorIf language is not one of the supported languages, or if engine is not "reportlab".
ImportErrorIf reportlab is not installed (pip install phonometry[report]), or matplotlib is missing for the embedded figure (pip install phonometry[plot]).

A supplied level rise does not qualify as an impulse (clause 4.5).

impulsive_sound_adjustment(
signal: ArrayLike,
fs: float,
*,
dt: float = 0.02,
reference_pressure: float = 2e-05,
calibration_offset: float = 0.0,
onset_rate_method: _OnsetRateMethod = 'least_squares',
laeq: float | None = None,
) -> ImpulsiveSoundResult

Objective prominence adjustment of an impulsive interval (ISO/PAS 1996-3).

Computes the LpAF history from the calibrated signal (Clause 4), detects the onsets, evaluates the prominence of each and returns the governing adjustment KI (Formula 3) of the most prominent qualifying impulse, together with the source category (Clause 7) and the adjusted LAeq.

Parameters

NameDescription
signalCalibrated sound pressure signal of the candidate event, in pascal.
fsSampling rate of signal, in Hz.
dtTarget LpAF sampling interval, in seconds (10-25 ms).
reference_pressureReference pressure, in pascal (default 20 uPa).
calibration_offsetLevel offset, in dB, for signals not scaled to pascal. The adjustment KI is unaffected by it (Clause 8); only the reported levels shift.
onset_rate_method"least_squares" (default) or "upper_half" for pass-bys (3.5, Note 1).
laeqEquivalent level of the interval, in dB; when omitted it is computed from the A-weighted signal energy.

Returns: An ImpulsiveSoundResult with the level history, onsets, prominence, adjustment, category and adjusted LAeq.

Raises

ExceptionWhen
ValueErrorfor invalid fs, dt or an empty signal.
ImpulsiveSoundResult(
times: np.ndarray,
levels: np.ndarray,
dt: float,
onsets: tuple[ImpulseOnset, ...],
prominence: float,
adjustment: float,
category: str,
laeq: float,
adjusted_laeq: float,
)

Objective prominence of an impulsive interval (ISO/PAS 1996-3:2022).

Attributes

NameDescription
timesTime of each LpAF sample, in seconds.
levelsA-weighted, F time-weighted level LpAF, in dB.
dtSampling interval of levels, in seconds.
onsetsThe detected onsets, ordered in time (Clause 4).
prominenceGoverning prominence P: the highest P among the qualifying onsets (Clause 5); nan when none qualifies.
adjustmentThe LAeq adjustment KI, in dB (Formula 3); 0 dB when no onset qualifies.
categorySource category (Clause 7): "not impulsive", "regular impulsive" or "highly impulsive".
laeqA-weighted equivalent level of the interval, in dB.
adjusted_laeqlaeq + adjustment, in dB.

property

The qualifying onset with the highest prominence, or None.

ImpulsiveSoundResult.plot(
ax: Axes | None = None,
*,
language: str = 'en',
**kwargs: Any,
) -> Axes

Plot LpAF versus time with the detected onsets marked.

Draws the level history, the starting/end points of each onset, the least-squares onset line and the level difference of the governing impulse, annotated with the prominence, adjustment and category.

Requires matplotlib (pip install phonometry[plot]); returns the Axes.

No qualifying onset (gradient > 10 dB/s) was found in the interval.

predicted_prominence(
onset_rate: ArrayLike,
level_difference: ArrayLike,
) -> np.ndarray

Predicted prominence P of an impulse (NT ACOU 112, clause 7).

(Formula 1), with the base-10 logarithm. Both quantities are read from the A-weighted, time-weighting-F level history: the onset rate is the slope of the onset in dB/s and the level difference is the level rise over the onset in dB (clauses 4.6-4.7). An impulse qualifies when its onset rate exceeds ONSET_RATE_LIMIT (10 dB/s).

Parameters

NameDescription
onset_rateOnset rate(s), in dB/s (> 0).
level_differenceLevel difference(s), in dB (> 0).

Returns: The predicted prominence P (scalar inputs give a 0-d array).

Raises

ExceptionWhen
ValueErrorfor a non-positive onset rate or level difference.
rating_level(
laeq: ArrayLike,
adjustment: ArrayLike,
durations: ArrayLike,
reference_time: float,
) -> float

Rating level over a reference time interval (clause 8, Note 1).

Combines the impulse-adjusted equivalent levels of the measurement sub-intervals into a single rating level:

Parameters

NameDescription
laeqEquivalent level LAeq,N of each sub-interval, in dB.
adjustmentAdjustment KI,N of each sub-interval, in dB.
durationsDuration dt_N of each sub-interval (any time unit, consistent with reference_time).
reference_timeReference time interval T (same unit as durations); commonly the sum of the durations.

Returns: The rating level LAr,T, in dB.

Raises

ExceptionWhen
ValueErrorfor mismatched lengths or a non-positive time.
sound_pressure_level_history(
signal: ArrayLike,
fs: float,
*,
dt: float = 0.02,
reference_pressure: float = 2e-05,
calibration_offset: float = 0.0,
) -> tuple[np.ndarray, np.ndarray]

A frequency-weighted, F time-weighted level history LpAF (Clause 4).

The signal is A-weighted (IEC 61672-1), F time-weighted ( ms) and sampled at intervals dt in the 10-25 ms range required by the standard.

Parameters

NameDescription
signalCalibrated sound pressure signal, in pascal.
fsSampling rate of signal, in Hz.
dtTarget sampling interval of LpAF, in seconds (10-25 ms).
reference_pressureReference pressure, in pascal (default 20 uPa).
calibration_offsetLevel offset added to LpAF, in dB, for signals recorded on a scale other than pascal.

Returns: (times, levels), the sample times in seconds and LpAF in dB. The realised interval is times[1] - times[0] and may differ slightly from dt because it is an integer number of samples.

Raises

ExceptionWhen
ValueErrorfor a non-positive fs or dt outside 10-25 ms.