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(seacarb)
library(oce)
library(marelac)

1 Sensor data

1m gridded, downcast profiles were used.

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

2 Mixed layer depth

df <- df %>% 
  mutate(rho = swSigma(salinity = sal, temperature = tem, pressure = dep/10))

 # seacarb = rho(S = sal, T = tem, P = pres),
 # marelac = sw_dens(S = sal, t = tem, p = pres + 1, method = "Gibbs")
# density criterion

df <- expand_grid(df, rho_lim = c(0.1,0.2,0.5))

df <- df %>% 
  group_by(ID, date_time_ID, station, rho_lim) %>% 
  mutate(d_rho = rho - min(rho)) %>% 
  mutate(layer = if_else(d_rho > rho_lim, "deep", "surface")) %>% 
  ungroup()
  
MLD <- df  %>% 
  group_by(ID, date_time_ID, station, rho_lim) %>% 
  filter(d_rho > rho_lim) %>% 
  summarise(MLD = min(dep)) %>% 
  ungroup()

df <- full_join(df, MLD)
df %>% 
  filter(dep < 30) %>% 
  arrange(dep) %>% 
  ggplot(aes(rho, dep))+
  geom_hline(aes(yintercept = MLD))+
  geom_path()+
  geom_point(aes(col=layer))+
  scale_y_reverse()+
  scale_color_brewer(palette = "Set1", direction = -1)+
  facet_grid(ID~station)
MLD_sum <- MLD %>% 
  select(-station) %>% 
  group_by(ID, date_time_ID, rho_lim)%>%
  summarise_all(list(~mean(.),~sd(.),~min(.), ~max(.)))

MLD_sum %>% 
  ggplot()+
  geom_ribbon(aes(date_time_ID, ymin = min, ymax = max), alpha = 0.5)+
  geom_path(aes(date_time_ID, mean))+
  geom_errorbar(aes(date_time_ID, ymin = mean-sd, ymax = mean+sd))+
  geom_point(aes(date_time_ID, mean))+
  labs(x="Mean transect date", y="Mixed layer depth [m]")+
  ylim(0,30)+
  facet_wrap(~rho_lim)

Rho, S, and T profiles were plotted individually pdf here.

df_long <- df %>% 
  pivot_longer(cols = c("sal", "tem", "rho"), names_to = "parameter", values_to = "value")

pdf(file=here::here("output/Plots/MLD",
    "profiles_MLD_individual.pdf"), onefile = TRUE, width = 9, height = 5)

for(i_ID in unique(df_long$ID)){
  for(i_station in unique(df_long$station)){
 
      
      #i_ID      <-      unique(df_long$ID)[1]
      #i_station <- unique(df_long$station)[1]

      if (nrow(df_long %>% filter(ID == i_ID, station == i_station)) > 0){
      
    
    
      print(
    
        
        df_long %>%
          arrange(date_time) %>% 
          filter(ID == i_ID,
                 station == i_station,
                 dep<20) %>%
          ggplot(aes(value,dep))+
          geom_hline(aes(yintercept = MLD))+
          geom_path()+
          scale_y_reverse()+
          scale_color_brewer(palette = "Set1")+
          labs(y="Depth [m]", title = str_c(i_ID," | ",i_station))+
          facet_wrap(~parameter, scales = "free_x")+
          theme_bw()
      )
    }
  }
}

dev.off()

rm(i_ID, i_station)

3 NCP penetration depth

CT_ts <-
  read_csv(here::here("Data/_merged_data_files", "BloomSail_CTD_HydroC_CT_cumulative_timeseries.csv"))

CT_profiles <-
  read_csv(here::here("Data/_merged_data_files", "BloomSail_CTD_HydroC_CT_cumulative_profiles.csv"))

CT_conc_surf <-
  CT_profiles %>% 
  filter(dep < 3,
         parameter == "CT",
         sign == "neg") %>% 
  group_by(ID, date_time_ID) %>% 
  summarise(dCT = mean(diff_value))

CT_conc_surf %>% 
  ggplot(aes(date_time_ID, dCT))+
  geom_path()

NCP_integ <- CT_ts %>% 
  filter(sign == "neg") %>% 
  group_by(ID, date_time_ID) %>% 
  summarise(dNCPi = sum(dCT))

NCP_integ %>% 
  ggplot(aes(date_time_ID, dNCPi))+
  geom_path()

CT <- full_join(CT_conc_surf, NCP_integ)

CT <- CT %>% 
  mutate(dep_NCP = -(dNCPi/dCT)*1e3)

CT_long <- CT %>% 
  pivot_longer(3:5, names_to = "parameter", values_to = "values")

CT_long %>% 
  ggplot(aes(date_time_ID, values))+
  geom_path()+
  geom_point()+
  facet_grid(parameter~., scales = "free_y")


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     seacarb_3.2.12  oce_1.2-0      
 [5] gsw_1.0-5       testthat_2.3.1  forcats_0.4.0   stringr_1.4.0  
 [9] dplyr_0.8.3     purrr_0.3.3     readr_1.3.1     tidyr_1.0.0    
[13] tibble_2.1.3    ggplot2_3.3.0   tidyverse_1.3.0

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5 xfun_0.10        haven_2.2.0      lattice_0.20-35 
 [5] colorspace_1.4-1 vctrs_0.2.0      generics_0.0.2   htmltools_0.4.0 
 [9] yaml_2.2.0       rlang_0.4.5      later_1.0.0      pillar_1.4.2    
[13] withr_2.1.2      glue_1.3.1       DBI_1.0.0        dbplyr_1.4.2    
[17] modelr_0.1.5     readxl_1.3.1     lifecycle_0.1.0  munsell_0.5.0   
[21] gtable_0.3.0     workflowr_1.6.0  cellranger_1.1.0 rvest_0.3.5     
[25] evaluate_0.14    labeling_0.3     knitr_1.26       httpuv_1.5.2    
[29] broom_0.5.3      Rcpp_1.0.2       promises_1.1.0   backports_1.1.5 
[33] scales_1.0.0     jsonlite_1.6     fs_1.3.1         hms_0.5.2       
[37] digest_0.6.22    stringi_1.4.3    grid_3.5.0       rprojroot_1.3-2 
[41] here_0.1         cli_1.1.0        tools_3.5.0      magrittr_1.5    
[45] crayon_1.3.4     pkgconfig_2.0.3  zeallot_0.1.0    xml2_1.2.2      
[49] reprex_0.3.0     lubridate_1.7.4  rstudioapi_0.10  assertthat_0.2.1
[53] rmarkdown_2.0    httr_1.4.1       R6_2.4.0         nlme_3.1-137    
[57] git2r_0.26.1     compiler_3.5.0