Skip to content

Instantly share code, notes, and snippets.

@russbiggs
Created July 30, 2026 15:13
Show Gist options
  • Select an option

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

Select an option

Save russbiggs/66326191975f8e87d6eb14bf4de82c9a to your computer and use it in GitHub Desktop.
ag_calibrate.R
calibrate <- function(pm, rh) {
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.84e-4 * (pm^2) * (pm / 50 - (21 / 5)))
))
}
return(max(0.0, 2.966 + (0.69 * pm) + (8.84e-4 * (pm^2))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment