China's air quality index (AQI) and its calculation method

1. Introduction

The establishment of ambient air quality standards can play a positive role in ambient air quality management, protecting human health, maintaining ecological and environmental security, and promoting the harmonious and sustainable development of man, society and nature. In the 1970s, the United States first established the ambient air index standard. Then, countries around the world also established their own air quality index release system based on their own air quality conditions, such as API (air pollution index) and AQI (air quality index) in China. It can be seen that the establishment time of air quality index standard is not very long.

At present, China's air quality standards come from the ambient air quality standard (GB3095-2012) and the technical regulations on ambient air quality index (AQI) (Trial) (HJ 633-2012) issued by the Ministry of environmental protection. From the previous 3 and 5 pollutants to the current 6 pollutant standards, they are:, as follows:

Table 1 development history of air quality index in China

2. AQI calculation method

As shown in Table 1, the air quality index is divided into 24h average index, 1h average index and 8h average index, so the calculation methods of different types of indexes are also different. In reality, our commonly used indexes are 24-hour and 1h. The real-time AQI data usually released by the meteorological platform is calculated according to the 1hAQI standard. The 24-hour AQI can better reflect the overall air quality of the day.

Let's first introduce the AQI calculation method, and then we will introduce the specific calculation method of 1hAQI and 24hAQI.

Figure 1 AQI calculation method and example

However, by observing Table 1, we can find that there are only 4 kinds of pollutants in 1hAQI, which are lacking. In fact, it is in 1h AQIThe calculation standard of is based on 24h, that is, it is directly used in 24hThe IAQI of these two pollutants in 1h is calculated according to the IAQI calculation standard.

3. AQI calculation code (Python)

Let's first show the AQI calculation code for 1h. In fact, the code for 24h is similar to that for 1h. We only need to replace Idata.

import pandas as pd
import numpy as np
import json
import copy

if __name__ == '__main__':
   """This is 1 h of AQI Calculation code, 24 h Only need to be replaced Idata that will do"""
    qua = [0, 50, 100, 150, 200, 300, 400, 500]
    data = pd.read_json("D:\py\Game data processing\data\data4.json")
    print(round(2.50))
    print(type(data))
    data1 = data.values
    print(type(data1))
    IAQI =list(np.zeros(len(data1[0][0]["PM2.5"])))
    print((data1[0][0]).keys())
    Data=np.array([data1[0][0]["PM2.5"],data1[0][0]["PM10"],data1[0][0]["SO2"],data1[0][0]["NO2"],data1[0][0]["CO"],data1[0][0]["O3"]]).reshape(len(data1[0][0]["PM2.5"]),6)
    Idata = [
        [0, 35, 75, 115, 150, 250, 350, 500],  # PM2. 5. 24-hour average
        [0, 50, 150, 250, 350, 420, 500, 600],  # (PM10) 24-hour average
        [0,150,500,650,800],#so2
        [0,100,200,700,1200,2340,3090,3840],#no2
        [0,5,10,35,60,90,120,150],#co
        [0,160,200,300,400,800,1000,1200]#o3
    ]
      # Idata = [
    #     [0, 35, 75, 115, 150, 250, 350, 500] , # PM2.5 
    #     [0, 50, 150, 250, 350, 420, 500, 600],  # (PM10)
    #     [0, 50,150,475,800,1600,2100,2620],  # (SO2) 
    #     [0,40,80,180,280,565,750,940],  # 
    #     [0, 2,4,14,24,36,48,60],  # (CO)
    #     [0, 100,160,215,265,800]  # (O3)
    # ]
    #The above is the Idata required in 24hAQI calculation
    T_IA=0
    i=j=k=0
    print(len(Idata))
    for i in range(len(Idata)):
        T_data=Data[:,i]
        T_Idata=Idata[i]
        for j in range(len(T_data)):
            for k in range(1,len(T_Idata)):
                if T_Idata[k]>T_data[j]:
                    break
            if k==(len(T_Idata)-1) and T_Idata[k]<T_data[j]:
                T_IA=T_Idata[k]
            else:
                T_IA=int(round((((qua[k]-qua[k-1])/(T_Idata[k]-T_Idata[k-1]))*(T_data[j]-T_Idata[k-1])+qua[k-1])+0.5))
            if T_IA>IAQI[j]:
                IAQI[j]=T_IA
    data1[0][0]["AQI"]=(IAQI)
    data2=copy.deepcopy(data1[0][0]['date'])
    data1[0][0].pop("date")
    data1[0][0]["date"]=data2
    filename="D:\py\Game data processing\data\IAdata4.json"
    Dic={}

    Dic["air_data"]=data1[0].tolist()
    with open(filename, 'w') as file_obj:
        json.dump(Dic,file_obj)

4. Follow up

How can we convert the AQI into the air quality level more intuitively

          

 

Keywords: Python

Added by matthewlesh on Tue, 01 Feb 2022 14:59:15 +0200