- This topic has 1 reply, 1 voice, and was last updated 2 weeks, 3 days ago by
David White.
-
AuthorPosts
-
August 17, 2026 at 7:44 pm #30457
David White
ParticipantI have a Flex located outdoors directly next to a uRad Smoggie. I believe both use the same pm2.5 sensor. And sometimes I even get the same particle count :slight_smile:
But the Smoggie does not compute/report the US EPA AQI – only the raw pm2.5 count. I want to compute the AQI so I can easily compare both results.
Here is the code I use to calculate the AQI (this follows suggested code elsewhere here and from Google search AI) –
// Standard US EPA PM2.5 Breakpoints (Concentration Low, Concentration High, AQI Low, AQI High) double[][] BREAKPOINTS = { {0.0, 9.0, 0, 50}, {9.1, 35.4, 51, 100}, {35.5, 55.4, 101, 150}, {55.5, 125.4, 151, 200}, {125.5, 225.4, 201, 300}, {225.5, 325.4, 301, 500}, {325.5, 504.4, 501, 600} // Extended range if needed }; int calculatePm25Aqi(double pm25Concentration) { // Truncate to 1 decimal place double cp = Math.floor(pm25Concentration * 10.0) / 10.0; if (cp < 0.0) return 0; if (cp > 504.4) return 500; // Cap at maximum AQI for (double[] bp : BREAKPOINTS) { double bpLo = bp[0]; double bpHi = bp[1]; double iLo = bp[2]; double iHi = bp[3]; if (cp >= bpLo && cp <= bpHi) { double aqi = ((iHi - iLo) / (bpHi - bpLo)) * (cp - bpLo) + iLo; return (int) Math.round(aqi); } } return 500; }All of this seems reasonable to me. But as you can see in the attachement, the result coming from this computation for my outside Smoggie does NOT quite match that shown for the Purple widget – even though the pm2.5 values are identical (5).
At first I tried replacing the call to Math.round() with Math.floor() and Math.ceil() as this seems the mostly likely possible difference in an otherwise pretty well understood computation. the results from Math.floor() is closer to that shown for the Purple widget but it is still higher.
Can anyone suggest why these values do not match? Thanks
Attachments:
August 24, 2026 at 5:19 pm #30462David White
ParticipantI think there is nothing wrong with my computation. What I believe is the difference between my Smoggie and the Purple Flex is that the Flex reports fractional values for pm2.5 whereas the Smoggie seems to give only integer values for this item.
Someone over on Reddit said: For US EPA AQI, 0-50 = 0-9ug/m3. So this is LIKELY a product of PA only showing the whole concentration value (I.e., 2.1 vs. 2.2 ug/m3).
So I decided to start running pm2.5 values between 1.5 and 2.5 thru the EPA formula I have (got elsewhere here). I found that at pm2.5 = 1.6 I get AQI = 9. At 2.0 I get 11, at 2.2 I get 12 and so on. So I guess the Reddit answer is correct – the display of the pm2.5 value is being rounded while the computation for AQI is using the raw value.
This then raises the question of why does the Smoggie not provide fractional data for pm2.5? Both sensors use the same mechanism, as I understand it. I know that the Smoggie data is somehow “corrected” and perhaps the data is rounded up/down or something and the fractional value is lost by the time the json I get has been produced?
I am trying hard to compare/contrast the Smoggie with the Purple Flex and this sort of thing makes that a bit more difficult. Is there some way to access the un-corrected data that might include the fractional portion?
Best
-
AuthorPosts
- You must be logged in to reply to this topic.
