jonathankoren / weewx-aqi

Air Quality Calculations for WeeWx
GNU General Public License v3.0
9 stars 4 forks source link

Force linear_interpolate to do floating division #1

Closed jpbion closed 5 years ago

jpbion commented 5 years ago

Under Python 2, which weewx 3 uses, linear_interpolate works properly in the PM2.5 case for US AQI calculations because the breakpoint table happens to use floating point values for high and low observations. In python 2, (int/float) returns a float. Some of the other pollutants, such as PM10, have integer values in that table for the high and low observations and AQI. In Python2 int/int = int, so 7 / 2 = 3 (again, in Python 2). This is noticed when the pollutant level for PM10 is "1", the calculated AQI becomes (50 / 54), resulting in 0, which rounds to 0 of course. The correct result should be (50 / 54) = 0.926, rounded becomes 1. This result can be verified by going to the website https://airnow.gov/index.cfm?action=airnow.calculator - and then choosing the "Concentration to AQI" tab, and PM10 pollutant, concentration "1" - will return "1" and not "0", as the pre-modified weewx-aqi will erroneously produce. This patch is done because fixing it here, in the calculation, is more robust than remembering to make all the "add_breakpoint" calls specify floating point values for observation low/high for all its entries.

jonathankoren commented 5 years ago

Awesome. Thanks.