yunqianz/purpleair-temperature-calibration
๐ก๏ธ 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
๐ 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 leveltree_canopy_cover- Tree cover percentagelifeorage- Days since deployment
Example:
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):
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 โ TargetAuto-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
- Click "Upload PurpleAir CSV file"
- Select column mappings
- Choose temperature unit
- Click "Start Calibration"
- 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
- Temperature Stratification: Three specialized XGBoost models for different thermal regimes
- Temporal Features: 12-hour sensor thermal history and dynamics
- Meteorological Integration: Automatic ERA5 data fetching (solar radiation, humidity, wind, etc.)
- 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:
@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
- Code Repository: GitHub
- Archived Code: Zenodo DOI: 10.5281/zenodo.18463819
- ERA5 Data Archive: Zenodo DOI: 10.5281/zenodo.18485026
- Paper: DOI: 10.5281/zenodo.18463819
๐ 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
- Validate input data
- Fetch ERA5 meteorological data for location/time
- Calculate 63 features (spatial + temporal)
- Apply temperature-stratified model
- 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
- Email: lianglu@berkeley.edu
- Issues: GitHub Issues
๐ License
MIT License - See repository for details
Developed by: Yunqian Zhang & Lu Liang Institution: University of California, Berkeley Last Updated: February 2025
