Created
July 10, 2026 19:23
-
-
Save russbiggs/f231e80de162432b1c79bca95281a07c to your computer and use it in GitHub Desktop.
AirGradient calibration algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calibrate(pm: float, rh: float) -> float: | |
| if pm < 30: | |
| return max(0.0, (0.524 * pm) - (0.0862 * rh) + 5.75) | |
| if pm < 50: | |
| return max( | |
| 0.0, | |
| ( | |
| (0.786 * (pm / 20 - (3 / 2)) + 0.524 * (1 - (pm / 20 - (3 / 2)))) * pm | |
| - (0.0862 * rh) | |
| + 5.75 | |
| ), | |
| ) | |
| if pm < 210: | |
| return max(0.0, (0.786 * pm) - (0.0862 * rh) + 5.75) | |
| if pm < 260: | |
| return max( | |
| 0.0, | |
| ( | |
| (0.69 * (pm / 50 - 21 / 5) + 0.786 * (1 - (pm / 50 - (21 / 5)))) * pm | |
| - (0.0862 * rh * (1 - (pm / 50 - (21 / 5)))) | |
| + (2.966 * (pm / 50 - (21 / 5))) | |
| + (5.75 * (1 - (pm / 50 - (21 / 5)))) | |
| + (8.84 * (10**-4) * (pm**2) * (pm / 50 - (21 / 5))) | |
| ), | |
| ) | |
| else: | |
| return max(0.0, 2.966 + (0.69 * pm) + (8.84 * (10**-4) * (pm**2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment