Air Temperature from Sonic Temperature

Calculate air temperature from sonic temperature and water vapor concentration.

Sonic anemometers measure temperature indirectly through the speed of sound. This example shows how to correct sonic temperature to true air temperature using water vapor concentration for realistic eddy covariance measurements.

Best for: High-resolution (10 Hz, 20 Hz) eddy covariance time series correction.

Air temperature from sonic temperature

Sonic anemometers measure the speed of sound between transducer pairs. This speed depends on both air temperature and humidity. The measured “sonic temperature” must be corrected using water vapor concentration to get true air temperature.

import numpy as np
import pandas as pd
import diive as dv

Create realistic example data

Generate 3-day time series with diurnal patterns (typical for tower data)

# Create 30-minute time series for 3 days
dates = pd.date_range('2024-01-01', periods=144, freq='30min')

# Realistic sonic temperature (280-310 K, ~7-37°C) with diurnal pattern
sonic_temp = pd.Series(
    295 + 10 * np.sin(np.arange(144) * 2 * np.pi / 48),
    index=dates,
    name='sonic_temp'
)

# Realistic water vapor concentration (0.005-0.025 mol/mol) with diurnal pattern
h2o = pd.Series(
    0.015 + 0.01 * np.sin(np.arange(144) * 2 * np.pi / 48),
    index=dates,
    name='h2o'
)

print("Air Temperature from Sonic Temperature")
print("=" * 50)
print(f"Sonic temperature range: {sonic_temp.min():.2f} to {sonic_temp.max():.2f} K "
      f"({sonic_temp.min() - 273.15:.1f} to {sonic_temp.max() - 273.15:.1f}°C)")
print(f"Water vapor concentration: {h2o.min():.4f} to {h2o.max():.4f} mol/mol")
Air Temperature from Sonic Temperature
==================================================
Sonic temperature range: 285.00 to 305.00 K (11.9 to 31.9°C)
Water vapor concentration: 0.0050 to 0.0250 mol/mol

Calculate air temperature

Apply the correction using the Striednig et al. (2020) formula

air_temp = dv.variables.air_temp_from_sonic_temp(sonic_temp=sonic_temp, h2o=h2o)

print(f"\nAir temperature range: {air_temp.min():.2f} to {air_temp.max():.2f} K "
      f"({air_temp.min() - 273.15:.1f} to {air_temp.max() - 273.15:.1f}°C)")
print(f"Temperature correction: {(sonic_temp - air_temp).mean():.3f} K on average")
Air temperature range: 284.54 to 302.58 K (11.4 to 29.4°C)
Temperature correction: 1.424 K on average

Comparison and interpretation

Visualize the relationship between sonic temperature, water vapor, and air temperature

df = pd.DataFrame({
    'Sonic Temp (K)': sonic_temp,
    'Air Temp (K)': air_temp,
    'H2O (mol/mol)': h2o
})

print("\nFirst 10 rows:")
print(df.head(10).to_string())
First 10 rows:
                     Sonic Temp (K)  Air Temp (K)  H2O (mol/mol)
2024-01-01 00:00:00      295.000000    293.590764       0.015000
2024-01-01 00:30:00      296.305262    294.767260       0.016305
2024-01-01 01:00:00      297.588190    295.922672       0.017588
2024-01-01 01:30:00      298.826834    297.037307       0.018827
2024-01-01 02:00:00      300.000000    298.092210       0.020000
2024-01-01 02:30:00      301.087614    299.069482       0.021088
2024-01-01 03:00:00      302.071068    299.952580       0.022071
2024-01-01 03:30:00      302.933533    300.726582       0.022934
2024-01-01 04:00:00      303.660254    301.378433       0.023660
2024-01-01 04:30:00      304.238795    301.897156       0.024239

Key insights

The correction typically reduces sonic temperature by 1-2 K depending on humidity. Higher water vapor concentrations require larger corrections because water vapor affects the speed of sound more than dry air. This correction is essential for accurate flux calculations in eddy covariance systems.

diff = sonic_temp - air_temp
corr = diff.corr(h2o)
print(f"\nRelationship between correction and water vapor:")
print(f"  Correlation between (Sonic T - Air T) and H2O: {corr:.3f}")
print(f"  Meaning: When H2O concentration increases, the temperature correction")
print(f"  also increases. Perfect 1.0 correlation means they move together exactly")
print(f"  due to the diurnal cycle (warm days = more moisture + larger correction).")
print(f"\nCorrection statistics:")
print(f"  Mean: {diff.mean():.3f} K")
print(f"  Range: {diff.min():.3f} to {diff.max():.3f} K")
Relationship between correction and water vapor:
  Correlation between (Sonic T - Air T) and H2O: 1.000
  Meaning: When H2O concentration increases, the temperature correction
  also increases. Perfect 1.0 correlation means they move together exactly
  due to the diurnal cycle (warm days = more moisture + larger correction).

Correction statistics:
  Mean: 1.424 K
  Range: 0.455 to 2.421 K

Total running time of the script: (0 minutes 0.006 seconds)

Gallery generated by Sphinx-Gallery