basicr_on_data.luftkval.oslo10.Rmd 4.05 KB
Newer Older
jml's avatar
jml committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
---
title: "basicr on data.luftkval.oslo10"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{luft}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
library(basicr)
knitr::opts_chunk$set(collapse = T, comment = "#>")
```

## Basic analysis on 'data.luftkval.oslo10' df.


18
### Get 'data.luftkval.oslo10' dataset.
jml's avatar
jml committed
19
20
21

```R

22
fromDate <- "2015/01/01 00:00:00"
jml's avatar
jml committed
23
24
25
26
27
28
29
toDate <- "2018/12/31 23:00:00"
timeResolution <- "hourly"
precision <- "hourly"

element_id <- c("NO2")

# station ids
30
station_id <- c("7","848","827","665","9","11","163","504","809")
jml's avatar
jml committed
31
32
33


# luft
34
luft <- glow::ts(service="d.luft.oslyr",
jml's avatar
jml committed
35
36
37
38
                 fromDate=fromDate,toDate=toDate,precision=timeResolution,timeResolution=timeResolution,
                 element_id=element_id,station_id=station_id)


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
# qa indicator
luft_qa <- glow::qa(service="d.luft.oslyr",
                 fromDate=fromDate,toDate=toDate,precision=timeResolution,timeResolution=timeResolution,
                 element_id=element_id,station_id=station_id)

study <- friendlyts::bind_cols_fts(luft,luft_qa,precision="hourly")
study <- stats::na.omit(study)

head(study)
```

## Focus on valid data
```r
# read qcflag nilu meta
path <- try(normalizePath(file.path(.libPaths()[1],"data.luftkval.oslo10","data","qcflag_meta.rda"),mustWork=TRUE))
tmp <- load(file=path)
qcflag_meta <- get(tmp)
known_ok   <- qcflag_meta %>% filter(FlagType=="OK") %>% select(ID)

all <- paste0(element_id,"_",station_id)
qa_all <- paste0("qa_",element_id,"_",station_id)

cond <- paste(qa_all, "%in%",  known_ok,collapse=" & ")

# valid data on train/test dataset
study <- study %>% filter(eval(parse(text=cond))) %>% select(c("WDAY","YEAR","MONTH","DAY","HOUR"),tidyselect::all_of(all),tidyselect::all_of(qa_all)) %>% friendlyts::as_tbl_friendlyts(precision=precision,date_type="friendlyts",CHECKNAS=FALSE)
study <- stats::na.omit(study)
jml's avatar
jml committed
66
67
68

```

69
70
71
72
### Missing values

```R

73
basicr::plot_coverage_ts(x=study,timeResolution=timeResolution,DESKTOP=TRUE)
74
75
76

```

77
### basics characteristics
jml's avatar
jml committed
78
79
80

```R

81
82
83
84
85
86
87
basicr::basic_info(df=study,target="NO2_7",group="none")
basicr::basic_info(df=study,target="NO2_7",group="YEAR")
basicr::basic_info(df=study,target="NO2_7",group="MONTH")
basicr::basic_info(df=study,target="NO2_7",group="WDAY")
basicr::basic_info(df=study,target="NO2_7",group="HOUR")
basicr::basic_info(df=study,target="NO2_7",group=c("YEAR","MONTH"))
basicr::basic_info(df=study,target="NO2_7",group=c("WDAY","HOUR"))
jml's avatar
jml committed
88

89
90
91
basicr::plot_tbl_basic(study,target="NO2_7",group="HOUR",y_name="[ug/m3]")
basicr::plot_tbl_basic(study,target="NO2_7",group="WDAY",y_name="[ug/m3]")
basicr::plot_tbl_basic(study,target="NO2_7",group="MONTH",y_name="[ug/m3]")
jml's avatar
jml committed
92

93
94
95
96
97
98
```

### Timeseries of basic characteristics and box-whisker timeseries plot with observation timeseries

```R

99
100
101
res <- basicr::basic_ts(df=study,target="NO2_7",group=c("WDAY","HOUR"),precision="hourly")
# plot_boxwhisk_ts() works only with ggplo2 <= version 3.1.1
# basicr::plot_boxwhisk_ts(x=res,fromDate="2004/01/05 00:00:00",toDate="2004/01/06 00:00:00",timeResolution="hourly",DESKTOP=TRUE)
102
103
104
105
106
107

```

### L-moment

```R
jml's avatar
jml committed
108

109
lmom_ <- basicr::samlmu2(df=tmp,target="NO2_7")
110
basicr::plot_lmrd(x=lmom_,DESKTOP=TRUE)
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# and
res <- basicr::basic_info(df=tmp,target="NO2_7",group=c("WDAY","HOUR"))
basicr::plot_lmrd(x=res,DESKTOP=TRUE)


res <- lapply(paste0(element_id,"_",station_id),function(x){basicr::basic_info(df=study,target=x)})
res <- do.call("rbind",res)
basicr::plot_lmrd(x=res,DESKTOP=FALSE,path="~")

#res <- lapply(paste0(element_id,"_","7"),function(x){basicr::basic_info(df=study,target=x,group=c("WDAY"))})
#res <- lapply(paste0(element_id,"_","7"),function(x){basicr::basic_info(df=study,target=x,group=c("HOUR"))})
res <- lapply(paste0(element_id,"_","7"),function(x){basicr::basic_info(df=study,target=x,group=c("WDAY","HOUR"))})
res <- do.call("rbind",res)
basicr::plot_lmrd(x=res,DESKTOP=FALSE,path="~")


res <- lapply(paste0(element_id,"_",station_id),function(x){basicr::basic_info(df=study,target=x,group=c("WDAY","HOUR"))})
res <- do.call("rbind",res)

write.csv(res,file="~/NO2_oslo10_param_wday_hour.csv")
jml's avatar
jml committed
131
132
133


```