inferenceWGBT.ts
Purpose
This module computes Wet Bulb Globe Temperature (WBGT) values from meteorological inputs using two XGBoost-derived ONNX models: one predicting Natural Wet Bulb temperature (NWB) and one predicting Globe Temperature (GT).
Its responsibilities include:
- Loading and caching ONNX sessions for the NWB and GT models
- Constructing a shared
[Ta, Wind, Solar, RH]feature tensor - Running both models against the same input
- Combining the model outputs into WBGT estimates for both sun and shade conditions
- Validating that air temperature is a finite number before inference
Invariants
Air Temperature Validation
inputArray[0] (air temperature, Ta) must be a finite number.
Invalid values throw a descriptive Error before any model session is created or run.
Fixed Input Layout
The input tensor always has shape [1, 4] with a fixed column order:
[Ta, Wind, Solar, RH]
Both models receive the identical tensor. Column order must not be changed without retraining both models.
WBGT Combination Formulas
Sun and shade WBGT are computed from model outputs using fixed meteorological weighting coefficients:
wbgtSun = 0.7 × NWB + 0.2 × GT + 0.1 × Ta
wbgtShade = 0.7 × NWB + 0.3 × GT
Variants
Session Caching
Both ONNX sessions are loaded and cached via getOnnxSession. Subsequent calls within the same process lifetime reuse the cached sessions without re-loading model files from disk.
Exports
InferenceResult
type InferenceResult = {
predictedNWB: number;
predictedGT: number;
wbgtSun: number;
wbgtShade: number;
};
Contains raw model outputs and derived WBGT estimates:
| Field | Description |
|---|---|
predictedNWB | Natural Wet Bulb temperature (°C) |
predictedGT | Globe Temperature (°C) |
wbgtSun | WBGT in direct sunlight conditions |
wbgtShade | WBGT in shaded conditions |
runInference(...)
async function runInference(inputArray: number[]): Promise<InferenceResult>
Runs NWB and GT ONNX models and returns combined WBGT estimates.
Parameters
| Parameter | Description |
|---|---|
inputArray | [Ta, Wind, Solar, RH] — air temperature (°C), wind speed (m/s), solar radiation (W/m²), relative humidity (%) |
Returns
A Promise<InferenceResult> with raw model predictions and computed WBGT for sun and shade.
Throws
Throws when:
inputArray[0](air temperature) is not a finite number- Either ONNX session fails to load or run