Last updated: 2020-03-18

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/Maps/
    Ignored:    data/Ostergarnsholm/
    Ignored:    data/TinaV/
    Ignored:    data/_merged_data_files/
    Ignored:    data/_summarized_data_files/

Untracked files:
    Untracked:  output/Plots/MLD/

Unstaged changes:
    Modified:   analysis/_site.yml

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(patchwork)
library(seacarb)
library(zoo)
#library(metR)
#library(scico)
# library(broom)
library(lubridate)
# library(tibbletime)
library(marelac)
library(seacarb)

1 Sensor data

The cruise mean pCO2 recorded in profiling-mode (stations only) and depths < 3m was used for gas exchange calcualtions.

water <-
  read_csv(here::here("Data/_merged_data_files", "BloomSail_CTD_HydroC_CT.csv"))

water <- water %>% 
  filter(dep < 3) %>% 
  select(date_time, ID, tem, pCO2_water = pCO2)

water_ID <- water %>% 
  group_by(ID) %>% 
  summarise_all(mean) %>% 
  ungroup() %>% 
  select(-ID)

water_ID %>% 
  ggplot(aes(date_time, pCO2_water))+
  geom_point(data=water, aes(date_time, pCO2_water), col="grey")+
  geom_path()+
  geom_point()

start <- min(water$date_time)
end   <- max(water$date_time)

2 Wind data

Metrological data were recorded on the flux tower located on Ostergarnsholm island.

air <- read_delim(here::here("Data/Ostergarnsholm/Tower", "Oes_Jens_atm_water_June_to_August_2018.csv"),
                 delim = ";"               )

air <- air %>%
  mutate(date_time = ymd_hms( paste(paste(year, month, day, sep = "/"),
                                          paste(hour, min, sec, sep = ":")))) %>% 
  select("date_time",
         "CO2 12m [ppm]",
         "w_c [ppm m/s]",
         "WS 12m [m/s]",
         "WD 12m [degrees]",
         "T 12m [degrees C]",
         "RIS [W/m^2]"
         ) %>% 
  filter(date_time > start,
         date_time < end)

rm(end, start)

air <- air %>% 
  mutate(freq = "30 min") %>% 
  select(date_time, freq, pCO2_air = "CO2 12m [ppm]", wind = "WS 12m [m/s]")
df <- full_join(air, water_ID) %>% 
  arrange(date_time)

df <- df %>% 
  mutate(pCO2_water = na.approx(pCO2_water, rule = 2),
         tem = na.approx(tem, rule = 2),
         wind = na.approx(wind, rule = 2)) %>% 
  filter(!is.na(pCO2_air))

df_daily <- df %>% 
  mutate(day = yday(date_time)) %>% 
  group_by(day) %>% 
  summarise_all(mean, na.rm = TRUE) %>% 
  ungroup() %>% 
  select(-day) %>% 
  mutate(freq = "daily")

df <- bind_rows(df, df_daily)


rm(air, water_ID, water, df_daily)

2.1 Time series plot

df_long <- df %>% 
  gather("parameter", "value", 3:6)

df_long %>% 
  ggplot(aes(date_time, value, col=freq))+
  geom_line()+
  facet_grid(parameter~., scales = "free_y")+
  scale_color_brewer(palette = "Set1", direction = -1)+
  theme_bw()

3 Air-sea CO2 flux

3.1 Calculation

F = k * dCO2

with

dCO2 = K0 * dpCO2 and

k = coeff * U^2 * (660/Sc)^0.5

Units used here are:

  • dpCO2: µatm
  • K0: mol atm-1 kg-1
  • dCO2: µmol kg-1

  • wind speed U: m s-1

  • coeff for k calculation (eg 0.251 in W14): cm hr-1 (m s-1)-2
  • gas transfer velocities k: cm hr-1 (= 6060100 m s-1)

  • air sea CO2 flux F: mol m–2 d–1

  • conversion between the unit of k * dCO2 and F requires a factor of 10-5 * 24

Sc_W14 <- function(tem) {
  2116.8 - 136.25 * tem + 4.7353 * tem^2 - 0.092307 * tem^3 + 0.0007555 * tem^4
}

Sc_W14(20)
[1] 668.344
df <- df %>% 
  mutate(dpCO2 = pCO2_water - pCO2_air,
         dCO2  = dpCO2 * K0(S=6.92, T=tem),
         k_W92 = gas_transfer(t = tem, u10 = wind, species = "CO2", method = "Wanninkhof1")* 60^2 * 100,
         k_W14 = 0.251 * wind^2 * (Sc_W14(tem)/660)^(-0.5),
         #F_W14_simple = 7.7 * 10^(–4) wind^2,
         k_SM18 = 0.24 * wind^2 * ((1943-119.6*tem + 3.488*tem^2 - 0.0417*tem^3) / 660)^(-0.5)) %>% 
  pivot_longer(9:11, names_to = "k_para", values_to = "k_value")

# calculate flux F [mol m–2 d–1]

df <- df %>% 
  mutate(flux_daily = k_value*dCO2*1e-5*24) 

Timeseries

df %>% 
  ggplot(aes(date_time, flux_daily, col=k_para))+
  geom_line()+
  labs(y="F (mol m-2 d-1)")+
  facet_wrap(~freq)

# scale flux to time interval

df <- df %>% 
  mutate(scale = if_else(freq == "daily", 1, 24*2)) %>% 
  mutate(flux_scale = flux_daily / scale) %>% 
  group_by(freq, k_para) %>% 
  arrange(date_time) %>% 
  mutate(flux_cum = cumsum(flux_scale)) %>% 
  ungroup()

df %>% 
  ggplot(aes(date_time, flux_cum, col=k_para))+
  geom_line()+
  labs(y="F (mol m-2)")+
  facet_wrap(~freq)

4 Open tasks / questions

  • Calculate mean wind direction correctly for northerly winds
  • Correct conversion of CO2 concentration from mol kg-1 to mol m-3 required?

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] marelac_2.1.9   shape_1.4.4     lubridate_1.7.4 zoo_1.8-6      
 [5] seacarb_3.2.12  oce_1.2-0       gsw_1.0-5       testthat_2.3.1 
 [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         here_0.1           lattice_0.20-35    assertthat_0.2.1  
 [5] zeallot_0.1.0      rprojroot_1.3-2    digest_0.6.22      R6_2.4.0          
 [9] cellranger_1.1.0   backports_1.1.5    reprex_0.3.0       evaluate_0.14     
[13] httr_1.4.1         pillar_1.4.2       rlang_0.4.5        readxl_1.3.1      
[17] rstudioapi_0.10    rmarkdown_2.0      labeling_0.3       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    crayon_1.3.4       dbplyr_1.4.2       withr_2.1.2       
[33] later_1.0.0        grid_3.5.0         nlme_3.1-137       jsonlite_1.6      
[37] gtable_0.3.0       lifecycle_0.1.0    DBI_1.0.0          git2r_0.26.1      
[41] magrittr_1.5       scales_1.0.0       cli_1.1.0          stringi_1.4.3     
[45] fs_1.3.1           promises_1.1.0     xml2_1.2.2         ellipsis_0.3.0    
[49] generics_0.0.2     vctrs_0.2.0        RColorBrewer_1.1-2 tools_3.5.0       
[53] glue_1.3.1         hms_0.5.2          yaml_2.2.0         colorspace_1.4-1  
[57] rvest_0.3.5        knitr_1.26         haven_2.2.0