【空气质量数据分析专题五】污染物浓度年际变化分析

前言

大气空气质量污染物一般为SO2、NO2 、CO、PM10、PM2.5、O3六项污染物。日级别浓度中,除O3使用最大8小时滑动平均浓度外,其他五项污染物均采用日平均浓度。
除CO浓度单位为mg/m3外,其他五项污染物浓度单位均为μg/m3,各污染物浓度对应的级别见《环境空气质量标准》(GB 3095—2012)。

分析流程

对数据进行专题二的预处理后,计算出各污染物各年的年均浓度,最后进行可视化分析。

核心代码

(1)计算各污染物各年年均浓度(需要注意的是,求某指标某时段的均值时,要用该指标该时段的综合除以总记录数,不能分段平均再平均,分段平均再平均只能适用于分段方式为等长度分段

@staticmethod
def each_year_concentration_cal(dft):
      """
      计算某年均浓度
      :param dft: 该年全年数据
      :return: 该年各污染物浓度年均值
      """
      return round(np.mean(dft['PM10']), 2), round(np.mean(dft['PM2.5']), 2), round(np.mean(dft['SO2']), 2), \
             round(np.mean(dft['NO2']), 2), round(np.mean(dft['CO']), 2), round(np.mean(dft['O3']), 2)

(2)可视化分析

def year_trend_analysis(self, df_station, year_list):
    """
    日级别数据年变化分析
    :param df_station: 站点数据
    :param year_list: 年份列表
    :return: None
    """
    all_year_pollutes = list()
    for year in year_list:
        df_station_year = df_station[df_station['year'] == year]
        if len(df_station_year.index) != 0:
            all_year_pollutes.append(list(self.each_year_concentration_cal(df_station_year)))
        else:
            all_year_pollutes.append([np.NAN] * 6)
    logger.info(df_station['station'].values[0] + '污染物浓度为: ' + str(all_year_pollutes))

    co_arr = list()
    for i in range(len(all_year_pollutes)):
        co_arr.append(all_year_pollutes[i].pop(4))

    bar_width = 0.1
    index_pm10 = np.arange(len(all_year_pollutes))
    index_pm2_5 = index_pm10 + 1.5 * bar_width
    index_so2 = index_pm2_5 + 1.5 * bar_width  # 年份INDEX
    index_no2 = index_so2 + 1.5 * bar_width
    index_o3 = index_no2 + 1.5 * bar_width

    x_ticks = [str(x) + "年" for x in year_list]

    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    plt.bar(index_pm10, height=[k[0] for k in all_year_pollutes], width=bar_width, label='PM$_{10}$')
    plt.bar(index_pm2_5, height=[k[1] for k in all_year_pollutes], width=bar_width, label='PM$_{2.5}$')
    plt.bar(index_so2, height=[k[2] for k in all_year_pollutes], width=bar_width, label='SO$_{2}$')
    plt.bar(index_no2, height=[k[3] for k in all_year_pollutes], width=bar_width, label='NO$_{2}$')
    plt.bar(index_o3, height=[k[4] for k in all_year_pollutes], width=bar_width, label='O$_{3}$')

    ax1.set_ylim(0, 100)
    ax1.set_yticks(np.linspace(0, 100, 6))
    plt.legend(ncol=1, loc='upper left', fontsize=8)  # 显示图例
    plt.ylabel('污染物浓度(${μg}$/m${^3}$)')  # 纵坐标轴标题

    ax2 = ax1.twinx()
    ax2.plot(index_pm10 + bar_width * 3, co_arr, label='CO浓度', color='black', marker='o', markerfacecolor='red',
             markersize=4)
    plt.ylabel('CO浓度(mg/m${^3}$)')
    plt.xticks(index_pm10 + bar_width * 3, x_ticks)
    plt.legend(loc='upper right', fontsize=8)
    ax2.set_yticks(np.linspace(0, 1.5, 6))
    plt.grid(axis='y', ls='--')
    pic_loc0 = Path(self.cf_info['output']['picture']).joinpath(df_station['city'].values[0])
    pic_loc = pic_loc0.joinpath('污染物年变化特征')
    if not os.path.exists(pic_loc):
        os.mkdir(pic_loc)
    plt.savefig(pic_loc / (
            df_station['station'].values[0] + str(year_list[0]) + '-' + str(year_list[-1]) + '年各污染物浓度变化.png'),
                dpi=1200, bbox_inches='tight')
    plt.show()

结果展示与分析

结果如下图所示,从该图可以看出各污染物年均浓度的变化趋势,有利于对该地区空气质量的变化情况有直观了解。

优良率
(图片右键新标签页打开会很清晰)

预告

下期进行污染物浓度季节变化的分析。

以下是本人独自运营的微信公众号,用于分享个人学习及工作生活趣事,大佬们可以关注一波。

优良率
  • 3
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

⁣北潇

老板大气!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值