-
Notifications
You must be signed in to change notification settings - Fork 0
/
Finnmaid+GETM.Rmd
329 lines (237 loc) · 8.37 KB
/
Finnmaid+GETM.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
---
title: "Finnmaid and GETM"
author: "Jens Daniel Müller und Lara Sophie Burchardt"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
workflowr::wflow_html:
number_sections: true
toc_depth: 3
toc_float:
collapsed: false
editor_options:
chunk_output_type: console
---
```{r global_options, include = FALSE}
knitr::opts_chunk$set(warning=FALSE, message=FALSE)
```
```{r packages}
library(tidyverse)
library(ncdf4)
library(vroom)
library(lubridate)
library(here)
library(seacarb)
library(oce)
library(patchwork)
```
```{r subsetting_criteria}
# route
select_route <- "E"
# latitude limits
low_lat <- 57.3
high_lat <- 57.5
#depth range to subset GETM 3d files
d1_shallow <- 0
d1_deep <- 80
# date limits
start_date <- "2018-07-01"
end_date <- "2018-08-22"
```
# GETM Data preparation
## Salinity and temperature profiles
Mean salinity and temperature profiles within the BloomSail area were extracted from daily GETM transects beneath the Finnmaid track.
```{r read_getm_3d_sal_tem, eval=FALSE}
nc <- nc_open(here::here("data/GETM", "Finnmaid.E.3d.2018.nc"))
lat <- ncvar_get(nc, "latc")
time_units <- nc$dim$time$units %>% #we read the time unit from the netcdf file to calibrate the time
substr(start = 15, stop = 33) %>% #calculation, we take the relevant information from the string
ymd_hms() # and transform it to the right format
t <- time_units + ncvar_get(nc, "time") # read time vector
rm(time_units)
d <- ncvar_get(nc, "zax") # read depths vector
for (var_3d in c("salt", "temp")) {
array <- ncvar_get(nc, var_3d) # store the data in a 3-dimensional array
#dim(array) # should be 3d with dimensions: 544 coordinates, 51 depths, and number of days of month
fillvalue <- ncatt_get(nc, var_3d, "_FillValue")
# Working with the data
array[array == fillvalue$value] <- NA
for (i in seq(1,length(t),1)){
# i <- 3
array_slice <- array[, , i] # slices data from one day
array_slice_df <- as.data.frame(t(array_slice))
array_slice_df <- as_tibble(array_slice_df)
gt_3d_part <- array_slice_df %>%
set_names(as.character(lat)) %>%
mutate(dep = -d) %>%
gather("lat", "value", 1:length(lat)) %>%
mutate(lat = as.numeric(lat)) %>%
filter(lat > low_lat, lat < high_lat,
dep >= d1_shallow, dep <= d1_deep) %>%
#summarise_all("mean") %>%
mutate(var = var_3d,
date_time=t[i]) %>%
dplyr::select(date_time, dep, value, var) #%>%
#filter(date_time >= start_date, date_time <= end_date)
if (exists("gt_3d")) {
gt_3d <- bind_rows(gt_3d, gt_3d_part)
} else {gt_3d <- gt_3d_part}
rm(array_slice, array_slice_df, gt_3d_part)
}
rm(array, fillvalue)
}
nc_close(nc)
rm(nc)
gt_3d_jun_aug <- gt_3d %>%
filter(date_time >= start_date & date_time <= end_date) %>%
group_by(dep,var,date_time ) %>%
summarise_all(list(value=~mean(.,na.rm=TRUE))) %>%
ungroup()
gt_3d_jun_aug %>%
vroom_write((here::here("data/_summarized_data_files", file = "gt_3d_jun_aug_2018.csv")))
rm(gt_3d, gt_3d_jun_aug, d1_deep, d1_shallow, i, lat, d, t, var_3d)
```
## Mixed layer depth
Regional mean mixed layer depth estimates based on sewater density and windspeed within the BloomSail area were extracted from 3h GETM surface data along the Finnmaid track.
```{r read_getm_2d_mld_wind, eval=FALSE}
nc_2d <- nc_open(here("data/GETM", "Finnmaid.E.2d.2018.nc"))
#print(nc_2d)
lat <- ncvar_get(nc_2d, "latc")
time_units <- nc_2d$dim$time$units %>% #we read the time unit from the netcdf file to calibrate the time
substr(start = 15, stop = 33) %>% #calculation, we take the relevant information from the string
ymd_hms() # and transform it to the right format
t <- time_units + ncvar_get(nc_2d, "time") # read time vector
rm(time_units)
for (var in c("mld_rho", "u10", "v10")) {
#var <- "mld_rho"
array <- ncvar_get(nc_2d, var) # store the data in a 3-dimensional array
fillvalue <- ncatt_get(nc_2d, var, "_FillValue")
array[array == fillvalue$value] <- NA
array <- as.data.frame(t(array), xy=TRUE)
array <- as_tibble(array)
gt_2d_part <- array %>%
set_names(as.character(lat)) %>%
mutate(date_time = t) %>%
filter(date_time >= start_date & date_time <= end_date) %>%
gather("lat", "value", 1:length(lat)) %>%
mutate(lat = as.numeric(lat)) %>%
filter(lat > low_lat, lat<high_lat) %>%
select(-lat) %>%
group_by(date_time) %>%
summarise_all(list(value=~mean(.,na.rm=TRUE))) %>%
ungroup() %>%
mutate(var = var)
if (exists("gt_2d")) {
gt_2d <- bind_rows(gt_2d, gt_2d_part)
} else {gt_2d <- gt_2d_part}
rm(array, fillvalue, gt_2d_part)
}
nc_close(nc_2d)
rm(nc_2d)
gt_2d <- gt_2d %>%
pivot_wider(values_from = value, names_from = var) %>%
mutate(U_10 = (sqrt(u10^2 + v10^2))) %>%
select(-c(u10, v10))
gt_2d %>%
vroom_write((here::here("data/_summarized_data_files", file = "gt_2d_jun_aug_2018.csv")))
rm(t, var, gt_2d, lat)
```
# Hydrography
## Read summary files
```{r read_gt_summary_files}
gt_3d_jun_aug <-
read_tsv((here::here("data/_summarized_data_files", file = "gt_3d_jun_aug_2018.csv")))
gt_2d_jun_aug <-
read_tsv((here::here("data/_summarized_data_files", file = "gt_2d_jun_aug_2018.csv")))
gt_3d_jun_aug <- gt_3d_jun_aug %>%
pivot_wider(values_from = value, names_from = var) %>%
mutate(rho = swSigma(salinity = salt, temperature = temp, pressure = dep/10))
gt_2d_jun_aug_daily <- gt_2d_jun_aug %>%
mutate(day = yday(date_time)) %>%
group_by(day) %>%
summarise_all(list(~mean(.,na.rm=TRUE))) %>%
ungroup() %>%
select(-day)
```
## Hovmoeller Plots
```{r plot_hovmoeller_gt_salt_temp_rho}
p_sal <- gt_3d_jun_aug %>%
filter(dep <= 30) %>%
ggplot()+
geom_raster(aes(date_time, dep, fill=salt))+
scale_fill_viridis_c(name="Salinity ", direction = -1)+
scale_y_reverse()+
coord_cartesian(expand = 0)+
labs(y="Depth [m]")+
theme_bw()+
theme(axis.title.x = element_blank(),
axis.text.x = element_blank())+
geom_line(data= gt_2d_jun_aug_daily,
aes(x = date_time, y = mld_rho), color = "white")+
scale_color_discrete(name = "Legend", labels = c("MLD Rho"))
p_tem <- gt_3d_jun_aug %>%
filter(dep <= 30) %>%
ggplot()+
geom_raster(aes(date_time, dep, fill=temp))+
scale_fill_viridis_c(name="Temperature (°C)", option = "B")+
scale_y_reverse()+
coord_cartesian(expand = 0)+
labs(y="Depth [m]", x="")+
theme_bw()+
theme(axis.title.x = element_blank(),
axis.text.x = element_blank())+
geom_line(data= gt_2d_jun_aug_daily,
aes(x = date_time, y = mld_rho), color = "white")+
scale_color_discrete(name = "Legend", labels = c("MLD Rho"))
p_rho <- gt_3d_jun_aug %>%
filter(dep <= 30) %>%
ggplot()+
geom_raster(aes(date_time, dep, fill=rho))+
scale_fill_viridis_c(name="d Rho (kg/m^3)", direction = -1)+
scale_y_reverse()+
coord_cartesian(expand = 0)+
labs(y="Depth [m]", x="")+
theme_bw()+
theme(axis.title.x = element_blank())+
geom_line(data= gt_2d_jun_aug_daily,
aes(x = date_time, y = mld_rho), color = "white")+
scale_color_discrete(name = "Legend", labels = c("MLD Rho"))
p_sal / p_tem / p_rho
```
## Profiles
```{r plot_profiles_gt_salt_temp_rho}
gt_3d_jun_aug_long <- gt_3d_jun_aug %>%
pivot_longer(3:5, values_to = "value", names_to = "parameter")
#
lab_dates <- pretty(gt_3d_jun_aug_long$date_time)
gt_3d_jun_aug_long %>%
filter(dep<30) %>%
ggplot(aes(value, dep,
col=as.numeric(date_time),
group=as.factor(date_time)))+
geom_path()+
scale_y_reverse(expand = c(0,0))+
scale_color_viridis_c(breaks = as.numeric(lab_dates),
labels = lab_dates,
name="Date")+
theme_bw()+
facet_grid(~parameter, scales = "free_x")
```
# Metrology
## Windspeeds
```{r plot_winspeed}
gt_2d_jun_aug %>%
ggplot()+
geom_line(aes(x= date_time, y = U_10, col="3-hourly"))+
geom_line(data = gt_2d_jun_aug_daily,
aes(x= date_time, y = U_10, col="Daily mean"))+
labs(y="U (m/s)", x = "Date")+
scale_color_brewer(palette = "Set1", name="", direction = -1)+
theme_bw()
```
# Finnmaid data
Finnmaid data, including reconstructed data during LICOS operation failure.
```{r read_Tina-V_Sensor_data, eval= FALSE}
#df <-
# read_csv(here::here("Data/_summarized_data_files",
# "Finnmaid.csv"))
```