Utility Modules
Environment Temperature Estimation
Environment Temperature Estimation
Provides functions to estimate ambient/environment temperature from thermal frames.
- pythermal.utils.environment.estimate_environment_temperature(temp_array: ndarray, min_temp: float, max_temp: float, percentile: float = 5.0) float | None[source]
Estimate environment temperature from a thermal frame.
Version 1: Uses the 5th percentile of frame temperatures as environment temperature. This assumes that the coldest pixels represent the ambient/room temperature, as they are least affected by heat sources.
- Parameters:
temp_array – Temperature array (96x96, uint16 raw values or float32 Celsius)
min_temp – Minimum temperature in Celsius from metadata
max_temp – Maximum temperature in Celsius from metadata
percentile – Percentile to use for estimation (default: 5.0 for 5th percentile)
- Returns:
Estimated environment temperature in Celsius, or None if input is invalid
- pythermal.utils.environment.estimate_environment_temperature_v1(temp_array: ndarray, min_temp: float, max_temp: float, smoothing: bool = True, smoothing_factor: float = 0.3) float | None[source]
Estimate environment temperature using version 1 method with optional smoothing filter.
Uses the 5th percentile method and applies exponential moving average smoothing to reduce noise and provide stable estimates.
- Parameters:
temp_array – Temperature array (96x96, uint16 raw values or float32 Celsius)
min_temp – Minimum temperature in Celsius from metadata
max_temp – Maximum temperature in Celsius from metadata
smoothing – Whether to apply smoothing filter (default: True)
smoothing_factor – Smoothing factor for exponential moving average (default: 0.3) Lower values (0.1-0.3) = more smoothing, slower response Higher values (0.4-0.7) = less smoothing, faster response
- Returns:
Estimated environment temperature in Celsius (5th percentile, smoothed), or None if input is invalid
- pythermal.utils.environment.reset_environment_temperature_smoothing()[source]
Reset the smoothing filter state.
Call this when starting a new session or when you want to clear the smoothing history.
- pythermal.utils.environment.get_environment_temperature_history() list[source]
Get the history of raw environment temperature estimates.
- Returns:
List of recent raw temperature estimates
- pythermal.utils.environment.estimate_body_temperature(environment_temp: float, alpha: float = 0.6, core_temp: float = 37.0) float[source]
Estimate body (skin) temperature from environment temperature.
Uses the formula: Ts = Te + α × (Tc − Te)
Where: - Ts = Skin temperature (estimated body temperature) - Te = Environment temperature - Tc = Core body temperature (default: 37°C) - α = Blood flow regulation coefficient
- Parameters:
environment_temp – Environment/room temperature in Celsius
alpha – Blood flow regulation coefficient (default: 0.6) - Face/torso: α ≈ 0.5–0.7 (default: 0.6) - Hands/feet: α ≈ 0.2–0.4
core_temp – Core body temperature in Celsius (default: 37.0)
- Returns:
Estimated body (skin) temperature in Celsius
Examples
>>> # Face/torso at 10°C room temperature >>> estimate_body_temperature(10.0, alpha=0.6) 26.2 # ≈ 10 + 0.6 × (37 - 10) = 26.2°C
>>> # Hands/feet at 10°C room temperature >>> estimate_body_temperature(10.0, alpha=0.25) 16.75 # ≈ 10 + 0.25 × (37 - 10) = 16.75°C