predictionWGBT.ts

Assembles meteorological inputs and runs the WBGT ONNX model for the current device location

Purpose

This module produces a WBGT (Wet Bulb Globe Temperature) prediction for the user’s current GPS location by combining cached weather data with a computed solar radiation estimate and running the WBGT ONNX inference model.

Its responsibilities include:

  • Resolving the current device GPS position
  • Retrieving the nearest cached weather point via getWeatherPointCached
  • Computing solar radiation from sky cover, date, and coordinates via computeSolarRadiation
  • Assembling the [Ta, Wind, Solar, RH] input vector in model-required order
  • Invoking runInference via a lazy require
  • Returning the full prediction payload including location, weather, inputs, and model outputs

Invariants

Weather Availability Requirement

If getWeatherPointCached throws a WeatherCacheMissError, it is caught and re-thrown as a WbgtWeatherUnavailableError with the original error as cause.

All other errors from the weather service are re-thrown unwrapped.


Fixed Input Column Order

The inference input vector is always assembled as:

[airTemp (°C), windSpeed (m/s), solarRadiation (W/m²), relativeHumidity (%)]

This order must not change without retraining the NWB and GT models.


Lazy ONNX Require

runInference is loaded via a lazy require() at call time to keep the native ONNX module out of app startup and to support Jest’s CommonJS runtime.


Exports

WbgtWeatherUnavailableError

class WbgtWeatherUnavailableError extends Error {
	name: "WbgtWeatherUnavailableError";
	cause?: unknown;
}

Thrown when WBGT prediction cannot proceed because no weather data is available for the current location.


makeWbgtPrediction()

const makeWbgtPrediction: () => Promise<{
	location: { lat: number; lon: number; elev: number };
	weather: WeatherPoint;
	input: number[];
	predictedNWB: number;
	predictedGT: number;
	wbgtSun: number;
	wbgtShade: number;
}>

Fetches device location, retrieves cached weather, computes solar radiation, and runs the WBGT model.

Throws

  • WbgtWeatherUnavailableError — when weather data cannot be resolved for the current location
  • Any error from getDeviceLocation or runInference