diff --git a/README.rst b/README.rst index ca14835..16f6993 100644 --- a/README.rst +++ b/README.rst @@ -7,6 +7,7 @@ A library to convert between AQI value and pollutant concentration * United States Environmental Protection Agency (EPA) * China Ministry of Environmental Protection (MEP) +* European Common Air Quality Index (CAQI) .. image:: https://travis-ci.org/hrbonz/python-aqi.svg?branch=master :target: https://travis-ci.org/hrbonz/python-aqi @@ -128,6 +129,7 @@ Resources * GB3095—2012 (2012/02/29) found at http://www.mep.gov.cn/gkml/hbb/bwj/201203/t20120302_224147.htm * HJ633-2012 (2012/02/29) found at http://www.zzemc.cn/em_aw/Content/HJ633-2012.pdf +* CAQI: CAQI Air quality index https://www.airqualitynow.eu/download/CITEAIR-Comparing_Urban_Air_Quality_across_Borders.pdf License ======= diff --git a/aqi/__init__.py b/aqi/__init__.py index 3d2dde7..d592af2 100644 --- a/aqi/__init__.py +++ b/aqi/__init__.py @@ -5,7 +5,8 @@ from aqi.constants import (POLLUTANT_PM25, POLLUTANT_PM10, POLLUTANT_O3_8H, POLLUTANT_O3_1H, POLLUTANT_CO_8H, POLLUTANT_SO2_1H, - POLLUTANT_NO2_1H, ALGO_EPA, ALGO_MEP) + POLLUTANT_NO2_1H, ALGO_EPA, ALGO_MEP, + ALGO_CAQI) from aqi.algos import get_algo, list_algos diff --git a/aqi/algos/caqi.py b/aqi/algos/caqi.py new file mode 100644 index 0000000..266afa3 --- /dev/null +++ b/aqi/algos/caqi.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- + +from decimal import * + +from aqi.constants import (POLLUTANT_PM25, POLLUTANT_PM10, + POLLUTANT_O3_1H, POLLUTANT_CO_8H, POLLUTANT_SO2_1H, + POLLUTANT_NO2_1H) +from aqi.algos.base import PiecewiseAQI + + +class AQI(PiecewiseAQI): + """Implementation of the CAQI algorithm. + """ + + piecewise = { + 'aqi': [ + (Decimal(0), Decimal(24.99)), + (Decimal(25), Decimal(49.99)), + (Decimal(50), Decimal(74.99)), + (Decimal(75), Decimal(99.99)), + (Decimal(100), Decimal(1000))], + 'bp': { + POLLUTANT_NO2_1H: [ + (Decimal('0'), Decimal('49.99')), + (Decimal('50'), Decimal('99.99')), + (Decimal('100'), Decimal('199.99')), + (Decimal('200'), Decimal('399.99')), + (Decimal('400'), Decimal('inf')), + ], + POLLUTANT_O3_1H: [ + (Decimal('0.0'), Decimal('60.000')), + (Decimal('60.001'), Decimal('120.000')), + (Decimal('120.001'), Decimal('180.000')), + (Decimal('180.001'), Decimal('240.000')), + (Decimal('240.001'), Decimal('inf')), + ], + POLLUTANT_PM10: [ + (Decimal('0'), Decimal('25')), + (Decimal('25.01'), Decimal('50')), + (Decimal('50.01'), Decimal('90')), + (Decimal('90.01'), Decimal('180')), + (Decimal('180.01'), Decimal('inf')), + ], + POLLUTANT_PM25: [ + (Decimal('0.0'), Decimal('15.0')), + (Decimal('15.01'), Decimal('30.0')), + (Decimal('30.01'), Decimal('55.0')), + (Decimal('55.01'), Decimal('110.0')), + (Decimal('110.01'), Decimal('inf')), + ], + POLLUTANT_CO_8H: [ + (Decimal('0.0'), Decimal('5000.0')), + (Decimal('5000.01'), Decimal('7500.0')), + (Decimal('7500.01'), Decimal('10000.0')), + (Decimal('10000.01'), Decimal('20000.0')), + (Decimal('20000.01'), Decimal('inf')), + ], + POLLUTANT_SO2_1H: [ + (Decimal('0'), Decimal('50')), + (Decimal('50.01'), Decimal('100')), + (Decimal('100.01'), Decimal('350')), + (Decimal('350.01'), Decimal('500')), + (Decimal('500.01'), Decimal('inf')), + ], + }, + 'prec': { + POLLUTANT_O3_1H: Decimal('.001'), + POLLUTANT_PM10: Decimal('.1'), + POLLUTANT_PM25: Decimal('.1'), + POLLUTANT_CO_8H: Decimal('.1'), + POLLUTANT_SO2_1H: Decimal('1.'), + POLLUTANT_NO2_1H: Decimal('1.'), + }, + 'units': { + POLLUTANT_O3_1H: 'µg/m³', + POLLUTANT_PM10: 'µg/m³', + POLLUTANT_PM25: 'µg/m³', + POLLUTANT_CO_8H: 'µg/m³', + POLLUTANT_SO2_1H: 'µg/m³', + POLLUTANT_NO2_1H: 'µg/m³', + }, + } diff --git a/aqi/constants.py b/aqi/constants.py index 5ec0e99..b80ac05 100644 --- a/aqi/constants.py +++ b/aqi/constants.py @@ -16,3 +16,4 @@ # constants for algorithms, canonical module name ALGO_EPA = 'aqi.algos.epa' ALGO_MEP = 'aqi.algos.mep' +ALGO_CAQI = 'aqi.algos.caqi'