Last updated: 2020-03-21
Checks: 7 0
Knit directory: BloomSail/
This reproducible R Markdown analysis was created with workflowr (version 1.6.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20191021)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: data/Finnmaid_2018/
Ignored: data/GETM/
Ignored: data/Maps/
Ignored: data/Ostergarnsholm/
Ignored: data/TinaV/
Ignored: data/_merged_data_files/
Ignored: data/_summarized_data_files/
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
There are no past versions. Publish this analysis with wflow_publish()
to start tracking its development.
library(tidyverse)
library(ncdf4)
library(vroom)
library(lubridate)
library(here)
library(seacarb)
# route
select_route <- "E"
# variable names in 2d and 3d GETM files
#defined later, since more than one needed
# 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-06-01"
end_date <- "2018-08-31"
# data Salinity
var_3d <- "salt"
nc <- nc_open(paste("data/GETM/Finnmaid.E.3d.2018.nc", sep = ""))
nc_2d <- nc_open(paste("data/GETM/Finnmaid.E.2d.2018.nc", sep = ""))
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
d <- ncvar_get(nc, "zax") # read depths vector
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")
nc_close(nc)
# 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_salt_ngs_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_salt_ngs_3d")) {
gt_salt_ngs_3d <- bind_rows(gt_salt_ngs_3d, gt_salt_ngs_3d_part)
} else {gt_salt_ngs_3d <- gt_salt_ngs_3d_part}
rm(array_slice, array_slice_df, gt_salt_ngs_3d_part)
}
rm(nc, time_units, t, d, array, fillvalue)
gt_salt_ngs_3d$date_time %>%
cut.POSIXt(breaks = "days") %>%
round.POSIXt(units = "days")
gt_salt_ngs_3d_jun_aug <- gt_salt_ngs_3d %>%
group_by(dep,var,date_time ) %>%
summarise_all(list(value=~mean(.,na.rm=TRUE))) %>%
ungroup() %>%
filter(date_time >= start_date & date_time <= end_date)
# data temperature
var_3d <- "temp"
nc <- nc_open(paste("data/GETM/Finnmaid.E.3d.2018.nc", sep = ""))
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
d <- ncvar_get(nc, "zax") # read depths vector
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")
nc_close(nc)
# 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_temp_ngs_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_temp_ngs_3d")) {
gt_temp_ngs_3d <- bind_rows(gt_temp_ngs_3d, gt_temp_ngs_3d_part)
} else {gt_temp_ngs_3d <- gt_temp_ngs_3d_part}
rm(array_slice, array_slice_df, gt_temp_ngs_3d_part)
}
rm(nc, time_units, t, d, array, fillvalue, var_3d)
gt_temp_ngs_3d$date_time %>%
cut.POSIXt(breaks = "days") %>%
round.POSIXt(units = "days")
gt_temp_ngs_3d_jun_aug <- gt_temp_ngs_3d %>%
group_by(dep,var,date_time ) %>%
summarise_all(list(value=~mean(.,na.rm=TRUE))) %>%
ungroup() %>%
filter(date_time >= start_date & date_time <= end_date)
# mld rho data
var <- "mld_rho"
nc_2d <- nc_open(paste("data/GETM/Finnmaid.E.2d.2018.nc", sep = ""))
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
array <- ncvar_get(nc_2d, var) # 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_2d, var, "_FillValue")
#nc_close(nc_2d)
# Working with the data
array[array == fillvalue$value] <- NA
array <- ncvar_get(nc_2d, var) # store the data in a 3-dimensional array
dim(array) # should be 2d with dimensions: 1575 coordinate, 31d*(24h/d/3h)=248 time steps
array <- as.data.frame(t(array), xy=TRUE)
array <- as_tibble(array)
gt_mldrho_ngs_2d <- array %>%
set_names(as.character(lat)) %>%
mutate(date_time = t) %>%
gather("lat", "value", 1:length(lat)) %>%
mutate(lat = as.numeric(lat)) %>%
filter(lat > low_lat, lat<high_lat) %>%
mutate(var = var) %>%
dplyr::select(date_time, value, var) %>%
filter(date_time >= start_date & date_time <= end_date)
rm(nc_2d, time_units, t, array, fillvalue, var)
# combine salinity and temperature data
gt_temp_salt_ngs_3d_jun_aug <- inner_join(gt_temp_ngs_3d_jun_aug,gt_salt_ngs_3d_jun_aug, by = c("dep", "date_time"))
gt_temp_salt_ngs_3d_jun_aug %>%
vroom_write((here::here("data/_summarized_data_files", file = "gt_temp_salt_ngs_3d_jun_aug_2018.csv")))
gt_mldrho_ngs_2d %>%
vroom_write((here::here("data/_summarized_data_files", file = "gt_mldrho_ngs_2d_jun_aug_2018.csv")))
rm(gt_salt_ngs_3d, gt_temp_ngs_3d, gt_salt_ngs_3d_jun_aug, gt_temp_ngs_3d_jun_aug, d1_deep, d1_shallow, i, lat)
#Hovmoeller Plots
gt_temp_salt_ngs_3d_jun_aug <-
vroom((here::here("data/_summarized_data_files", file = "gt_temp_salt_ngs_3d_jun_aug_2018.csv")))
gt_mldrho_ngs_2d <-
vroom((here::here("data/_summarized_data_files", file = "gt_mldrho_ngs_2d_jun_aug_2018.csv")))
gt_temp_salt_ngs_3d_jun_aug <- gt_temp_salt_ngs_3d_jun_aug %>%
mutate(date = ymd(date_time),
year = year(date_time))
p1 <- ggplot()+
geom_raster(data= gt_temp_salt_ngs_3d_jun_aug ,aes(date, dep, fill=value.y))+
#scale_fill_scico(palette = "vik", name="mean difference in SST [°C]")+
scale_fill_viridis_c(name="Salility ", option = "B")+
scale_x_date(expand = c(0,0))+
scale_y_continuous(expand = c(0,0))+
labs(y="Depth [m]")+
theme_bw()+
theme(
axis.title.x = element_blank(),
legend.position = "bottom",
legend.key.width = unit(1.3, "cm"),
legend.key.height = unit(0.3, "cm")
)
# add mld rho as white line
p1+
geom_line(data= gt_mldrho_ngs_2d, aes(x = as.Date(date_time),y = value, color = "white"), color = "white")+
scale_color_discrete(name = "Legend", labels = c("MLD Rho"))
gt_temp_salt_ngs_3d_jun_aug <- gt_temp_salt_ngs_3d_jun_aug %>%
mutate(date = ymd(date_time),
year = year(date_time))
p2 <- ggplot()+
geom_raster(data= gt_temp_salt_ngs_3d_jun_aug ,aes(date, dep, fill=value.x))+
#scale_fill_scico(palette = "vik", name="mean difference in SST [°C]")+
scale_fill_viridis_c(name="Temperature [°C] ", option = "B")+
scale_x_date(expand = c(0,0))+
scale_y_continuous(expand = c(0,0))+
labs(y="Depth [m]")+
theme_bw()+
theme(
axis.title.x = element_blank(),
legend.position = "bottom",
legend.key.width = unit(1.3, "cm"),
legend.key.height = unit(0.3, "cm")
)
# add mld rho as white line
p2+
geom_line(data= gt_mldrho_ngs_2d, aes(x = as.Date(date_time),y = value, color = "white"), color = "white")+
scale_color_discrete(name = "Legend", labels = c("MLD Rho"))
#Windspeeds
In the following section, we calculate windspeeds from the parameters v and u. The windspeeds are plotted over time.
# component u10
var <- "u10"
nc_2d <- nc_open(paste("data/GETM/Finnmaid.E.2d.2018.nc", sep = ""))
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
array <- ncvar_get(nc_2d, var) # 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_2d, var, "_FillValue")
nc_close(nc_2d)
# Working with the data
array[array == fillvalue$value] <- NA
array <- as.data.frame(t(array), xy=TRUE)
array <- as_tibble(array)
gt_u10_ngs_2d <- array %>%
set_names(as.character(lat)) %>%
mutate(date_time = t) %>%
gather("lat", "value", 1:length(lat)) %>%
mutate(lat = as.numeric(lat)) %>%
filter(lat > low_lat, lat<high_lat) %>%
mutate(var = var) %>%
dplyr::select(date_time, value, var, lat) %>%
filter(date_time >= start_date & date_time <= end_date)
gt_u10_ngs_2d <- gt_u10_ngs_2d %>%
group_by(var,date_time ) %>%
summarise_all(list(value=~mean(.,na.rm=TRUE))) %>%
ungroup() %>%
mutate(value = value_value) %>%
select(var, value, date_time)
rm(var, array, fillvalue, t, time_units, lat, nc_2d)
# component v10
var <- "v10"
nc_2d <- nc_open(paste("data/GETM/Finnmaid.E.2d.2018.nc", sep = ""))
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
array <- ncvar_get(nc_2d, var) # 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_2d, var, "_FillValue")
nc_close(nc_2d)
# Working with the data
array[array == fillvalue$value] <- NA
array <- as.data.frame(t(array), xy=TRUE)
array <- as_tibble(array)
gt_v10_ngs_2d <- array %>%
set_names(as.character(lat)) %>%
mutate(date_time = t) %>%
gather("lat", "value", 1:length(lat)) %>%
mutate(lat = as.numeric(lat)) %>%
filter(lat > low_lat, lat<high_lat) %>%
mutate(var = var) %>%
dplyr::select(date_time, value, var) %>%
filter(date_time >= start_date & date_time <= end_date)
gt_v10_ngs_2d <- gt_v10_ngs_2d %>%
group_by(var,date_time ) %>%
summarise_all(list(value=~mean(.,na.rm=TRUE))) %>%
ungroup() %>%
select(var, value, date_time)
# combine both
gt_v10_u10_ngs_2d <- full_join(gt_u10_ngs_2d, gt_v10_ngs_2d, by = "date_time")
gt_v10_u10_ngs_2d <- gt_v10_u10_ngs_2d %>%
mutate(windspeed = (sqrt(value.x^2+value.y^2)))
gt_v10_u10_ngs_2d %>%
ggplot()+
geom_line(aes(x= date_time, y = windspeed), color = "blue")+
labs(y="Windspeed", x = "Date")+
theme_bw()+
theme(
axis.title.x = element_blank(),
legend.position = "bottom",
legend.key.width = unit(1.3, "cm"),
legend.key.height = unit(0.3, "cm"))
gt_v10_u10_ngs_2d %>%
vroom_write((here::here("data/_summarized_data_files", file = "gt_u10_v10_windspeed_ngs_3d_jun_aug_2018.csv")))
rm(array, fillvalue, nc_2d, var, t, time_units, lat, gt_u10_ngs_2d, gt_v10_ngs_2d, gt_v10_u10_ngs_2d)
Finnmaid data, including reconstructed data during LICOS operation failure.
#df <-
# read_csv(here::here("Data/_summarized_data_files",
# "Finnmaid.csv"))
sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] seacarb_3.2.12 oce_1.2-0 gsw_1.0-5 testthat_2.3.1
[5] here_0.1 lubridate_1.7.4 vroom_1.2.0 ncdf4_1.17
[9] forcats_0.4.0 stringr_1.4.0 dplyr_0.8.3 purrr_0.3.3
[13] readr_1.3.1 tidyr_1.0.0 tibble_2.1.3 ggplot2_3.3.0
[17] tidyverse_1.3.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 lattice_0.20-35 assertthat_0.2.1 zeallot_0.1.0
[5] rprojroot_1.3-2 digest_0.6.22 R6_2.4.0 cellranger_1.1.0
[9] backports_1.1.5 reprex_0.3.0 evaluate_0.14 httr_1.4.1
[13] pillar_1.4.2 rlang_0.4.5 readxl_1.3.1 rstudioapi_0.10
[17] rmarkdown_2.0 labeling_0.3 bit_1.1-14 munsell_0.5.0
[21] broom_0.5.3 compiler_3.5.0 httpuv_1.5.2 modelr_0.1.5
[25] xfun_0.10 pkgconfig_2.0.3 htmltools_0.4.0 tidyselect_0.2.5
[29] workflowr_1.6.0 viridisLite_0.3.0 crayon_1.3.4 dbplyr_1.4.2
[33] withr_2.1.2 later_1.0.0 grid_3.5.0 nlme_3.1-137
[37] jsonlite_1.6 gtable_0.3.0 lifecycle_0.1.0 DBI_1.0.0
[41] git2r_0.26.1 magrittr_1.5 scales_1.0.0 cli_1.1.0
[45] stringi_1.4.3 fs_1.3.1 promises_1.1.0 xml2_1.2.2
[49] ellipsis_0.3.0 generics_0.0.2 vctrs_0.2.0 tools_3.5.0
[53] bit64_0.9-7 glue_1.3.1 hms_0.5.2 parallel_3.5.0
[57] yaml_2.2.0 colorspace_1.4-1 rvest_0.3.5 knitr_1.26
[61] haven_2.2.0