Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError when PM concentration is higher than the defined maximum #27

Open
stefanthoss opened this issue Nov 29, 2021 · 1 comment
Open

Comments

@stefanthoss
Copy link

I'm using version 0.6.1 of this library with the default EPA algorithm. When I provide a PM concentration that is higher than the upper limit defined by the maximum AQI range (i.e. it would result in an AQI above 500), the library fails with an IndexError.

The error gets thrown by the line

(aqilo, aqihi) = self.piecewise['aqi'][idx]
since the idx variable is larger than the AQI boundary array allows.

Complete error message:

  File "/home/pi/.local/lib/python3.7/site-packages/aqi/__init__.py", line 45, in to_aqi                                                                               
    return _aqi.aqi(ccs)
  File "/home/pi/.local/lib/python3.7/site-packages/aqi/algos/base.py", line 36, in aqi                                                                                
    _iaqi = self.iaqi(elem, cc)
  File "/home/pi/.local/lib/python3.7/site-packages/aqi/algos/base.py", line 91, in iaqi                                                                               
    (aqilo, aqihi) = self.piecewise['aqi'][idx]
IndexError: list index out of range
@pjrobertson
Copy link

An easier solution that I went with is:

AQI_MAX = 500
def my_function(self):
        try:
            return aqi.to_aqi(
                [(aqi.POLLUTANT_PM25, self.pm25),
                (aqi.POLLUTANT_PM10, self.pm10)]
                )
        except IndexError:
            # in some cases, the PM2.5/PM10 values can be 99999, which goes beyond the index.
            return AQI_MAX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants