-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
134 lines (99 loc) · 3.2 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# CNAQI
<!-- badges: start -->
<!-- badges: end -->
The goal of `CNAQI` is to calculate Air Quality Index according to regulations and standards of Ministry of Ecology and Environment of China.
根据中华人民共和国生态环境部《环境空气质量指数(AQI)技术规定(HJ633—2012)》中的相关标准和方法,提供五个用于计算AQI的函数
## Installation
You can install the development version of `CNAQI` like so:
``` r
devtools::install.package("evanliu3594/CNAQI")
```
## 1.Functions
### `DaliyMeanConc()`
`DaliyMeanConc()` calculates daily mean concentration of 6 pollutants. Note that average `O3` concentration for one day is presented by maximum 8-hour average concentration.
> Note: units of $SO_2$, $NO_2$, $PM_{10}$, $PM_{2.5}$ and $O_3$ input are $μg/m^3$
> unit of $CO$ is $mg/m^3$
```{r}
library(CNAQI)
C <- rnorm(24, 35, 5)
DaliyMeanConc("PM2.5", C)
```
### `IAQI_hourly()`
`IAQI_hourly()` is for calculate hourly IAQI for a given pollutant
```{r}
IAQI_hourly("O3", 142)
```
### `AQI_Hourly()`
`AQI_Hourly()` calculates the hourly AQI score and the featured pollutants based on 4 pollutants' concentration.
```{r}
AQI_Hourly(SO2 = 300,NO2 = 200,CO = 100,O3 = 120)
```
### `IAQI_Daily()`
`IAQI_Daily()` calculates daily IAQI for given pollutant
```{r}
IAQI_Daily("O3", 142)
```
### `AQI_Daily()`
`AQI_Daily()` calculate the daily AQI score and the featured pollutants based on 6 pollutants' concentration.
```{r}
AQI_Daily(SO2 = 55, NO2 = 23, CO = 12, O3 = 122, PM2.5 = 35, PM10 = 55)
```
## 2.A sample workflow with AQI series functions in `tidyr` syntax.
### generate sample data
```{r}
library(tidyverse)
set.seed(3594)
sampleConc <- data.frame(
Time = 0:23,
SO2 = rnorm(24, mean = 300, sd = 20),
NO2 = rnorm(24, mean = 800, sd = 100),
O3 = rnorm(24, mean = 50, sd = 15),
CO = rnorm(24, mean = 25, sd = 10),
PM2.5 = rnorm(24, mean = 200, sd = 50),
PM10 = rnorm(24, mean = 350, sd = 100)
)
sampleConc
```
### Calculate hourly IAQI
```{r}
sampleConc %>%
pivot_longer(-Time, names_to = 'Pollu', values_to = 'Conc') %>% rowwise() %>%
mutate(IAQI_h = IAQI_hourly(Pollu = Pollu, Conc = Conc)) %>% select(-Conc) %>%
pivot_wider(names_from = 'Pollu', values_from = 'IAQI_h')
```
### Calculate hourly AQI
```{r}
sampleConc %>% rowwise() %>% mutate(
AQI_h = AQI_Hourly(SO2 = SO2, NO2 = NO2,CO = CO,O3 = O3), .keep = 'none'
)
```
### Calculate daily concentration
```{r}
sampleConc_daily_mean <- sampleConc %>% select(-Time) %>%
imap_dbl(~DaliyMeanConc(Pollu = .y, Conc = .x))
sampleConc_daily_mean
```
### Calculate daily IAQI
```{r}
tibble(!!!sampleConc_daily_mean) %>%
pivot_longer(everything(), names_to = "Pollu", values_to = "Conc") %>%
rowwise() %>% mutate(IAQI = IAQI_Daily(Pollu = Pollu, Conc = Conc))
```
### Calculate daily AQI
```{r}
tibble(!!!sampleConc_daily_mean) %>%
mutate(AQI = AQI_Daily(SO2 = SO2, NO2 = NO2, CO = CO, PM10 = PM10, PM2.5 = PM2.5, O3 = O3),
.keep = "none")
```