# mackshema/pollution_prediction architecture

> Architecture diagram of the GitHub repository mackshema/pollution_prediction, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mackshema/pollution_prediction
- Repository: https://github.com/mackshema/pollution_prediction

## Overview

AirGuard collects city sensor readings and live wind, combines them with historical wind trajectories and satellite pollution data to build a training dataset, then cleans and trains a forecasting model. Its separate live prediction process reads the latest IoT and wind CSV data, estimates pollution and wind-driven spread, and writes forecasts that the dashboard presents on maps and charts. The README also describes risk alerts. Evidence is strongest for the excerpted scripts; the documented Bi-LSTM training and the live predictor’s Random Forest/scaler artifacts do not line up, so no model handoff between them is asserted.

Main entry points: [`pollution_ai_project/iot_gateway.py`](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/iot_gateway.py) (Sensor Readings), [`pollution_ai_project/merge_datasets.py`](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/merge_datasets.py) (Dataset Merge), [`pollution_ai_project/dashboard.py`](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/dashboard.py) (Monitoring Dashboard), [`pollution_ai_project/live_wind_feed.py`](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/live_wind_feed.py) (Live Wind Buffer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Data Ingestion"]
  node_gateway["Sensor Gateway<br/>[iot_gateway.py]"]
  node_iotcsv["Sensor Readings<br/>[iot_gateway.py]"]
  node_windcollector["Wind Collector<br/>[live_wind_feed.py]"]
  node_windcsv["Live Wind Buffer<br/>[live_wind_feed.py]"]
end

subgraph group_history["Historical Data"]
  node_era5["ERA5 Download<br/>[era5_download.py]"]
  node_trajectory["Wind Trajectories"]
  node_sentinel["Sentinel-5P Export"]
  node_fusion["Dataset Merge<br/>[merge_datasets.py]"]
  node_trainingdata["Training Dataset<br/>[merge_datasets.py]"]
  node_cleaner["Data Cleaning"]
  node_cleandata["Clean Dataset"]
end

subgraph group_model["Training and Inference"]
  node_trainer["Model Training"]
  node_modelartifact["Trained Model"]
  node_predictor["Live Predictor"]
  node_predictions["Prediction Output"]
end

subgraph group_present["Monitoring and Output"]
  node_dashboard["Monitoring Dashboard<br/>[dashboard.py]"]
end

node_sensor(("IoT Sensors"))
node_mqtt["MQTT Broker"]
node_weather(("Open-Meteo"))
node_era5service(("Climate Data Store"))
node_earthengine(("Google Earth Engine"))
node_officials(("City Authorities"))

node_sensor -->|"publishes readings"| node_mqtt
node_gateway -->|"subscribes to"| node_mqtt
node_gateway -->|"appends readings"| node_iotcsv
node_weather -->|"provides wind"| node_windcollector
node_windcollector -->|"appends readings"| node_windcsv
node_era5service -->|"serves reanalysis"| node_era5
node_era5 -->|"downloads wind data"| node_trajectory
node_era5 -->|"reads NetCDF"| node_trajectory
node_earthengine -->|"provides imagery"| node_sentinel
node_iotcsv -->|"loads readings"| node_fusion
node_trajectory -->|"loads trajectories"| node_fusion
node_sentinel -->|"loads pollution CSV"| node_fusion
node_fusion -->|"writes merged data"| node_trainingdata
node_trainingdata -->|"loads dataset"| node_cleaner
node_cleaner -->|"writes clean data"| node_cleandata
node_cleandata -->|"loads training rows"| node_trainer
node_trainer -->|"saves model"| node_modelartifact
node_iotcsv -->|"reads latest sensor"| node_predictor
node_windcsv -->|"reads latest wind"| node_predictor
node_predictor -->|"writes forecasts"| node_predictions
node_iotcsv -->|"loads sensor data"| node_dashboard
node_windcsv -->|"loads wind data"| node_dashboard
node_predictions -->|"loads forecasts"| node_dashboard
node_dashboard -->|"presents forecasts"| node_officials

click node_gateway "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/iot_gateway.py"
click node_iotcsv "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/iot_gateway.py"
click node_windcollector "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/live_wind_feed.py"
click node_windcsv "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/live_wind_feed.py"
click node_era5 "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/era5_download.py"
click node_trajectory "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/convert_wind_to_trajectory.py"
click node_sentinel "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/sentinel5p_download.py"
click node_fusion "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/merge_datasets.py"
click node_trainingdata "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/merge_datasets.py"
click node_cleaner "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/clean_training_data.py"
click node_cleandata "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/clean_training_data.py"
click node_trainer "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/train_pollution_model.py"
click node_modelartifact "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/train_pollution_model.py"
click node_predictor "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/predict_pollution.py"
click node_predictions "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/predict_pollution.py"
click node_dashboard "https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/dashboard.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gateway,node_iotcsv,node_windcollector,node_windcsv toneBlue
class node_era5,node_trajectory,node_sentinel,node_fusion,node_trainingdata,node_cleaner,node_cleandata toneAmber
class node_trainer,node_modelartifact,node_predictor,node_predictions toneMint
class node_dashboard toneRose
class node_sensor,node_mqtt,node_weather,node_era5service,node_earthengine,node_officials toneIndigo
```

## Components

### Data Ingestion

- [Sensor Gateway](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/iot_gateway.py): `pollution_ai_project/iot_gateway.py`
- [Sensor Readings](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/iot_gateway.py): `pollution_ai_project/iot_gateway.py`
- [Wind Collector](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/live_wind_feed.py): `pollution_ai_project/live_wind_feed.py`
- [Live Wind Buffer](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/live_wind_feed.py): `pollution_ai_project/live_wind_feed.py`

### Historical Data

- [ERA5 Download](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/era5_download.py): `pollution_ai_project/era5_download.py`
- [Wind Trajectories](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/convert_wind_to_trajectory.py): `pollution_ai_project/convert_wind_to_trajectory.py`
- [Sentinel-5P Export](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/sentinel5p_download.py): `pollution_ai_project/sentinel5p_download.py`
- [Dataset Merge](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/merge_datasets.py): `pollution_ai_project/merge_datasets.py`
- [Training Dataset](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/merge_datasets.py): `pollution_ai_project/merge_datasets.py`
- [Data Cleaning](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/clean_training_data.py): `pollution_ai_project/clean_training_data.py`
- [Clean Dataset](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/clean_training_data.py): `pollution_ai_project/clean_training_data.py`

### Training and Inference

- [Model Training](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/train_pollution_model.py): `pollution_ai_project/train_pollution_model.py`
- [Trained Model](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/train_pollution_model.py): `pollution_ai_project/train_pollution_model.py`
- [Live Predictor](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/predict_pollution.py): `pollution_ai_project/predict_pollution.py`
- [Prediction Output](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/predict_pollution.py): `pollution_ai_project/predict_pollution.py`

### Monitoring and Output

- [Monitoring Dashboard](https://github.com/mackshema/pollution_prediction/blob/main/pollution_ai_project/dashboard.py): `pollution_ai_project/dashboard.py`

### Other components

- **IoT Sensors**
- **MQTT Broker**
- **Open-Meteo**
- **Climate Data Store**
- **Google Earth Engine**
- **City Authorities**

## Connections

- IoT Sensors → MQTT Broker: publishes readings
- Sensor Gateway → MQTT Broker: subscribes to (evidence: `pollution_ai_project/iot_gateway.py`)
- Sensor Gateway → Sensor Readings: appends readings (evidence: `pollution_ai_project/iot_gateway.py`)
- Open-Meteo → Wind Collector: provides wind (evidence: `pollution_ai_project/live_wind_feed.py`)
- Wind Collector → Live Wind Buffer: appends readings (evidence: `pollution_ai_project/live_wind_feed.py`)
- Climate Data Store → ERA5 Download: serves reanalysis (evidence: `pollution_ai_project/era5_download.py`)
- ERA5 Download → Wind Trajectories: downloads wind data (evidence: `pollution_ai_project/era5_download.py`)
- ERA5 Download → Wind Trajectories: reads NetCDF (evidence: `pollution_ai_project/convert_wind_to_trajectory.py`)
- Google Earth Engine → Sentinel-5P Export: provides imagery (evidence: `pollution_ai_project/sentinel5p_download.py`)
- Sensor Readings → Dataset Merge: loads readings (evidence: `pollution_ai_project/merge_datasets.py`)
- Wind Trajectories → Dataset Merge: loads trajectories (evidence: `pollution_ai_project/merge_datasets.py`)
- Sentinel-5P Export → Dataset Merge: loads pollution CSV (evidence: `pollution_ai_project/merge_datasets.py`)
- Dataset Merge → Training Dataset: writes merged data (evidence: `pollution_ai_project/merge_datasets.py`)
- Training Dataset → Data Cleaning: loads dataset (evidence: `pollution_ai_project/clean_training_data.py`)
- Data Cleaning → Clean Dataset: writes clean data (evidence: `pollution_ai_project/clean_training_data.py`)
- Clean Dataset → Model Training: loads training rows (evidence: `pollution_ai_project/train_pollution_model.py`)
- Model Training → Trained Model: saves model (evidence: `pollution_ai_project/train_pollution_model.py`)
- Sensor Readings → Live Predictor: reads latest sensor (evidence: `pollution_ai_project/predict_pollution.py`)
- Live Wind Buffer → Live Predictor: reads latest wind (evidence: `pollution_ai_project/predict_pollution.py`)
- Live Predictor → Prediction Output: writes forecasts (evidence: `pollution_ai_project/predict_pollution.py`)
- Sensor Readings → Monitoring Dashboard: loads sensor data (evidence: `pollution_ai_project/dashboard.py`)
- Live Wind Buffer → Monitoring Dashboard: loads wind data (evidence: `pollution_ai_project/dashboard.py`)
- Prediction Output → Monitoring Dashboard: loads forecasts (evidence: `pollution_ai_project/dashboard.py`)
- Monitoring Dashboard → City Authorities: presents forecasts (evidence: `README.md`)
