基于Python的小时污染物IAQI、AQI计算
一、IAQI计算公式1
二、Python代码2
函数代码:
def calculate_aqi(concentration, c_low, c_high, i_low, i_high):
"""
根据浓度计算每种污染物的子指数
:param concentration: 污染物浓度
:param c_low: 浓度范围下限
:param c_high: 浓度范围上限
:param i_low: AQI范围下限
:param i_high: AQI范围上限
:return: 子指数
"""
return ((i_high - i_low) / (c_high - c_low)) * (concentration - c_low) + i_low
def get_aqi(pollutants):
"""
根据小时污染物浓度计算 AQI
:param pollutants: 包含污染物及其浓度的字典
:return: AQI值
"""
# AQI的浓度范围及子指数范围: (c_low, c_high, i_low, i_high)
breakpoints = {
'PM2.5': [(0, 35, 0, 50), (35, 75, 50, 100), (75, 115, 100, 150), (115, 150, 150, 200), (150, 250, 200, 300), (250, 350, 300, 400), (350, 500, 400, 500)],
'PM10': [(0, 50, 0, 50), (50, 150, 50, 100), (150, 250, 100, 150), (250, 350, 150, 200), (350, 420, 200, 300), (420, 500, 300, 400), (500, 600, 400, 500)],
'O3': [(0, 160, 0, 50), (160, 200, 50, 100), (200, 300, 100, 150), (300, 400, 150, 200), (400, 800, 200, 300), (800, 1000, 300, 400), (1000, 1200, 400, 500)],
'CO': [(0, 5, 0, 50), (5, 10, 50, 100), (10, 35, 100, 150), (35, 60, 150, 200), (60, 90, 200, 300), (90, 120, 300, 400), (120, 150, 400, 500)],
'NO2': [(0, 100, 0, 50), (100, 200, 50, 100), (200, 700, 100, 150), (700, 1200, 150, 200), (1200, 2340, 200, 300), (2340, 3090, 300, 400), (3090, 3840, 400, 500)],
'SO2': [(0, 150, 0, 50), (150, 500, 50, 100), (500, 650, 100, 150), (650, 800, 150, 200)],
}
aqi_values = []
pollutant_values = []
for pollutant, concentration in pollutants.items():
# 获取对应污染物的浓度范围和 AQI 范围
if pollutant in breakpoints:
for c_low, c_high, i_low, i_high in breakpoints[pollutant]:
if c_low <= concentration <= c_high:
aqi_values.append(calculate_aqi(concentration, c_low, c_high, i_low, i_high))
break
pollutant_values.append(pollutant)
# 返回最大的 AQI 作为最终 AQI
print(pollutant_values)
print(aqi_values)
return max(aqi_values)
# 示例数据
pollutants = {
'PM2.5': 35,
'PM10': 70,
'O3': 100,
'CO': 1.0,
'NO2': 45,
'SO2': 50
}
aqi = get_aqi(pollutants)
print("The AQI is:", aqi)
结果:
['PM2.5', 'PM10', 'O3', 'CO', 'NO2', 'SO2']
[50.0, 60.0, 31.25, 10.0, 22.5, 16.666666666666664]
The AQI is: 60.0