def get_aqi(o3_8h: float = None, no2_1h: float = None, so2_24h: float = None, co_8h: float = None, pm25_24h: float = None, pm10_24h: float = None, with_level: bool = False) -> (int, {}): """ Calculates Singapore PSI (Maximum from individual indexes) :param o3_8h: O3 average (8h), ppm :param no2_1h: NO2 average (1h), ppm :param so2_24h: SO2 average (24h), ppm :param co_8h: CO average (8h), ppm :param pm25_24h: PM2.5 average (24h), μg/m3 :param pm10_24h: PM10 average (24h), μg/m3 :param with_level: Boolean distinguishing whether to print AQI level such as 'good' or 'hazardous' :return: Singapore PSI, dict with tuples (Individual PSI, General message, Risk message) keys are: o3_8h, no2_1h, so2_24h, co_8h, pm25_24h, pm10_24h -1 means AQI is not available """ aqi_data = {} if o3_8h: aqi_data['o3_8h'] = get_psi_o3_8h(o3_8h) if no2_1h and bool(__round_down(no2_1h, 3)): aqi_data['no2_1h'] = get_psi_no2_1h(no2_1h) if so2_24h: aqi_data['so2_24h'] = get_psi_so2_24h(so2_24h) if co_8h: aqi_data['co_8h'] = get_psi_co_8h(co_8h) if pm25_24h: aqi_data['pm25_24h'] = get_psi_pm25_24h(pm25_24h) if pm10_24h: aqi_data['pm10_24h'] = get_psi_pm10_24h(pm10_24h) if len(aqi_data) == 0: return AQI_NOT_AVAILABLE, aqi_data value = max(list(map(lambda x: x[0], aqi_data.values()))) if not with_level: return value, aqi_data return value, {'level': __get_aqi_level(value, SG_PSI, SG_PSI_LEVELS)}
def get_aqhi(o3_3h: float, no2_3h: float, so2_3h: float, pm25_3h: float, pm10_3h: float, with_level: bool = False) -> \ Union[Tuple[int, str, str], Tuple[int, dict]]: """ Calculates Hong Kong AQHI :param o3_3h: O3 average (3h), ppm :param no2_3h: NO2 average (3h), ppm :param so2_3h: SO2 average (3h), ppm :param pm25_3h: PM2.5 average (3h), μg/m3 :param pm10_3h: PM10 average (3h), μg/m3 :param with_level: Boolean distinguishing whether to print AQI level such as 'good' or 'hazardous' :return: Hong Kong AQHI, Effect message, Caution message """ if any(value is None for value in (o3_3h, no2_3h, so2_3h, pm10_3h, pm25_3h)): return AQI_NOT_AVAILABLE, "", "" betas = [ 0.0004462559, 0.0001393235, 0.0005116328, 0.0002821751, 0.0002180567 ] if so2_3h == 0: so2_3h = 0.020 # normal level - to make formula work without SO2 c = [ no2_3h * 1000 * NO2_PPB_UGM3, so2_3h * 1000 * SO2_PPB_UGM3, o3_3h * 1000 * O3_PPB_UGM3, pm10_3h, pm25_3h ] ars = list(map(__added_risk, betas, c)) ar_total = sum(ars[0:3]) + max(ars[3:5]) aqhi = len(HK_AR) for i in range(len(HK_AR)): if HK_AR[i][0] <= ar_total <= HK_AR[i][1]: aqhi = i + 1 text1, text2 = __get_aqi_texts(aqhi, HK_AR, HK_AQHI_GENERAL, HK_AQHI_RISK) if not with_level: return aqhi, text1, text2 return aqhi, {'level': __get_aqi_level(aqhi, HK_AQHI, HK_AQHI_LEVELS)}
def get_aqhi( o3_3h: float, no2_3h: float, pm25_3h: float, pm10_3h: float, with_level: bool = False ) -> Union[Tuple[float, str, str], Tuple[float, dict]]: """ Calculates Canada AQHI :param o3_3h: O3 average (3h), ppm :param no2_3h: NO2 average (3h), ppm :param pm25_3h: PM2.5 average (3h), μg/m3 :param pm10_3h: PM10 average (3h), μg/m3 :param with_level: Boolean distinguishing whether to print AQI level such as 'good' or 'hazardous' :return: CA AQHI, General message, Risk message """ if any(value is None for value in (o3_3h, no2_3h, pm10_3h, pm25_3h)): return AQI_NOT_AVAILABLE, "", "" betas = [0.000537, 0.000871, 0.000487, 0.000297] c = [o3_3h * 1000, no2_3h * 1000, pm25_3h, pm10_3h] ars = list(map(__added_risk, betas, c)) ar_pm25 = sum(ars[0:2]) + ars[2] pm25 = max(1, min(CA_AQHI[-1][1], round(ar_pm25))) ar_pm10 = sum(ars[0:2]) + ars[3] pm10 = max(1, min(CA_AQHI[-1][1], round(ar_pm10))) aqhi = max(pm25, pm10) text1, text2 = __get_aqi_texts(aqhi, CA_AQHI, CA_AQHI_GENERAL, CA_AQHI_RISK) if not with_level: return aqhi, text1, text2 return aqhi, {'level': __get_aqi_level(aqhi, CA_AQHI, CA_AQHI_LEVELS)}
def get_caqi(co_1h: float = None, o3_max_1h: float = None, no2_max_1h: float = None, pm25_24h: float = None, pm25_1h: float = None, pm10_1h: float = None, pm10_24h: float = None, so2_max_1h: float = None, with_level: bool = False) -> (int, {}): """ Calculates CAQI Europe (Maximum from individual indexes) :param co_1h: CO average (1h), ppm :param o3_max_1h: O3 maximum (max in 1h), ppm :param no2_max_1h: NO2 maximum (max in 1h), ppm :param pm25_1h: PM2.5 average (1h), μg/m3 :param pm25_24h: PM2.5 average (24h), μg/m3 :param pm10_1h: PM10 average (1h), μg/m3 :param pm10_24h: PM10 average (24h), μg/m3 :param so2_max_1h: SO2 maximum (max in 1h), ppm :param with_level: Boolean distinguishing whether to print AQI level such as 'good' or 'hazardous' :return: CAQI Europe, dict with aqi values keys are: no2_1h, so2_1h, o3_1h, co_1h, pm25_1h, pm25_24h, pm10_1h, pm10_24h -1 means AQI is not available """ aqi_data = {} if no2_max_1h: aqi_data['no2_1h'] = get_caqi_no2_1h(no2_max_1h) if so2_max_1h: aqi_data['so2_1h'] = get_caqi_so2_1h(so2_max_1h) if o3_max_1h: aqi_data['o3_1h'] = get_caqi_o3_1h(o3_max_1h) if co_1h: aqi_data['co_1h'] = get_caqi_co_1h(co_1h) if pm25_1h: aqi_data['pm25_1h'] = get_caqi_pm25_1h(pm25_1h) if pm25_24h: aqi_data['pm25_24h'] = get_caqi_pm25_24h(pm25_24h) if pm10_1h: aqi_data['pm10_1h'] = get_caqi_pm10_1h(pm10_1h) if pm10_24h: aqi_data['pm10_24h'] = get_caqi_pm10_24h(pm10_24h) if len(aqi_data) == 0: return AQI_NOT_AVAILABLE, aqi_data value = max(list(map(lambda x: x, aqi_data.values()))) if not with_level: return value, aqi_data return value, {'level': __get_aqi_level(value, EU_CAQI, EU_CAQI_LEVELS)}
def get_aqi(o3_8h: float = None, co_8h: float = None, pm25_24h: float = None, pm10_24h: float = None, so2_24h: float = None, no2_24h: float = None, nh3_24h: float = None, pb_24h: float = None, with_level: bool = False) -> (int, {}): """ Calculates India AQI (Maximum from individual indexes) :param o3_8h: O3 average (8h), ppm :param co_8h: CO average (8h), ppm :param pm25_24h: PM2.5 average (24h), μg/m3 :param pm10_24h: PM10 average (24h), μg/m3 :param so2_24h: SO2 average (24h), ppm :param no2_24h: NO2 average (24h), ppm :param nh3_24h: HN3 average (24h), ppm :param pb_24h: Pb average (24h), ppm :param with_level: Boolean distinguishing whether to print AQI level such as 'good' or 'hazardous' :return: India AQI, dict with tuples (Individual aqi, Effect message, Caution message) keys are: o3_8h, co_8h, pm25_24h, pm10_24h, so2_24h, no2_24h, nh3_24h, pb_24h -1 means AQI is not available """ aqi_data = {} if o3_8h: aqi_data['o3_8h'] = get_aqi_o3_8h(o3_8h) if co_8h: aqi_data['co_8h'] = get_aqi_co_8h(co_8h) if pm25_24h: aqi_data['pm25_24h'] = get_aqi_pm25_24h(pm25_24h) if pm10_24h: aqi_data['pm10_24h'] = get_aqi_pm10_24h(pm10_24h) if so2_24h: aqi_data['so2_24h'] = get_aqi_so2_24h(so2_24h) if no2_24h: aqi_data['no2_24h'] = get_aqi_no2_24h(no2_24h) if nh3_24h: aqi_data['nh3_24h'] = get_aqi_nh3_24h(nh3_24h) if pb_24h: aqi_data['pb_24h'] = get_aqi_pb_24h(pb_24h) if len(aqi_data) == 0: return AQI_NOT_AVAILABLE, aqi_data value = max(list(map(lambda x: x[0], aqi_data.values()))) if not with_level: return value, aqi_data return value, {'level': __get_aqi_level(value, IN_AQI, IN_AQI_LEVELS)}