Skip to content

Instantly share code, notes, and snippets.

@russbiggs
Created July 10, 2026 19:23
Show Gist options
  • Select an option

  • Save russbiggs/f231e80de162432b1c79bca95281a07c to your computer and use it in GitHub Desktop.

Select an option

Save russbiggs/f231e80de162432b1c79bca95281a07c to your computer and use it in GitHub Desktop.
AirGradient calibration algorithm
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