Last updated: 2020-04-30

Checks: 7 0

Knit directory: BloomSail/

This reproducible R Markdown analysis was created with workflowr (version 1.6.1). 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 results in this page were generated with repository version fe72316. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

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/
    Ignored:    data/backup/
    Ignored:    output/Plots/Figures_publication/.tmp.drivedownload/

Untracked files:
    Untracked:  output/Plots/response_time/

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.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/read-in.Rmd) and HTML (docs/read-in.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd fe72316 jens-daniel-mueller 2020-04-30 revised variable and object names, used temp-dependent tau only, rerun code
html d9248a6 jens-daniel-mueller 2020-04-29 Build site.
Rmd 70bd3f0 jens-daniel-mueller 2020-04-29 correct interpolation, new d pco2 plot
html aa52c73 jens-daniel-mueller 2020-04-28 Build site.
Rmd 3044ec0 jens-daniel-mueller 2020-04-28 completely revised
html 57f7231 jens-daniel-mueller 2020-04-28 Build site.
Rmd 5ebd364 jens-daniel-mueller 2020-04-28 revised
html b5722a7 jens-daniel-mueller 2020-04-28 Build site.
html 472c2b4 jens-daniel-mueller 2020-04-21 Build site.
html f8fcf50 jens-daniel-mueller 2020-04-19 created pub figures for time series
html 87658c3 jens-daniel-mueller 2020-04-14 Build site.
Rmd 5c96a65 jens-daniel-mueller 2020-04-14 temperature penetration depth
html 624835e jens-daniel-mueller 2020-04-02 Build site.
Rmd a7ac65d jens-daniel-mueller 2020-04-02 BloomSail data 1-5m and sd in time series plots
html 26cf733 jens-daniel-mueller 2020-04-02 Build site.
Rmd 57b77af jens-daniel-mueller 2020-04-02 corrected Finnmaid lat borders and plotted fm track in map
html a6c4c22 jens-daniel-mueller 2020-03-30 Build site.
html 80c78b3 jens-daniel-mueller 2020-03-30 Build site.
html 5f8ca30 jens-daniel-mueller 2020-03-20 Build site.
Rmd 1ebd01a jens-daniel-mueller 2020-03-20 reorganitzed filenames and navbar

library(tidyverse)
library(data.table)
library(lubridate)
library(DataExplorer)
library(leaflet)
library(readxl)
library(gsubfn)

In this document, raw data files are read, merged into one file with harmonized column names and written as summarized data file.

1 Sea-Bird SBE 16 sensor data (ts)

CTD sensor data including recordings from auxiliary pH, O2, Chla and pCO2 sensors were recorded with a measurement frequency of 15 sec. (In addition, pCO2 data were also internally recorded on the Contros HydroC instrument with higher temporal resolution and will later be used for further analysis after merging with CTD data.)

1.1 Read regular profiles and transects

files <- list.files(path = "data/TinaV/Sensor/Profiles_Transects/", pattern = "[.]cnv$")
#file <- files[1]

for (file in files){
  
  start.date <- data.table(read.delim(here::here("data/TinaV/Sensor/Profiles_Transects/", file),
                                      sep="#", nrows = 160))[[78,1]]
  start.date <- substr(start.date, 15, 34)
  start.date <- mdy_hms(start.date, tz="UTC")
  
  tempo <- read.delim(here::here("data/TinaV/Sensor/Profiles_Transects/", file),
                      sep="", skip = 160, header = FALSE)
  tempo <- data.table(tempo[,c(2,3,4,5,6,7,9,11,13)])
  names(tempo) <- c("date_time", "dep", "tem", "sal", "V_pH", "pH", "Chl", "O2", "pCO2_analog")
  tempo$start.date <- start.date
  tempo$date_time <- tempo$date_time + tempo$start.date
  
  tempo$ID <- substr(file, 1, 6)
  tempo$type <- substr(file, 8,8)
  tempo$station <- substr(file, 8,10)
  
  tempo$cast <- "up"
  tempo[date_time < mean(tempo[dep == max(tempo$dep)]$date_time)]$cast <- "down"
  
  if (exists("dataset")){
    dataset <- rbind(dataset, tempo)
  }
  
  if (!exists("dataset")){
    dataset <- tempo
  }
  
  rm(start.date)
  rm(tempo)
}


ts <- dataset
rm(dataset, file, files)

1.2 Read profiles and transects around Ostergarnsholm

files <- list.files(path = "data/TinaV/Sensor/Ostergarnsholm/", pattern = "[.]cnv$")

for (file in files){
  
  start.date <- data.table(read.delim(here::here("data/TinaV/Sensor/Ostergarnsholm/", file),
                                      sep="#", nrows = 160))[[78,1]]
  start.date <- substr(start.date, 15, 34)
  start.date <- mdy_hms(start.date, tz="UTC")
  
  tempo <- read.delim(here::here("data/TinaV/Sensor/Ostergarnsholm/", file),
                      sep="", skip = 160, header = FALSE)
  tempo <- data.table(tempo[,c(2,3,4,5,6,7,9,11,13)])
  names(tempo) <- c("date_time", "dep", "tem", "sal", "V_pH", "pH", "Chl", "O2", "pCO2_analog")
  tempo$start.date <- start.date
  tempo$date_time <- tempo$date_time + tempo$start.date
  
  tempo$ID <- substr(file, 1, 6)
  tempo$type <- substr(file, 8,8)
  tempo$station <- substr(file, 11,12)
    
  tempo$cast <- "up"
  tempo[date_time < mean(tempo[dep == max(tempo$dep)]$date_time)]$cast <- "down"
  
  if (exists("dataset")){
    dataset <- rbind(dataset, tempo)
  }
  
  if (!exists("dataset")){
    dataset <- tempo
  }
  
  rm(start.date)
  rm(tempo)
}


ts_OGB <- dataset
rm(dataset, file, files)

ts_OGB <- ts_OGB %>% 
  mutate(type = if_else(station=="bo", "P", "T"),
         station = if_else(station == "bo", "P14", station),
         station = if_else(station == "in", "T14", station),
         station = if_else(station == "ou", "T15", station))
ts <- bind_rows(ts, ts_OGB) %>% 
  arrange(date_time)

rm(ts_OGB)

1.3 EDA raw data

source("code/eda.R")
eda(ts, "ts-raw")
rm(eda)

The output of an automated Exploratory Data Analysis (EDA) performed with the package DataExplorer can be accessed here:

Link to EDA report of CTD raw data

1.4 Clean data set

Sensor recordings were cleaned from obviously erroneous readings, by setting suspecious values to NA.

class(ts)
ts <- data.table(ts)

# Profiling data

# temperature

# ts %>%
#   filter(type == "P") %>%
#   ggplot(aes(tem, dep, col=station, linetype = cast))+
#   geom_line()+
#   scale_y_reverse()+
#   geom_vline(xintercept = c(10, 20))+
#   facet_wrap(~ID)

ts[ID == "180723" & station == "P07" & dep < 2 & cast == "up"]$tem <- NA

# salinity

# ts %>%
#   filter(type == "P") %>%
#   ggplot(aes(sal, dep, col=station, linetype = cast))+
#   geom_path()+
#   scale_y_reverse()+
#   facet_wrap(~ID)

ts[sal < 6]$sal <- NA

# pH

# ts %>%
#   filter(type == "P") %>%
#   ggplot(aes(pH, dep, col=station, linetype=cast))+
#   geom_path()+
#   scale_y_reverse()+
#   facet_wrap(~ID)
# 
# ts %>%
#   filter(type == "P") %>%
#   ggplot(aes(V_pH, dep, col=station, linetype=cast))+
#   geom_path()+
#   scale_y_reverse()+
#   facet_wrap(~ID)

ts[pH < 7.5]$V_pH <- NA
ts[pH < 7.5]$pH <- NA

ts[ID == "180709" & station == "P03" & dep < 5 & cast == "down"]$pH <- NA
ts[ID == "180709" & station == "P05" & dep < 10 & cast == "down"]$pH <- NA
ts[ID == "180718" & station == "P10" & dep < 3 & cast == "down"]$pH <- NA
ts[ID == "180815" & station == "P03" & dep < 2 & cast == "down"]$pH <- NA
ts[ID == "180820" & station == "P11" & dep < 15 & cast == "down"]$pH <- NA

ts[ID == "180709" & station == "P03" & dep < 5 & cast == "down"]$V_pH <- NA
ts[ID == "180709" & station == "P05" & dep < 10 & cast == "down"]$V_pH <- NA
ts[ID == "180718" & station == "P10" & dep < 3 & cast == "down"]$V_pH <- NA
ts[ID == "180815" & station == "P03" & dep < 2 & cast == "down"]$V_pH <- NA
ts[ID == "180820" & station == "P11" & dep < 15 & cast == "down"]$V_pH <- NA


# pCO2

# ts %>%
#   filter(type == "P") %>%
#   ggplot(aes(pCO2, dep, col=station, linetype = cast))+
#   geom_path()+
#   scale_y_reverse()+
#   facet_wrap(~ID)

ts[ID == "180616"]$pCO2_analog <- NA

# O2

# ts %>% 
#   filter(type == "P") %>% 
#   ggplot(aes(O2, dep, col=station, linetype = cast))+
#   geom_path()+
#   scale_y_reverse()+
#   facet_wrap(~ID)

# Chlorophyll

# ts %>%
#   filter(type == "P") %>%
#   ggplot(aes(Chl, dep, col=station, linetype = cast))+
#   geom_path()+
#   scale_y_reverse()+
#   facet_wrap(~ID)

ts[Chl > 100]$Chl <- NA


#### Surface transect data

# ts %>%
#   filter(type == "T") %>%
#   ggplot(aes(date, dep, col=station))+
#   geom_point()+
#   scale_y_reverse()+
#   facet_wrap(~ID, scales = "free_x")
# 
# ts %>%
#   filter(type == "T") %>%
#   ggplot(aes(date, tem, col=station))+
#   geom_point()+
#   facet_wrap(~ID, scales = "free_x")
# 
# ts %>%
#   filter(type == "T") %>%
#   ggplot(aes(date, sal, col=station))+
#   geom_point()+
#   facet_wrap(~ID, scales = "free_x")
# 
# ts %>%
#   filter(type == "T") %>%
#   ggplot(aes(date, pCO2, col=station))+
#   geom_point()+
#   facet_wrap(~ID, scales = "free_x")
# 
# ts %>%
#   filter(type == "T") %>%
#   ggplot(aes(date, pH, col=station))+
#   geom_point()+
#   facet_wrap(~ID, scales = "free_x")
# 
# ts %>%
#   filter(type == "T") %>%
#   ggplot(aes(date, Chl, col=station))+
#   geom_point()+
#   facet_wrap(~ID, scales = "free_x")

ts[type == "T" & Chl > 10]$Chl <- NA


# ts %>% 
#   filter(type == "T") %>% 
#   ggplot(aes(date, O2, col=station))+
#   geom_point()+
#   facet_wrap(~ID, scales = "free_x")

1.5 Write summary file

Relevant columns were selected and renamed, only observations from regular stations (P01-P13) and transects (T01-T13) were selected and summarized data were written to file.

ts <- ts %>% 
  select(date_time,
         ID,
         type,
         station,
         dep,
         sal,
         tem,
         pCO2_analog)

# ts <- ts %>% 
#   filter( !(station %in% c("PX1", "PX2", "TX1", "TX2") ))

ts %>% 
  write_csv(here::here("data/_summarized_data_files", "ts.csv"))

rm(ts)

1.6 EDA clean data

ts <- read_csv(here::here("data/_summarized_data_files", "ts.csv"),
               col_types = cols(pCO2_analog = col_double()))
source("code/eda.R")
eda(ts, "ts_clean")

rm(eda)

The output of an automated Exploratory Data Analysis (EDA) performed with the package DataExplorer can be accessed here:

Link to EDA report of CTD clean data

1.7 Overview plots

ts %>%
  arrange(date_time) %>% 
  filter(type == "P", !(station %in% c("PX1", "PX2"))) %>%
  ggplot(aes(tem, dep, col=ymd(ID), group=ID))+
  geom_path()+
  scale_y_reverse()+
  scale_color_viridis_c(trans = "date", name="")+
  labs(x="temperature (°C)", y="Depth (m)")+
  facet_wrap(~station)
temperature profiles by stations. Color refers to the starting date of each cruise.

temperature profiles by stations. Color refers to the starting date of each cruise.

ts %>%
  arrange(date_time) %>% 
  filter(type == "P", !(station %in% c("PX1", "PX2"))) %>%
  ggplot(aes(pCO2_analog, dep, col=ymd(ID), group=ID))+
  geom_path()+
  scale_y_reverse()+
  scale_color_viridis_c(trans = "date", name="")+
  labs(x="temperature (°C)", y="Depth (m)")+
  facet_wrap(~station)
pCO~2~ (analog signal) profiles by stations. Color refers to the starting date of each cruise.

pCO2 (analog signal) profiles by stations. Color refers to the starting date of each cruise.

2 HydroC CO2 data (th)

2.1 Read data

HydroC pCO2 data were provided by KM Contros after applying a drift correction to the raw data, which was based on pre- and post-deployment calibration results.

# Read Contros corrected data file

th <-
  read_csv2(here::here("Data/TinaV/Sensor/HydroC-pCO2/corrected_Contros",
                       "parameter&pCO2s(method 43).txt"),
            col_names = c("date_time", "Zero", "Flush", "p_NDIR",
                          "p_in", "T_control", "T_gas", "%rH_gas",
                          "Signal_raw", "Signal_ref", "T_sensor",
                          "pCO2_corr", "Runtime", "nr.ave")) %>% 
  mutate(date_time = dmy_hms(date_time),
         Flush = as.factor(as.character(Flush)),
         Zero = as.factor(as.character(Zero)))

2.2 Deployment identification and subsetting

Individual deployments (periods of observations with less than 30 sec between recordings) were identified and relevant deployment periods were subsetted. This procedure removes only recordings attributable to sensor testing and set-up.

th <- th %>% 
  arrange(date_time) %>% 
  mutate(deployment = cumsum(c(TRUE,diff(date_time)>=30)))

th <- th %>% 
  filter(deployment %in% c(2,6,9,14,17,21,23,27,31,33,34,35,37))

2.3 Removal of duplicated time stamps

# add counter for date_time observations

th <- th %>% 
  add_count(date_time)

# find triplicated time stamp and select only first observation, and merge

th_no_triple <- th %>% 
  filter(n <= 2)

th_triple_clean <- th %>% 
  filter(n > 2) %>% 
  slice(1)

th <- full_join(th_no_triple, th_triple_clean)

rm(list=setdiff(ls(), "th"))


# find duplicated time stamps and shift first by one second backward, and merge

th %>% 
  distinct(date_time)

th <- th %>% 
  select(-n) %>% 
  add_count(date_time)

unique(th$n)

th_no_duplicated <- th %>%
  filter(n == 1)

th_duplicated <- th %>% 
  filter(n == 2)

th_duplicated_first <- th_duplicated %>% 
  group_by(date_time) %>% 
  slice(1) %>% 
  ungroup() %>% 
  mutate(date_time = date_time - 1)

th_duplicated_second <- th_duplicated %>% 
  group_by(date_time) %>% 
  slice(2) %>% 
  ungroup()

th_duplicated_clean <- full_join(th_duplicated_first, th_duplicated_second) %>% 
  arrange(date_time)

th <- full_join(th_no_duplicated, th_duplicated_clean)

th %>% 
  distinct(date_time)

rm(list=setdiff(ls(), "th"))



# find duplicated time stamps and shift first by two seconds forward, and merge

th %>% 
  distinct(date_time)

th <- th %>% 
  select(-n) %>% 
  add_count(date_time)

unique(th$n)

th_no_duplicated <- th %>%
  filter(n == 1)

th_duplicated <- th %>% 
  filter(n == 2)

th_duplicated_first <- th_duplicated %>% 
  group_by(date_time) %>% 
  slice(1) %>% 
  ungroup() %>% 
  mutate(date_time = date_time + 2)

th_duplicated_second <- th_duplicated %>% 
  group_by(date_time) %>% 
  slice(2) %>% 
  ungroup()

th_duplicated_clean <- full_join(th_duplicated_first, th_duplicated_second) %>% 
  arrange(date_time)

th <- full_join(th_no_duplicated, th_duplicated_clean)

th %>% 
  distinct(date_time)

rm(list=setdiff(ls(), "th"))

# remaining duplicates are observations where other observations with a +/- 1 sec timestamp exist
# for those cases, only the first duplicated observation is selected (similar to triplicate treatment)


th %>% 
  distinct(date_time)

th <- th %>% 
  select(-n) %>% 
  add_count(date_time)

unique(th$n)


th_still_no_duplicated <- th %>% 
  filter(n == 1)

th_still_duplicated_first <- th %>% 
  filter(n == 2) %>% 
  group_by(date_time) %>% 
  slice(1)

th <- full_join(th_still_no_duplicated, th_still_duplicated_first)

th %>% 
  distinct(date_time)

rm(list=setdiff(ls(), "th"))

th <- th %>% 
  select(-n)

2.4 Flush and Zeroing identification

# Zeroing ID labelling

th <- th %>% 
  arrange(date_time) %>% 
  group_by(Zero) %>% 
  mutate(Zero_ID = as.factor(cumsum(c(TRUE,diff(date_time)>=30)))) %>% 
  ungroup()

unique(th$Zero_ID)

# Flush: Identification

th <- th %>% 
  mutate(Flush = 0) %>% 
  group_by(Zero, Zero_ID) %>% 
  mutate(start = min(date_time),
         duration = date_time - start,
         Flush = if_else(Zero == 0 & duration < 600, "1", "0")) %>% 
  ungroup()


#  Flush: Identify equilibration and internal gas mixing periods

th <- th %>% 
  mutate(mixing = if_else(duration < 20, "mixing", "equilibration"))

2.5 Deployment plots

pdf(file=here::here("output/Plots/read_in",
    "th_deployments.pdf"), onefile = TRUE, width = 7, height = 4)

for (i in unique(th$deployment)) {
  
  #i <- unique(th$deployment)[3]
  
  sub <-  th %>%
      filter(deployment == i)
  start_date <- min(sub$date_time)
  
  print(
    sub %>% 
      ggplot(aes(date_time, pCO2_corr, col=Zero_ID))+
      geom_line()+
      labs(title = paste("Deployment: ",i, "| Start time: ", start_date))
)
  
}

dev.off()

rm(sub, start_date, i)

A pdf with pCO2 timeseries plots of all deployments can be found here:

Link to pCO2 timeseries plots

source("code/eda.R")
eda(th, "th")
rm(eda)

The output of an automated Exploratory Data Analysis (EDA) performed with the package DataExplorer can be accessed here:

Link to EDA report of HydroC pCO2 data data

2.6 Write summary file

Summarized pCO2 date were written to file.

th %>% write_csv(here::here("Data/_summarized_data_files",
                            "th_full.csv"))

th %>% 
  select(date_time, Zero, Flush, pCO2_corr, deployment, Zero_ID, duration, mixing) %>% 
  write_csv(here::here("Data/_summarized_data_files",
                       "th.csv"))

rm(th)

3 Bottle data / discrete samples (tb)

Discrete samples were collected with a Niskin bottle and analysed for C[T] and A[T] at IOW CO2 lab.

3.1 Read data

tb <- read_csv(here::here("Data/TinaV/Bottle/Tracegases", "BloomSail_bottle_CO2_all.csv"),
                   col_types = list("c","c","n","n","n","n","n"))

tb <- tb %>% 
  select(ID=transect.ID,
         station=label,
         dep=Dep,
         sal=Sal,
         CT, AT)

3.2 Write summary file

tb %>% write_csv(here::here("Data/_summarized_data_files",
                            "tb.csv"))
rm(tb)

4 GPS track (tt)

GPS track data were recorded with a Samsung Galaxy tablet.

4.1 Read data

files <- list.files(path = "data/TinaV/Track/GPS_Logger_Track/", pattern = "[.]txt$")


for (file in files){
  
  # if the merged dataset does exist, append to it
  if (exists("dataset")){
    
    tempo<-data.table(read.delim(here::here("data/TinaV/Track/GPS_Logger_Track", file),
                                 sep=",")[,c(2,3,4)])
    names(tempo) <- c("date_time", "lat", "lon")
    tempo$date_time<- ymd_hms(tempo$date, tz="UTC")
    
    dataset<-rbind(dataset, tempo)
    rm(tempo)
  }
  
  # if the merged dataset doesn't exist, create it
  if (!exists("dataset")){
    dataset<-data.table(read.delim(here::here("data/TinaV/Track/GPS_Logger_Track", file),
                                   sep=",")[,c(2,3,4)])
    names(dataset) <- c("date_time", "lat", "lon")
    dataset$date_time<- ymd_hms(dataset$date_time, tz="UTC")
    
  }
}

tt <- dataset
rm(dataset, file, files)

4.2 Write summary file

tt %>% 
  write_csv(here::here("data/_summarized_data_files",
                       "tt.csv"))

rm(tt)

5 Finnmaid

pCO2 data were recorded on VOS Finnmaid in summer 2018.

5.1 Read data

### June - August 2018

files <- list.files(path = "data/Finnmaid_2018", pattern = "[.]xls$")
#file <-files[1]

for (file in files){
  
  
  df <- read_excel(here::here("data/Finnmaid_2018", file))
  df <- df[c(1,2,3,12,7,4,15,8,5,17)]
  names(df) <- c("date_time","lon","lat","pCO2","sal","tem","cO2","patm", "Teq","xCO2")
  df <- df[-c(1),]
  df$date_time <- as.POSIXct(as.numeric(df$date_time)*60*60*24, origin="1899-12-30", tz="GMT")
  df$lon <- as.numeric(as.character(df$lon))
  df$lat <- as.numeric(as.character(df$lat))
  df$pCO2 <- as.numeric(as.character(df$pCO2))
  df$sal <- as.numeric(as.character(df$sal))
  df$tem <- as.numeric(as.character(df$tem))
  df$cO2 <- as.numeric(as.character(df$cO2))
  df$patm <- as.numeric(as.character(df$patm))
  df$Teq <- as.numeric(as.character(df$Teq))
  df$xCO2 <- as.numeric(as.character(df$xCO2))
  df <- data.table(df)
  
  df$route <- strapplyc(as.character(file), ".*(.).xls*", simplify = TRUE)
  df$ID <- substr(as.character(file), 3, 10)
  
  if (exists("temp")){
    temp <- rbind (temp, df)
  } else{temp <- df}
  
}


rm(df, files, file)
temp <- temp[pCO2 != 0]


#### Los Gatos data


files <- list.files(path = "data/Finnmaid_2018/LGR", pattern = "[.]xls$")
#file <-files[1]

for (file in files){
  
  
  df <- read_excel(here::here("data/Finnmaid_2018/LGR", file))
  df <- df[c(2,3,4,8,6,5,14,7,15,9)]
  names(df) <- c("date_time","lon","lat","pCO2","sal","tem","cO2","patm", "Teq","xCO2")
  df <- df[-c(1),]
  df$date_time <- dmy_hms(df$date_time)
  df <- data.table(df)
  
  df$route <- substr(as.character(file), 12, 12)
  df$ID <- substr(as.character(file), 3, 10)
  
  if (exists("temp.LGR")){
    temp.LGR <- rbind (temp.LGR, df)
  } else{temp.LGR <- df}
  
}

5.2 Convert O2 concentration units

source(here::here("code", "O2stoO2c.R"))

temp.LGR <- temp.LGR %>%
  filter() %>% 
  mutate(cO2 = O2stoO2c(O2sat = cO2, T=tem, S=sal, P=3/10, p_atm = 1013.5))

rm(O2stoO2c, pH2Osat, sca_T, Scorr, TCorr, R, Vm)
temp$sensor <- "LICOR"
temp.LGR$sensor <- "LosGatos"

fm <- bind_rows(temp, temp.LGR)

rm(temp, temp.LGR, df, file, files)


# temp$Area <- with(temp,
#                   ifelse(lon>12 & lon<12.6, "1.MEB",
#                   ifelse(lon>13.1 & lon<14.3, "2.ARK",
#                   ifelse(lat>57.5 & lat<58.5 & route %in% c("E", "G"), "4.EGS",
#                   ifelse(lat>57.3 & lat<57.5 & route %in% c("E"), "BS",
#                   ifelse(lat>56.8 & lat<57.5 & route=="W", "3.WGS",
#                   ifelse(lat>58.5 & lat<59 & lon>20, "5.NGS",
#                   ifelse(lon>22 & lon<24, "6.WGF",
#                   ifelse(lon>24 & lon<24.5, "7.HGF", "NaN")))))))))

5.3 Write summary file

fm <-fm[complete.cases(fm[,pCO2]),]

fm %>% 
  write_csv(here::here("Data/_summarized_data_files",
                       "fm.csv"))
rm(fm)

6 Interactive map

fm <- read_csv(here::here("Data/_summarized_data_files",
                       "fm.csv"))

fm_sub <- fm %>%
  arrange(date_time) %>% 
  slice(which(row_number() %% 20 == 1))

tt <- read_csv(here::here("Data/_summarized_data_files", "tt.csv"))

tt_sub <- tt %>%
  slice(which(row_number() %% 20 == 1))

rm(tt, fm)

leaflet() %>% 
  setView(lng = 20, lat = 57.3, zoom = 8) %>%
  addLayersControl(baseGroups = c("Ocean Basemap",
                                  "Satellite"),
                   overlayGroups = c("BloomSail", "Finnmaid"),
                   options = layersControlOptions(collapsed = FALSE),
                   position = 'topright') %>% 
  addProviderTiles("Esri.WorldImagery", group = "Satellite") %>%
  addProviderTiles(providers$Esri.OceanBasemap, group = "Ocean Basemap") %>%
  addScaleBar(position = 'topright') %>%
  addMeasure(
    primaryLengthUnit = "kilometers",
    secondaryLengthUnit = 'miles', 
    primaryAreaUnit = "sqmeters",
    secondaryAreaUnit="acres", 
    position = 'topleft') %>% 
  addCircles(data = fm_sub, ~lon, ~lat,
               color = "white",
               group = "Finnmaid") %>% 
  addPolylines(data = tt_sub, ~lon, ~lat,
               color = "red",
               group = "BloomSail")

7 Tasks / open questions


sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_Germany.1252  LC_CTYPE=English_Germany.1252   
[3] LC_MONETARY=English_Germany.1252 LC_NUMERIC=C                    
[5] LC_TIME=English_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] gsubfn_0.7         proto_1.0.0        readxl_1.3.1       leaflet_2.0.3     
 [5] DataExplorer_0.8.1 lubridate_1.7.4    data.table_1.12.8  forcats_0.5.0     
 [9] stringr_1.4.0      dplyr_0.8.5        purrr_0.3.3        readr_1.3.1       
[13] tidyr_1.0.2        tibble_3.0.0       ggplot2_3.3.0      tidyverse_1.3.0   
[17] workflowr_1.6.1   

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4              whisker_0.4             knitr_1.28             
 [4] xml2_1.3.0              magrittr_1.5            hms_0.5.3              
 [7] rvest_0.3.5             tidyselect_1.0.0        viridisLite_0.3.0      
[10] here_0.1                colorspace_1.4-1        lattice_0.20-41        
[13] R6_2.4.1                rlang_0.4.5             fansi_0.4.1            
[16] tcltk_3.6.3             parallel_3.6.3          broom_0.5.5            
[19] xfun_0.12               dbplyr_1.4.2            modelr_0.1.6           
[22] withr_2.1.2             git2r_0.26.1            ellipsis_0.3.0         
[25] htmltools_0.4.0         assertthat_0.2.1        rprojroot_1.3-2        
[28] digest_0.6.25           lifecycle_0.2.0         haven_2.2.0            
[31] rmarkdown_2.1           compiler_3.6.3          cellranger_1.1.0       
[34] pillar_1.4.3            leaflet.providers_1.9.0 scales_1.1.0           
[37] backports_1.1.5         generics_0.0.2          jsonlite_1.6.1         
[40] httpuv_1.5.2            pkgconfig_2.0.3         igraph_1.2.5           
[43] rstudioapi_0.11         munsell_0.5.0           highr_0.8              
[46] httr_1.4.1              tools_3.6.3             networkD3_0.4          
[49] grid_3.6.3              nlme_3.1-145            gtable_0.3.0           
[52] DBI_1.1.0               cli_2.0.2               crosstalk_1.1.0.1      
[55] yaml_2.2.1              crayon_1.3.4            gridExtra_2.3          
[58] farver_2.0.3            later_1.0.0             promises_1.1.0         
[61] htmlwidgets_1.5.1       fs_1.4.0                vctrs_0.2.4            
[64] glue_1.3.2              evaluate_0.14           labeling_0.3           
[67] reprex_0.3.0            stringi_1.4.6