Last updated: 2020-07-14

Checks: 7 0

Knit directory: Cant_eMLR/

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(20200707) 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 dc1c56e. 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:    .Rproj.user/
    Ignored:    data/_summarized_data_files/
    Ignored:    dump/
    Ignored:    output/plots/

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/data_base.Rmd) and HTML (docs/data_base.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 dc1c56e jens-daniel-mueller 2020-07-14 tref calculated
html b1ece68 jens-daniel-mueller 2020-07-13 Build site.
Rmd 8eb1b22 jens-daniel-mueller 2020-07-13 cleaned data base file
Rmd 9e8f7f1 jens-daniel-mueller 2020-07-13 untracked changes
html 79312b2 jens-daniel-mueller 2020-07-13 Build site.
html 090cfeb jens-daniel-mueller 2020-07-13 Build site.
Rmd e6a2ade jens-daniel-mueller 2020-07-13 added Cstar calculation
html ae846e5 jens-daniel-mueller 2020-07-09 Build site.
Rmd 80782a1 jens-daniel-mueller 2020-07-09 Data cleaning, gridding, coverage plots
html f73ba58 jens-daniel-mueller 2020-07-08 Build site.
Rmd 8de2366 jens-daniel-mueller 2020-07-08 Data cleaning, gridding, coverage plots
html 6f0ac0f jens-daniel-mueller 2020-07-08 Build site.
Rmd 9f12d15 jens-daniel-mueller 2020-07-08 Data cleaning, gridding, coverage plots
html 848d7c4 jens-daniel-mueller 2020-07-08 Build site.
Rmd 5de66c3 jens-daniel-mueller 2020-07-08 correct label GLODAPv2_2020
html 81670f8 jens-daniel-mueller 2020-07-08 Build site.
Rmd 36cbea0 jens-daniel-mueller 2020-07-08 read GLODAPv2_2020

library(tidyverse)
library(lubridate)
library(patchwork)

1 Read GLODAP master file

GLODAP <- read_csv(here::here("data", "GLODAPv2.2020_Merged_Master_File.csv"),
                   na = "-9999",
                   col_types = cols(.default = col_double()))

# relevant columns
GLODAP <- GLODAP %>% 
  select(cruise:talkqc)

GLODAP <- GLODAP %>% 
  mutate(date = ymd(paste(year, month, day))) %>% 
         #decade = as.factor(floor(year / 10) * 10)) %>% 
  relocate(date)

GLODAP <- GLODAP %>% 
  select(-c(month:minute, 
            maxsampdepth, pressure,
            theta, sigma0:gamma,
            nitrate:nitritef))
GLODAP_stats <- GLODAP %>% 
  summarise(total = n(),
            tco2 = sum(!is.na(tco2)),
            tco2_flag = sum(!is.na(tco2) & tco2f == 2 & tco2qc == 1),
            talk = sum(!is.na(talk)),
            talk_f_qc = sum(!is.na(talk) & talkf == 2 & talkqc == 1),
            phosphate = sum(!is.na(phosphate)),
            phosphate_f_qc = sum(!is.na(phosphate) & phosphatef == 2 & phosphateqc == 1))

GLODAP_stats_2 <- GLODAP %>% 
  summarise(tco2_talk = sum(!is.na(tco2) & !is.na(talk)),
            tco2_phosphate = sum(!is.na(tco2) & !is.na(phosphate)),
            tco2_talk_phosphate = sum(!is.na(tco2) & !is.na(talk) & !is.na(phosphate)),
            tco2_talk_phosphate_f_qc = sum(!is.na(tco2) & !is.na(talk) & !is.na(phosphate) &
                                        tco2f == 2 & tco2qc == 1 &
                                        talkf == 2 & talkqc == 1 &
                                        phosphatef == 2 & phosphateqc == 1),
           incl_pH = sum(!is.na(tco2) & !is.na(talk) & !is.na(phosphate) &
                                        tco2f == 2 & tco2qc == 1 &
                                        talkf == 2 & talkqc == 1 &
                                        phosphatef == 2 & phosphateqc == 1 &
                                        !is.na(phts25p0)))

GLODAP_stats <- cbind(GLODAP_stats, GLODAP_stats_2)

rm(GLODAP_stats_2)

GLODAP_stats_long <- GLODAP_stats %>% 
  pivot_longer(1:12, names_to = "parameter", values_to = "n")

GLODAP_stats_long  %>%  write_csv(here::here("data/_summarized_data_files",
                                             "GLODAPv2.2020_stats.csv"))

2 Clean data

GLODAP <- GLODAP %>% 
  filter(!is.na(tco2))

GLODAP <- GLODAP %>% 
  filter(tco2f == "2") %>% 
  select(-tco2f)

GLODAP <- GLODAP %>% 
  filter(tco2qc == "1") %>% 
  select(-tco2qc)

###

GLODAP <- GLODAP %>% 
  filter(!is.na(talk))

GLODAP <- GLODAP %>% 
  filter(talkf == "2") %>% 
  select(-talkf)

GLODAP <- GLODAP %>% 
  filter(talkqc == "1") %>% 
  select(-talkqc)

###

GLODAP <- GLODAP %>% 
  filter(!is.na(phosphate))

GLODAP <- GLODAP %>% 
  filter(phosphatef == "2") %>% 
  select(-phosphatef)

GLODAP <- GLODAP %>% 
  filter(phosphateqc == "1") %>% 
  select(-phosphateqc)

###

GLODAP <- GLODAP %>% 
  filter(!is.na(temperature))

###
  
GLODAP <- GLODAP %>% 
  filter(!is.na(salinity))

GLODAP <- GLODAP %>% 
  filter(salinityf == "2") %>% 
  select(-salinityf)

GLODAP <- GLODAP %>% 
  filter(salinityqc == "1") %>% 
  select(-salinityqc)

###
  
GLODAP <- GLODAP %>% 
  filter(!is.na(silicate))

GLODAP <- GLODAP %>% 
  filter(silicatef == "2") %>% 
  select(-silicatef)

GLODAP <- GLODAP %>% 
  filter(silicateqc == "1") %>% 
  select(-silicateqc)

###
  
GLODAP <- GLODAP %>% 
  filter(!is.na(oxygen))

GLODAP <- GLODAP %>% 
  filter(oxygenf == "2") %>% 
  select(-oxygenf)

GLODAP <- GLODAP %>% 
  filter(oxygenqc == "1") %>% 
  select(-oxygenqc)

###

GLODAP <- GLODAP %>% 
  filter(!is.na(aou))

GLODAP <- GLODAP %>% 
  filter(aouf == "2") %>% 
  select(-aouf)

3 Assign reference eras

Samples before Jan 01, 2000 were assigned as to the “JGOFS/WOCE” era, else to “GO-SHIP” era.

GLODAP <- GLODAP %>%
  filter(year >= 1981) %>% 
  mutate(era = "JGOFS/WOCE",
         era = if_else(year >= 2000, "GO-SHIP", era),
         era = if_else(year >= 2013, "new_era", era))
GLODAP  %>%  write_csv(here::here("data/_summarized_data_files",
                                  "GLODAPv2.2020_clean.csv"))

4 Overview GLODAPv2-2020

4.1 Nr of observations

GLODAP_stats_long <-  read_csv(here::here("data/_summarized_data_files",
                                             "GLODAPv2.2020_stats.csv"))

GLODAP_stats_long %>% 
  ggplot(aes(parameter, n))+
  geom_col()+
  coord_flip()

rm(GLODAP_stats_long)

4.2 Data coverage

Spatio-temporal distribution of non-flagged, paired talk, tco2, and phosphate data.

GLODAP <- read_csv(here::here("data/_summarized_data_files",
                              "GLODAPv2.2020_clean.csv"))

4.3 Gridding

GLODAP <- GLODAP %>% 
  mutate(lat_grid = cut(latitude, seq(-90, 90, 5), seq(-87.5, 87.5, 5)),
         lat_grid = as.numeric(as.character(lat_grid)),
         lon_grid = cut(longitude, seq(-180, 180, 5), seq(-177.5, 177.5, 5)),
         lon_grid = as.numeric(as.character(lon_grid)))

GLODAP <- GLODAP %>% 
  arrange(date)

GLODAP_histogram_year <- GLODAP %>% 
  group_by(era, year) %>% 
  tally() %>% 
  ungroup()

GLODAP_map_era <- GLODAP %>% 
  group_by(era, lat_grid, lon_grid) %>% 
  tally() %>% 
  ungroup()

GLODAP_hovmoeller_year <- GLODAP %>% 
  group_by(year, lat_grid) %>% 
  tally() %>% 
  ungroup()

era_median_year <- GLODAP %>% 
  group_by(era) %>% 
  summarise(t_ref = median(year)) %>% 
  ungroup()

4.4 Histograms

GLODAP %>% 
  ggplot(aes(latitude, fill=era))+
  geom_histogram(binwidth = 10, col="black", boundary = 0)+
  scale_x_continuous(breaks = seq(-85,90,10))+
  scale_fill_viridis_d()+
  coord_flip(expand = 0)

GLODAP_histogram_year %>% 
  ggplot(aes(year, n, fill=era))+
  geom_col()+
  geom_vline(xintercept = era_median_year$t_ref)+
  coord_cartesian(expand = 0)

rm(GLODAP_histogram_year)

4.5 Hovmoeller (Lat-time)

GLODAP_hovmoeller_year %>% 
  ggplot(aes(year, lat_grid, fill=log10(n)))+
  geom_vline(xintercept = c(2000, 2013))+
  geom_tile()+
  scale_fill_viridis_c(option = "magma", direction = -1)

rm(GLODAP_hovmoeller_year)

4.6 Maps

mapWorld <- borders("world", colour="gray60", fill="gray60")

GLODAP_map_era <- GLODAP_map_era %>% 
  mutate(era = factor(era, c("JGOFS/WOCE", "GO-SHIP", "new_era")))

GLODAP_map_era %>%
  ggplot(aes(lon_grid, lat_grid, fill=log10(n)))+
  mapWorld+
  geom_raster()+
  scale_fill_viridis_c(option = "magma", direction = -1)+
  scale_x_continuous(breaks = seq(-180, 180, 30))+
  scale_y_continuous(breaks = seq(-90, 90, 30))+
  coord_quickmap(expand = FALSE)+
  facet_wrap(~era, ncol=1)

rm(GLODAP_map_era)

4.7 Individual cruise sections

cruises <- GLODAP %>% 
  group_by(cruise) %>% 
  summarise(date_mean = mean(date, na.rm = TRUE),
            n = n()) %>% 
  ungroup() %>% 
  arrange(date_mean)

GLODAP <- full_join(GLODAP, cruises)

mapWorld <- borders("world", colour="gray60", fill="gray60")

n <- 0
for (i_cruise in unique(cruises$cruise)) {

#i_cruise <- unique(cruises$cruise)[1]
n <- n+1
print(n)  
  
GLODAP_cruise <- GLODAP %>%
  filter(cruise == i_cruise) %>% 
  arrange(date)

cruises_cruise <- cruises %>%
  filter(cruise == i_cruise)
  
map <- GLODAP_cruise %>%
  ggplot(aes(longitude, latitude))+
  mapWorld+
  geom_point(aes(col=date))+
  geom_path()+
  coord_quickmap(expand = FALSE)+
  scale_color_viridis_c(trans = "date")+
  labs(title = paste("Mean date:", cruises_cruise$date_mean,
                     "| cruise:", cruises_cruise$cruise,
                     "| n(samples):", cruises_cruise$n))


lon_section <- GLODAP_cruise %>%
  ggplot(aes(longitude, depth))+
  scale_y_reverse()+
  scale_color_viridis_c()

lon_tco2 <- lon_section+
  geom_point(aes(col=tco2))

lon_talk <- lon_section+
  geom_point(aes(col=talk))

lon_phosphate <- lon_section+
  geom_point(aes(col=phosphate))


lat_section <- GLODAP_cruise %>%
  ggplot(aes(latitude, depth))+
  scale_y_reverse()+
  scale_color_viridis_c()

lat_tco2 <- lat_section+
  geom_point(aes(col=tco2))

lat_talk <- lat_section+
  geom_point(aes(col=talk))

lat_phosphate <- lat_section+
  geom_point(aes(col=phosphate))

map /
((lat_tco2 / lat_talk / lat_phosphate) |
(lon_tco2 / lon_talk / lon_phosphate))

ggsave(here::here("output/plots/data/all_cruises_clean",
                  paste("GLODAP_cruise_date",
                        cruises_cruise$date_mean,
                        "n",
                        cruises_cruise$n,
                        "cruise",
                        cruises_cruise$cruise,
                        ".png",
                        sep = "_")),
                  width = 9, height = 9)

rm(map,
   lon_section, lat_section,
   lat_tco2, lat_talk, lat_phosphate, lon_tco2, lon_talk, lon_phosphate,
   GLODAP_cruise, cruises_cruise)

}


# library("rnaturalearth")
# library("rnaturalearthdata")
# library("sf")
# 
# world <- ne_countries(scale = "small", returnclass = "sf")
# class(world)
# 
# GLODAP_map <- GLODAP %>% 
#   group_by(lat_grid, lon_grid) %>% 
#   tally() %>% 
#   ungroup()
# 
# ggplot() +
#   geom_raster(data = GLODAP_map, aes(lon_grid, lat_grid))+
#   geom_sf(data = world)+
#   coord_sf(crs = "+proj=robin +lat_0=0 +lon_0=0 +x0=0 +y0=0")


# https://gist.github.com/clauswilke/783e1a8ee3233775c9c3b8bfe531e28a
# https://twitter.com/clauswilke/status/1066024436208406529
# https://www.r-spatial.org/r/2018/10/25/ggplot2-sf.html

5 Open tasks

6 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] patchwork_1.0.0 lubridate_1.7.4 forcats_0.5.0   stringr_1.4.0  
 [5] dplyr_1.0.0     purrr_0.3.4     readr_1.3.1     tidyr_1.0.2    
 [9] tibble_3.0.1    ggplot2_3.3.2   tidyverse_1.3.0 workflowr_1.6.1

loaded via a namespace (and not attached):
 [1] jsonlite_1.6.1    rstudioapi_0.11   generics_0.0.2    magrittr_1.5     
 [5] farver_2.0.3      gtable_0.3.0      rmarkdown_2.1     vctrs_0.3.0      
 [9] fs_1.4.0          hms_0.5.3         xml2_1.3.0        pillar_1.4.4     
[13] htmltools_0.5.0   haven_2.2.0       later_1.0.0       broom_0.5.5      
[17] cellranger_1.1.0  lattice_0.20-41   tidyselect_1.1.0  knitr_1.28       
[21] git2r_0.26.1      whisker_0.4       lifecycle_0.2.0   pkgconfig_2.0.3  
[25] R6_2.4.1          digest_0.6.25     xfun_0.12         colorspace_1.4-1 
[29] rprojroot_1.3-2   stringi_1.4.6     yaml_2.2.1        evaluate_0.14    
[33] labeling_0.3      fansi_0.4.1       httr_1.4.1        compiler_3.6.3   
[37] here_0.1          cli_2.0.2         withr_2.1.2       backports_1.1.5  
[41] munsell_0.5.0     DBI_1.1.0         modelr_0.1.6      Rcpp_1.0.4.6     
[45] readxl_1.3.1      maps_3.3.0        dbplyr_1.4.2      ellipsis_0.3.1   
[49] assertthat_0.2.1  tools_3.6.3       reprex_0.3.0      viridisLite_0.3.0
[53] httpuv_1.5.2      scales_1.1.0      crayon_1.3.4      glue_1.4.1       
[57] rlang_0.4.6       nlme_3.1-145      rvest_0.3.5       promises_1.1.0   
[61] grid_3.6.3