From f7853419fa2874a66b7b9c7ca785039fb4a93532 Mon Sep 17 00:00:00 2001 From: karulis Date: Wed, 9 Jan 2019 20:57:51 +0100 Subject: [PATCH 1/4] Added EU's CAQI algorithm --- aqi/__init__.py | 3 +- aqi/algos/caqi.py | 82 +++++++++++++++++++++++++++++++++++++++++++++++ aqi/constants.py | 1 + 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 aqi/algos/caqi.py 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..2144f2f --- /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 EPA AQI algorithm. + """ + + piecewise = { + 'aqi': [ + (0, 25), + (26, 50), + (51, 75), + (76, 100), + (101, 1000)], + 'bp': { + POLLUTANT_NO2_1H: [ + (Decimal('0'), Decimal('50')), + (Decimal('51'), Decimal('100')), + (Decimal('101'), Decimal('200')), + (Decimal('201'), Decimal('400')), + (Decimal('401'), 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('26'), Decimal('50')), + (Decimal('51'), Decimal('90')), + (Decimal('91'), Decimal('180')), + (Decimal('181'), Decimal('inf')), + ], + POLLUTANT_PM25: [ + (Decimal('0.0'), Decimal('15.0')), + (Decimal('15.1'), Decimal('30.0')), + (Decimal('30.1'), Decimal('55.0')), + (Decimal('55.1'), Decimal('110.0')), + (Decimal('110.1'), Decimal('inf')), + ], + POLLUTANT_CO_8H: [ + (Decimal('0.0'), Decimal('5000.0')), + (Decimal('5000.1'), Decimal('7500.0')), + (Decimal('7500.1'), Decimal('10000.0')), + (Decimal('10000.1'), Decimal('20000.0')), + (Decimal('20000.1'), Decimal('inf')), + ], + POLLUTANT_SO2_1H: [ + (Decimal('0'), Decimal('50')), + (Decimal('51'), Decimal('100')), + (Decimal('101'), Decimal('350')), + (Decimal('351'), Decimal('500')), + (Decimal('501'), 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' From 052a69079527c6444340ecf9ec5f59d804629932 Mon Sep 17 00:00:00 2001 From: karulis Date: Fri, 11 Jan 2019 20:02:49 +0100 Subject: [PATCH 2/4] Comment update --- aqi/algos/caqi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aqi/algos/caqi.py b/aqi/algos/caqi.py index 2144f2f..755f839 100644 --- a/aqi/algos/caqi.py +++ b/aqi/algos/caqi.py @@ -9,7 +9,7 @@ class AQI(PiecewiseAQI): - """Implementation of the EPA AQI algorithm. + """Implementation of the CAQI algorithm. """ piecewise = { From 0838419c7fa7372802456f8041c25cc10adb77c0 Mon Sep 17 00:00:00 2001 From: karulis Date: Fri, 11 Jan 2019 20:26:26 +0100 Subject: [PATCH 3/4] Readme file update --- README.rst | 2 ++ 1 file changed, 2 insertions(+) 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 ======= From b44b362b7c15b60cb6bb24489765298358e86c4b Mon Sep 17 00:00:00 2001 From: karulis Date: Tue, 7 Jan 2020 21:21:08 +0100 Subject: [PATCH 4/4] Intervals changed --- aqi/algos/caqi.py | 52 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/aqi/algos/caqi.py b/aqi/algos/caqi.py index 755f839..266afa3 100644 --- a/aqi/algos/caqi.py +++ b/aqi/algos/caqi.py @@ -14,18 +14,18 @@ class AQI(PiecewiseAQI): piecewise = { 'aqi': [ - (0, 25), - (26, 50), - (51, 75), - (76, 100), - (101, 1000)], + (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('50')), - (Decimal('51'), Decimal('100')), - (Decimal('101'), Decimal('200')), - (Decimal('201'), Decimal('400')), - (Decimal('401'), Decimal('inf')), + (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')), @@ -36,31 +36,31 @@ class AQI(PiecewiseAQI): ], POLLUTANT_PM10: [ (Decimal('0'), Decimal('25')), - (Decimal('26'), Decimal('50')), - (Decimal('51'), Decimal('90')), - (Decimal('91'), Decimal('180')), - (Decimal('181'), Decimal('inf')), + (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.1'), Decimal('30.0')), - (Decimal('30.1'), Decimal('55.0')), - (Decimal('55.1'), Decimal('110.0')), - (Decimal('110.1'), Decimal('inf')), + (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.1'), Decimal('7500.0')), - (Decimal('7500.1'), Decimal('10000.0')), - (Decimal('10000.1'), Decimal('20000.0')), - (Decimal('20000.1'), Decimal('inf')), + (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('51'), Decimal('100')), - (Decimal('101'), Decimal('350')), - (Decimal('351'), Decimal('500')), - (Decimal('501'), Decimal('inf')), + (Decimal('50.01'), Decimal('100')), + (Decimal('100.01'), Decimal('350')), + (Decimal('350.01'), Decimal('500')), + (Decimal('500.01'), Decimal('inf')), ], }, 'prec': {