-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotClimate.Rmd
116 lines (98 loc) · 4.38 KB
/
plotClimate.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
---
title: "R Notebook"
output: html_notebook
---
```{r}
source('lib-dendro.R')
library(glue)
library(tidyverse)
library(ggplot2)
theme_set( theme_bw() +
theme(
plot.title = element_text(size = 20, hjust = 0.5, face = "bold"),
text=element_text(size=20, color = "gray9"),
legend.title=element_text(size=16, color = "gray9"),
legend.text=element_text(size=16, color = "gray9"),
axis.title=element_text(size=20),
axis.text=element_text(size=20, color = "gray9")
))
### DEFINE GLOBAL VARS ###
PATH = dirname(rstudioapi::getSourceEditorContext()$path)
print(PATH)
setwd(PATH)
PLACE = 'Penaflor'
ENV_DIR = glue('processed/{PLACE}-env-processed')
OUTPUT_PATH = 'output/request-Antonio-soil-sampling'
ts_start <- as.POSIXct("2022-04-01 09:00:00", tz = 'Europe/Madrid') # from april 1st 2022
ts_end <- as.POSIXct("2023-04-30 23:45:00", tz = 'Europe/Madrid') # to april 30th 2023
# Select TMS serial no for this analysis
SELECTED_TMS <- case_when( # select one TMS sensor for this site which has all its data valid
PLACE == 'Miedes' ~ c("94231935"),
PLACE == 'Corbalan' ~ c("94231943"),
PLACE == 'Penaflor' ~ c("94231934"), # 94231950 is delayed? and throws wrong results? double check
.default = NA
)
```
```{r}
db.env <- read.env.proc(file.path(".",ENV_DIR,'proc-env.csv'))
db.env <- db.env %>% filter(series %in% SELECTED_TMS)
```
```{r}
db.env <- db.env %>% filter(ts >= ts_start & ts <= ts_end)
summary(db.env)
```
```{r}
if (PLACE == 'Miedes' | PLACE == 'Penaflor') {
sampling.dates <- data.frame(xdate = c(as.POSIXct('2022-05-04 00:00:00', tz = 'Europe/Madrid'),
as.POSIXct('2022-08-19 00:00:00', tz = 'Europe/Madrid'),
as.POSIXct('2022-11-24 00:00:00', tz = 'Europe/Madrid'),
as.POSIXct('2023-02-16 00:00:00', tz = 'Europe/Madrid'))
) # sampling dates Miedes and Peñaflor
} else {
sampling.dates <- data.frame(xdate = c(as.POSIXct('2022-05-19 00:00:00', tz = 'Europe/Madrid'),
as.POSIXct('2022-08-22 00:00:00', tz = 'Europe/Madrid'),
as.POSIXct('2022-11-16 00:00:00', tz = 'Europe/Madrid'),
as.POSIXct('2023-02-20 00:00:00', tz = 'Europe/Madrid'))
) # sampling dates Corbalan
}
```
Soil temp:
```{r}
plot_temp_and_humidity <-
ggplot(data = db.env, aes(x=ts, y=soil.temp)) +
# ggtitle(glue("Soil temperature and humidity for {PLACE}")) +
geom_line(aes(colour = soil.temp)) +
scale_colour_gradient(low = "light blue", high = "red") +
scale_x_datetime(date_breaks = "1 month", date_labels="%b %Y", expand = expansion( mult = 0.01) ) +
theme(axis.text.x = element_text(angle = 30, hjust=1), legend.position = "bottom") +
scale_y_continuous("Temperature (ºC)\n", , breaks=seq(0,40,10), limits = c(0, 50),
sec.axis = dup_axis(name = "Volumetric Water Content (%)\n", breaks=seq(0,50,10))) +
geom_line(aes(x = ts, y = vwc * 100, linetype = "Volumetric\nWater Content (%)"), col="blue", show.legend = TRUE) +
scale_linetype_manual(NULL, values = 1) +
labs(x=expression(''), colour = "Soil Temperature (ºC)") +
geom_vline(data=sampling.dates, aes(xintercept=xdate), lty=2)
plot_temp_and_humidity
```
```{r}
ggsave(glue('{OUTPUT_PATH}/VWCytempAgg-{PLACE}-april2022-april2023-soiltemp.png'), width = 15, height = 10)
```
Surface temp:
```{r}
plot_temp_and_humidity <-
ggplot(data = db.env, aes(x=ts, y=surface.temp)) +
# ggtitle(glue("Surface temperature and humidity for {PLACE}")) +
geom_line(aes(colour = surface.temp)) +
scale_colour_gradient(low = "lightblue", high = "red") +
scale_x_datetime(date_breaks = "1 month", date_labels="%b %Y", expand = expansion( mult = 0.01) ) +
theme(axis.text.x = element_text(angle = 30, hjust=1), legend.position = "bottom") +
scale_y_continuous("Temperature (ºC)\n", breaks=seq(0,40,10), limits = c(0, 50),
sec.axis = dup_axis(name = "Volumetric Water Content (%)\n", breaks=seq(0,50,10))) +
geom_line(aes(x = ts, y = vwc * 100, linetype = "Volumetric\nWater Content (%)"), col="blue", show.legend = TRUE) +
scale_linetype_manual(NULL, values = 1) +
geom_vline(data=sampling.dates, aes(xintercept=xdate), lty=2) +
labs(x=expression(''), colour = "Surface Temperature (ºC)")
plot_temp_and_humidity
```
```{r}
ggsave(glue('{OUTPUT_PATH}/VWCytempAgg-{PLACE}-april2022-april2023-surfacetemp.png'), width = 15, height = 10)
```