CoolFace
Apppublic

yunqianz/purpleair-temperature-calibration

sourceHugging Facemitupdated 8mo agoView on Hugging Face
0likes
App README

๐ŸŒก๏ธ PurpleAir Temperature Calibration

Accurate temperature monitoring for heat exposure research using machine learning calibration.

๐Ÿ“Š Overview

This application calibrates PurpleAir temperature sensor readings using trained XGBoost models. It reduces measurement errors by 90%, achieving an overall RMSE of 1.43ยฐC.

Key Features

  • โ€”โœ… 90% error reduction compared to uncalibrated sensors
  • โ€”โœ… Temperature-stratified models (Cold/Moderate/Hot conditions)
  • โ€”โœ… 63 engineered features including temporal dynamics
  • โ€”โœ… Automatic ERA5 data integration for meteorological variables
  • โ€”โœ… Real-time calibration with CSV upload
  • โ€”โœ… Validated on 2,682 sensors across 31 U.S. states (2018-2022)

๐ŸŽฏ Performance

Temperature RangeRMSEImprovement
Cold (<10ยฐC)1.52ยฐC88% reduction
Moderate (10-30ยฐC)1.38ยฐC91% reduction
Hot (>30ยฐC)1.45ยฐC89% reduction
Overall1.43ยฐC90% reduction

๐Ÿš€ How to Use

1. Prepare Your Data

๐Ÿ“ Spatial Model (31 features)

Required columns:

  • โ€”timestamp - Date/time (YYYY-MM-DD HH:MM:SS)
  • โ€”temperature - Current sensor temp (ยฐF or ยฐC)
  • โ€”humidity - Relative humidity (%)
  • โ€”latitude - Sensor latitude (-90 to 90)
  • โ€”longitude - Sensor longitude (-180 to 180)

Optional (improve accuracy):

  • โ€”elevation - Meters above sea level
  • โ€”tree_canopy_cover - Tree cover percentage
  • โ€”life or age - Days since deployment

Example:

csv
timestamp,temperature,humidity,latitude,longitude,elevation,life
2024-01-15 12:00:00,68.5,45.2,37.7749,-122.4194,15,450
โฑ๏ธ Temporal Model (61 features - Higher Accuracy)

All Spatial columns PLUS:

  • โ€”Historical data: Include at least 12 hours of prior readings before each target timestamp
  • โ€”Minimum 6 hours for basic functionality (26/30 temporal features)
  • โ€”Recommended 12 hours for full feature set (all 30 temporal features including 12h rolling statistics)
  • โ€”Upload CSV with multiple rows (one per hour) for the same sensor

Example (time series):

csv
timestamp,temperature,humidity,latitude,longitude,elevation,life
2024-01-15 06:00:00,65.2,48.5,37.7749,-122.4194,15,450
2024-01-15 07:00:00,66.8,47.1,37.7749,-122.4194,15,450
2024-01-15 08:00:00,67.3,46.8,37.7749,-122.4194,15,450
2024-01-15 09:00:00,67.9,45.9,37.7749,-122.4194,15,450
2024-01-15 10:00:00,68.1,45.5,37.7749,-122.4194,15,450
2024-01-15 11:00:00,68.4,45.3,37.7749,-122.4194,15,450
2024-01-15 12:00:00,68.5,45.2,37.7749,-122.4194,15,450  โ† Target

Auto-derived from your data:

  • โ€”โœ… Lagged features (temp/humidity 1-6h ago)
  • โ€”โœ… Rolling statistics (moving averages, std dev)
  • โ€”โœ… Cumulative radiation, temperature trends
  • โ€”โœ… Hot/cold persistence counters

Auto-fetched:

  • โ€”โœ… ERA5 meteorological data (solar radiation, wind, pressure, etc.)
  • โ€”โœ… Derived features (dewpoint, VPD, time encodings, interaction terms)

2. Upload and Calibrate

  1. 1.Click "Upload PurpleAir CSV file"
  2. 2.Select column mappings
  3. 3.Choose temperature unit
  4. 4.Click "Start Calibration"
  5. 5.Download calibrated results

๐Ÿ”ฌ Methodology

This tool implements the calibration framework from:

"Nationwide Calibration of PurpleAir Temperature Sensors for Heat Exposure Research" Zhang, Y., Rong, Y., & Liang, L. (2025)

Calibration Approach

  1. 1.Temperature Stratification: Three specialized XGBoost models for different thermal regimes
  2. 2.Temporal Features: 12-hour sensor thermal history and dynamics
  3. 3.Meteorological Integration: Automatic ERA5 data fetching (solar radiation, humidity, wind, etc.)
  4. 4.Feature Engineering: 63 features capturing sensor physics and environmental conditions

Why This Works

PurpleAir sensors suffer from solar heating bias due to inadequate radiation shielding. Our calibration:

  • โ€”Captures sensor thermal inertia (how sensors heat up and cool down)
  • โ€”Accounts for varying bias across temperature ranges
  • โ€”Uses meteorological data to predict and correct systematic errors

๐Ÿ“š Citation

If you use this tool in your research, please cite:

bibtex
@article{zhang2025purpleair,
  title={Nationwide Calibration of PurpleAir Temperature Sensors for Heat Exposure Research},
  author={Zhang, Yunqian and Rong, Yan and Liang, Lu},
  journal={[Journal Name]},
  year={2025},
  doi={10.5281/zenodo.18463819}
}

๐Ÿ”— Resources

๐Ÿ“– Documentation

Data Requirements

  • โ€”Time Range: 2022-01-01 to 2024-12-31 (ERA5 data availability)
  • โ€”Location: Continental United States (CONUS) recommended
  • โ€”Temporal Resolution: Hourly data works best
  • โ€”File Format: CSV with standard column names

Limitations

  • โ€”Requires internet connection to fetch ERA5 data
  • โ€”First-time calibration may take longer (ERA5 download)
  • โ€”Calibration accuracy depends on data quality and completeness

๐Ÿ› ๏ธ Technical Details

Models

  • โ€”Algorithm: XGBoost (Gradient Boosting)
  • โ€”Model Size: 44 MB (3 models)
  • โ€”Features: 63 engineered features
  • โ€”Training Data: 797,744 hourly observations from 98 sensors

Processing Steps

  1. 1.Validate input data
  2. 2.Fetch ERA5 meteorological data for location/time
  3. 3.Calculate 63 features (spatial + temporal)
  4. 4.Apply temperature-stratified model
  5. 5.Return calibrated temperature with uncertainty estimates

๐Ÿ‘ฅ Authors

  • โ€”Yunqian Zhang - UC Berkeley / Beijing Normal University
  • โ€”Yan Rong - University of Illinois Chicago
  • โ€”Lu Liang (Corresponding Author) - UC Berkeley

๐Ÿ“ง Contact

๐Ÿ“„ License

MIT License - See repository for details


Developed by: Yunqian Zhang & Lu Liang Institution: University of California, Berkeley Last Updated: February 2025