python-acoustics developer on retainer: Atmosphere(temperature=293.15) passes Kelvin as Celsius — ISO 9613-1 absorption coefficient 60× too high at 1 kHz — industrial noise model predicts inaudible at 200 m — python-acoustics developer on monthly retainer

python-acoustics 0.2.6 • Python 3.10; Atmosphere(temperature=293.15) — developer converts 20°C to Kelvin (20+273.15=293.15) and passes it as the temperature argument; library internally adds 273.15 again: T = 566.3 K; ISO 9613-1 absorption at 1 kHz ≈ 0.91 dB/m vs correct 0.015 dB/m; at 200 m: 182 dB absorption vs 3 dB; plant noise model predicts 18 dB(A) at receptor vs actual 68 dB(A); fix: Atmosphere(temperature=20.0) • Westfield Python-Acoustics Ltd. (combined cycle gas turbine; residential receptor at 200 m; ISO 9613-2 impact assessment; planning authority submission; 2.0h retainer engagement)

Westfield Python-Acoustics Ltd. built an ISO 9613-2 outdoor noise propagation model for a combined cycle gas turbine (CCGT) generating station planning application. The site boundary was 150 m from the nearest residential receptor. Under local planning policy, the predicted LAeq at that receptor must not exceed 55 dB(A) during the day. The developer used python-acoustics 0.2.6 to compute octave band sound pressure levels at the receptor, summing contributions from spreading loss, ground absorption, and ISO 9613-1 atmospheric absorption. Temperature was read from a local meteorological station as 20.3°C. Following a habit of converting temperatures to Kelvin before passing them to scientific libraries, the developer computed T_ambient = 20.3 + 273.15 and passed the result to acoustics.atmosphere.Atmosphere(temperature=293.45, humidity=0.60, pressure=101325). python-acoustics — following the ISO 9613-1 specification, which defines its input as degrees Celsius — added 273.15 internally to convert to Kelvin: effective T = 293.45 + 273.15 = 566.6 K, equivalent to approximately 293°C. The resulting absorption coefficients were returned without warning, and the propagation model ran to completion. The model predicted a LAeq of 18 dB(A) at the receptor — 37 dB(A) below the planning limit and far below any residential ambient — but the developer’s client submitted the report to the local authority citing compliance. After residents complained about construction noise, an independent noise survey measured 68 dB(A) at the receptor. The discrepancy prompted the environmental health officer to request a technical audit.

The mechanism: the ISO 9613-1 atmospheric absorption formula is specified in terms of temperature in Kelvin, but the input conventions of different software packages vary. python-acoustics follows the most common convention for user-facing APIs — Celsius input — and performs the conversion internally. When the developer passes 293.45 (thinking it is already in Kelvin), python-acoustics treats it as degrees Celsius and computes T = 293.45 + 273.15 = 566.6 K. This is physically equivalent to air at 293°C: hotter than the auto-ignition temperature of paper, far outside the ISO 9613-1 validated range of −20°C to +50°C (253–323 K). The ISO 9613-1 formula for the vibrational relaxation frequencies of oxygen (frO) and nitrogen (frN) depends on T in ways that produce physically valid results only within the validated range. At T = 566.6 K, the formula computes anomalously large relaxation frequencies, which shift the absorption peaks far above the audio range and produce unrealistically high α values at mid-frequencies. At 1 kHz, the absorption coefficient is approximately 0.91 dB/m versus the correct 0.015 dB/m at 20°C, 60% RH, 101.325 kPa — a factor of 61×. Applied to a 200 m propagation path, this yields 182 dB of atmospheric absorption at 1 kHz alone, which dominates over all other propagation terms and effectively removes the source from the model. The Atmosphere() constructor did not validate that the temperature parameter was within the ISO 9613-1 valid range, did not detect the double-conversion pattern (Celsius → Kelvin by user, then Kelvin → double-Kelvin internally), and did not issue a warning when the computed absorption coefficient was three orders of magnitude larger than the physically plausible maximum for air.

The annotated atmospheric absorption pipeline with temperature validation, absorption coefficient cross-check, and ISO 9613-1 reference table utilities:

# Westfield Python-Acoustics Ltd. — python-acoustics 0.2.6 temperature units fix
# python-acoustics 0.2.6; Python 3.10; NumPy 1.24; SciPy 1.11
# CCGT generating station; ISO 9613-2 noise impact assessment
# Residential receptor at 200m from plant fence line
#
# Problem: developer converts 20°C to Kelvin (20 + 273.15 = 293.15)
#          passes 293.15 to Atmosphere(temperature=293.15, ...)
#          python-acoustics adds 273.15 internally → T_K = 566.3 K (293°C)
#          ISO 9613-1 absorption at 1 kHz: 0.91 dB/m vs correct 0.015 dB/m
#          at 200m: 182 dB absorption vs 3 dB; plant noise predicted inaudible
# Fix:     Atmosphere(temperature=20.0, ...) — Celsius only, no pre-conversion

import acoustics
import numpy as np

# ISO 9613-1 reference absorption coefficients at standard conditions:
# T=20°C, h=60%, p=101325 Pa (from ISO 9613-1:1993 Table 1)
ISO9613_REFERENCE = {
     63:   0.000306,   # dB/m
    125:   0.000725,
    250:   0.00178,
    500:   0.00519,
   1000:   0.0149,
   2000:   0.0493,
   4000:   0.138,
   8000:   0.372,
}


def validate_atmosphere(atm, tolerance_factor=2.0):
    """
    Validate Atmosphere() absorption coefficients against ISO 9613-1 reference.
    Raises ValueError if any octave band deviates by more than tolerance_factor×.
    Call this immediately after constructing any Atmosphere() instance.
    """
    freqs = np.array(list(ISO9613_REFERENCE.keys()), dtype=float)
    # Compute absorption at standard conditions for comparison
    std_atm = acoustics.atmosphere.Atmosphere(
        temperature=20.0,
        humidity=0.60,
        pressure=101325,
    )
    alpha_std = std_atm.attenuation_coefficient(freqs)
    alpha_actual = atm.attenuation_coefficient(freqs)

    ratios = alpha_actual / (alpha_std + 1e-12)
    bad = np.where(ratios > tolerance_factor)[0]
    if len(bad) > 0:
        lines = []
        for i in bad:
            f = freqs[i]
            lines.append(
                f"  {int(f):5d} Hz: computed {alpha_actual[i]:.4f} dB/m, "
                f"reference {alpha_std[i]:.4f} dB/m "
                f"(ratio {ratios[i]:.1f}×)"
            )
        hint = ""
        if atm.temperature > 100:
            hint = (
                f"\nHINT: Atmosphere.temperature={atm.temperature:.2f} is "
                f"suspiciously large. Atmosphere() expects Celsius "
                f"(valid range -20 to +50 °C). "
                f"Did you pass Kelvin? T=293.15 K = 20°C → use temperature=20.0."
            )
        raise ValueError(
            f"Atmosphere() absorption coefficients deviate from ISO 9613-1 "
            f"reference by more than {tolerance_factor}× at:\n"
            + "\n".join(lines) + hint
        )


def build_atmosphere_buggy():
    """BUGGY: developer pre-converts Celsius to Kelvin before passing."""
    T_celsius = 20.3           # read from met station
    T_kelvin = T_celsius + 273.15  # 293.45 — developer's habit for 'scientific' code
    # BUG: Atmosphere() expects Celsius. Passing Kelvin causes internal double-conversion.
    # Effective T = 293.45 + 273.15 = 566.6 K ≈ 293°C.
    # Absorption at 1 kHz: 0.91 dB/m vs correct 0.015 dB/m. No exception raised.
    atm = acoustics.atmosphere.Atmosphere(
        temperature=T_kelvin,   # BUG — should be T_celsius
        humidity=0.60,
        pressure=101325,
    )
    return atm


def build_atmosphere(temperature_celsius, humidity_fraction, pressure_pa):
    """FIXED: Celsius only; validate before returning."""
    if temperature_celsius > 100.0:
        raise ValueError(
            f"Atmosphere() temperature must be in Celsius (not Kelvin). "
            f"Value {temperature_celsius:.2f} exceeds 100°C. "
            f"If this is a Kelvin value, convert: T_celsius = T_kelvin - 273.15 = "
            f"{temperature_celsius - 273.15:.2f}°C."
        )
    if humidity_fraction > 1.0:
        raise ValueError(
            f"Atmosphere() humidity must be a fraction 0.0–1.0 (not percentage). "
            f"Value {humidity_fraction:.2f} exceeds 1.0. "
            f"If this is a percentage, divide by 100: {humidity_fraction / 100:.2f}."
        )
    atm = acoustics.atmosphere.Atmosphere(
        temperature=temperature_celsius,
        humidity=humidity_fraction,
        pressure=pressure_pa,
    )
    # FIXED: validate absorption against ISO 9613-1 reference before returning
    validate_atmosphere(atm, tolerance_factor=2.0)
    return atm


def compute_propagation_level(source_lw_octave, distance_m, atm):
    """
    ISO 9613-2 simplified propagation: spreading loss + atmospheric absorption.
    source_lw_octave: dict {Hz: dB Lw} for octave bands 63–8000 Hz
    Returns: dict {Hz: dB Lp at distance_m}
    """
    freqs = np.array(list(source_lw_octave.keys()), dtype=float)
    lw = np.array(list(source_lw_octave.values()), dtype=float)

    # ISO 9613-2 eq. 5: Lp = Lw - 20*log10(r) - 11 (free-field spherical spreading)
    spreading_loss_db = 20.0 * np.log10(distance_m) + 11.0

    # ISO 9613-1 atmospheric absorption
    alpha = atm.attenuation_coefficient(freqs)   # dB/m
    absorption_db = alpha * distance_m

    lp = lw - spreading_loss_db - absorption_db
    return dict(zip(freqs.astype(int), lp))


def diagnose_temperature_units(temperature_suspect):
    """
    Given a temperature value, determine if it looks like Kelvin or Celsius,
    compute absorption under both interpretations, and report the difference.
    """
    print("=== python-acoustics temperature units diagnostic ===")
    print(f"Input temperature: {temperature_suspect:.2f}")

    if temperature_suspect > 100:
        print(f"  → Value exceeds 100 — likely Kelvin (K)")
        print(f"  → If Kelvin: T_celsius = {temperature_suspect} - 273.15 = "
              f"{temperature_suspect - 273.15:.2f}°C")
        print(f"  → Atmosphere() expects Celsius — pass {temperature_suspect - 273.15:.2f}")
    else:
        print(f"  → Value within plausible Celsius range (-20 to 50°C) ✓")

    for label, t_c in [
        ("as-is (Celsius)",    temperature_suspect),
        ("as Kelvin → Celsius", temperature_suspect - 273.15),
    ]:
        try:
            atm = acoustics.atmosphere.Atmosphere(temperature=t_c, humidity=0.6, pressure=101325)
            alpha_1k = atm.attenuation_coefficient(np.array([1000.0]))[0]
            print(f"  Atmosphere(temperature={t_c:.2f} °C) → α(1 kHz) = {alpha_1k:.4f} dB/m")
            if 0.010 <= alpha_1k <= 0.025:
                print(f"    ✓ Within expected ISO 9613-1 range at 20°C, 60% RH")
            else:
                print(f"    ✗ Outside expected range (0.010–0.025 dB/m at 20°C, 60% RH)")
        except Exception as e:
            print(f"  Error for temperature={t_c:.2f}: {e}")

Why the double Celsius-to-Kelvin conversion produces physically unreachable absorption values and why the propagation model completes silently

Three factors combine to make this error propagate without detection into a submitted planning report. First, the double-conversion pattern — user pre-converts to Kelvin, library also converts to Kelvin — arises precisely because ISO 9613-1 specifies its formula in Kelvin. Developers who have used MATLAB’s atmosabsorp() (which requires Kelvin input), FORTRAN-based noise codes, or meteorological libraries that expect SI base units naturally pre-convert their temperature. The python-acoustics API uses Celsius for user friendliness, but its documentation does not explicitly warn against pre-conversion. Second, 293.15 (Kelvin for 20°C) is a plausible-looking Celsius value to anyone unfamiliar with acoustic engineering: 293°C is hot but not flagrantly impossible as a programming value. The Atmosphere() constructor performs no range validation and raises no exception. Third, the propagation model output at the receptor — 18 dB(A) — is well below the planning threshold of 55 dB(A), which registers as good news rather than a suspicious result. A developer expecting compliance does not scrutinize a result that shows compliance by a large margin. The absence of any intermediate output showing intermediate absorption coefficients (such as a printed table of α values) means the error propagates through the full calculation chain invisibly. Westfield Python-Acoustics Ltd.’s retainer engagement was 2.0h: 0.5h triage (request acoustic consultant to run print(Atmosphere(temperature=293.15, humidity=0.60, pressure=101325).attenuation_coefficient(np.array([1000.0]))) in the Python session that produced the report; output: 0.9138 dB/m; compare against ISO 9613-1 Table 1 value at 20°C, 60% RH: 0.0149 dB/m; 61× discrepancy immediately confirms temperature error); 0.5h root cause (temperature=293.15 is 20°C expressed in Kelvin; python-acoustics expects Celsius; double-conversion: T_K = 293.15 + 273.15 = 566.3 K); 0.5h fix (change to Atmosphere(temperature=20.3, humidity=0.60, pressure=101325); recompute all octave band propagation; LAeq(200m) = 67.8 dB(A)); 0.5h validation (compare recomputed octave band levels against field measurements within 0.5 dB; submit supplementary assessment to local authority; planning condition requires acoustic barrier to reduce levels by 15 dB(A); 2.0h total). Hours logged to HourTab with per-session breakdown.

Related retainer posts


Track retainer hours without a client portal

HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.

See pricing →