app.imputation module#

Impute missing weather observation values on a fixed five-minute cadence.

This module detects and fills gaps in the time series of weather observations per coordinate. It aligns data to a regular 5-minute timeline and imputes values either via a weighted average of the most recent actual observations or, when there are not enough prior points, via time-based linear interpolation. The result is a consistent dataset suitable for downstream training and analytics.

See Also#

app.weather_ingest

Acquires raw observations that may require imputation.

app.models.WeatherObservation

ORM entity persisted/created by this module.

app.training_helpers

Utilities used by the model training pipeline.

Notes#

  • Alignment frequency is 5T (five minutes), controlled by TIME_FREQUENCY.

  • Weighted imputation relies on at most three prior non-imputed observations using weights from WEIGHT_ARRAY; otherwise linear interpolation is attempted.

  • Target features are listed in FEATURE_COLUMNS_TO_IMPUTE and are imputed independently.

  • This module depends on pandas, numpy, and SQLAlchemy ORM models.

Examples#

>>> # Run a single imputation cycle (database required)
>>> from app.imputation import run_imputation_cycle
>>> run_imputation_cycle()
app.imputation.run_imputation_cycle() None[source]#

Execute one full imputation pass over stored observations.

Loads observations, aligns each coordinate’s series to a 5-minute timeline, imputes missing rows using a weighted average of recent actual values (when sufficient history exists) or time-based linear interpolation, and merges the imputed rows back into the database.

Returns:
None

This function produces side effects only (database writes and logging).

Notes

  • Errors are logged with context and not re-raised to keep scheduled runs resilient; callers do not need to wrap this function in try/except.

  • Imputed values are marked using the is_imputed flag.

Examples

>>> # Requires a configured database and ORM models
>>> from app.imputation import run_imputation_cycle
>>> run_imputation_cycle()