Last updated: 2020-11-25

Checks: 7 0

Knit directory: Cant_eMLR/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). 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 44d4ef3. 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/
    Ignored:    dump/

Untracked files:
    Untracked:  code/biogeochemical_functions.R
    Untracked:  code/test_scripts/analysis_previous_studies.Rmd
    Untracked:  code/test_scripts/read_World_Ocean_Atlas_2013_Clement.Rmd

Unstaged changes:
    Modified:   analysis/_site.yml
    Deleted:    analysis/analysis_previous_studies.Rmd
    Modified:   analysis/analysis_this_study.Rmd
    Modified:   analysis/analysis_this_study_vs_Gruber_2019.Rmd
    Modified:   analysis/child/setup.Rmd
    Modified:   analysis/mapping_cant_calculation.Rmd
    Modified:   analysis/mapping_cstar_calculation.Rmd
    Deleted:    analysis/read_World_Ocean_Atlas_2013_Clement.Rmd
    Modified:   code/Workflowr_project_managment.R
    Modified:   code/mapping_functions.R
    Modified:   code/plotting_functions.R

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/mapping_predictor_preparation.Rmd) and HTML (docs/mapping_predictor_preparation.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 44d4ef3 jens-daniel-mueller 2020-11-25 republish after creating functions
html b9cbd4f jens-daniel-mueller 2020-11-20 Build site.
html e563eef jens-daniel-mueller 2020-11-20 Build site.
Rmd 6b50088 jens-daniel-mueller 2020-11-20 rebuild all with seperate set-up and harmonized variable names
html 064d52f jens-daniel-mueller 2020-11-20 Build site.
Rmd 7ffabe6 jens-daniel-mueller 2020-11-20 use setup child Rmd file
html fc70a34 jens-daniel-mueller 2020-11-10 Build site.
html b170b79 jens-daniel-mueller 2020-11-03 Build site.
html 411a35b jens-daniel-mueller 2020-10-02 Build site.
html 0d38979 jens-daniel-mueller 2020-10-01 Build site.
html 4578cfa jens-daniel-mueller 2020-09-19 Build site.
html d59f716 jens-daniel-mueller 2020-09-18 Build site.
html f5a20ac jens-daniel-mueller 2020-09-17 Build site.
html cf64460 jens-daniel-mueller 2020-09-17 Build site.
html d43d9e2 jens-daniel-mueller 2020-09-16 Build site.
Rmd 9529ad2 jens-daniel-mueller 2020-09-16 PO4 and silicate included for pCO2 and revelle factor calculation
html 1f3319a jens-daniel-mueller 2020-09-16 Build site.
html 2e57b3f jens-daniel-mueller 2020-09-16 Build site.
Rmd e45d875 jens-daniel-mueller 2020-09-16 jonied surface predictor fields
html da91d98 jens-daniel-mueller 2020-09-10 Build site.
html 4c73801 jens-daniel-mueller 2020-09-10 Build site.
Rmd da66d06 jens-daniel-mueller 2020-09-10 global section plots modified
html f6f30c0 jens-daniel-mueller 2020-09-10 Build site.
Rmd f74449b jens-daniel-mueller 2020-09-10 global section plots added
html a34a239 jens-daniel-mueller 2020-09-10 Build site.
Rmd 143fbd7 jens-daniel-mueller 2020-09-10 global section plot added
html e60e13c jens-daniel-mueller 2020-09-09 Build site.
Rmd 7040b80 jens-daniel-mueller 2020-09-09 remove basin_AIP not covered by mapping
html c3ffdfd jens-daniel-mueller 2020-09-08 Build site.
Rmd 04ee730 jens-daniel-mueller 2020-09-08 rebuild after revision
html a50f053 jens-daniel-mueller 2020-09-07 Build site.
html da445a6 jens-daniel-mueller 2020-09-04 Build site.
html fa11a74 jens-daniel-mueller 2020-09-02 Build site.
html 429aab3 jens-daniel-mueller 2020-09-01 Build site.
html f4216dd jens-daniel-mueller 2020-09-01 Build site.
Rmd 8f3ce45 jens-daniel-mueller 2020-09-01 rebuild without PO4 star selection, oxygen only
html 13a76d5 jens-daniel-mueller 2020-08-28 Build site.
Rmd 2e6a4ca jens-daniel-mueller 2020-08-28 XXX
html 27404de jens-daniel-mueller 2020-08-27 Build site.
html 78feb87 jens-daniel-mueller 2020-08-27 Build site.
Rmd 42e98c8 jens-daniel-mueller 2020-08-27 section plots for all regular longitude added
html 9ba6c6f jens-daniel-mueller 2020-08-27 Build site.
Rmd a503cab jens-daniel-mueller 2020-08-27 section plots for all regular longitude added
html cbb9282 jens-daniel-mueller 2020-08-27 Build site.
Rmd bdb5c02 jens-daniel-mueller 2020-08-27 section plots for all regular longitude added
html 533920b jens-daniel-mueller 2020-08-27 Build site.
Rmd 94fbf0f jens-daniel-mueller 2020-08-27 section plots for all regular longitude added
html 2ddebe0 jens-daniel-mueller 2020-08-27 Build site.
Rmd 7bf17cd jens-daniel-mueller 2020-08-27 removed control plots
html b6d0e6a jens-daniel-mueller 2020-08-27 Build site.
html f40e48b jens-daniel-mueller 2020-08-26 Build site.
html ec20f40 jens-daniel-mueller 2020-08-24 Build site.
Rmd a804955 jens-daniel-mueller 2020-08-24 split mapping into 2 rmds, po4star selection in parameters, use po4star nitrate

1 Libraries

Loading libraries specific to the the analysis performed in this section.

library(metR)
library(marelac)
library(gsw)

2 Required data

All required data sets were subsetted spatially in the read-in section Data base. Currently, following data sets are used for mapping:

2.1 GLODAPv2_2016b_MappedClimatologies

Following variables are currently used:

  • Phosphate (+Phosphate*)
  • Silicate
  • Oxygen (+AOU)
  • TAlk (surface only)
  • TCO2 (surface only)
variables <-
  c("oxygen", "PO4", "silicate")

for (i_variable in variables) {
  temp <- read_csv(
    here::here(
      "data/interim",
      paste("GLODAPv2_2016_MappedClimatology",i_variable, ".csv", sep = "")
    )
  )
  
  if (exists("GLODAP_predictors")) {
    GLODAP_predictors <- full_join(GLODAP_predictors, temp)
  }
  
  if (!exists("GLODAP_predictors")) {
    GLODAP_predictors <- temp
  }
}

rm(temp, i_variable, variables)

GLODAP_predictors <- GLODAP_predictors %>%
  rename(phosphate = PO4)

# removed na's attributable to slightly different coverage of predictor fields
GLODAP_predictors <- GLODAP_predictors %>%
  drop_na()
variables <-
  c("PO4", "silicate", "TAlk", "TCO2")

for (i_variable in variables) {
  temp <- read_csv(
    here::here(
      "data/interim",
      paste("GLODAPv2_2016_MappedClimatology",i_variable, ".csv", sep = "")
    )
  )
  
  if (exists("GLODAP_predictors_CO2")) {
    GLODAP_predictors_CO2 <- full_join(GLODAP_predictors_CO2, temp)
  }
  
  if (!exists("GLODAP_predictors_CO2")) {
    GLODAP_predictors_CO2 <- temp
  }
}

rm(temp, i_variable, variables)


GLODAP_predictors_CO2 <- GLODAP_predictors_CO2 %>%
  rename(phosphate = PO4)

# removed na's attributable to slightly different coverage of predictor fields
GLODAP_predictors_CO2 <- GLODAP_predictors_CO2 %>%
  drop_na()

2.2 World Ocean Atlas 2018

  • Salinity
  • Temperature
  • Neutral density
WOA18_predictors <-
  read_csv(
    here::here(
      "data/interim",
      "WOA18_sal_tem.csv"
    )
  )

WOA18_predictors_surface <-
  read_csv(
    here::here(
      "data/interim",
      "WOA18_sal_tem_surface.csv"
    )
  )

3 Join WOA18 + GLODAP

WOA18 and GLODAP predictor climatologies are merged. Only horizontal grid cells with observations from both predictor fields are kept.

CAVEAT: Coverage of GLODAP climatologies differs slightly for parameters (some are NA in some regions)

predictors <- full_join(
  GLODAP_predictors,
  WOA18_predictors)

predictors <- predictors %>% 
  drop_na()

rm(GLODAP_predictors, WOA18_predictors)
predictors_surface <- full_join(
  GLODAP_predictors_CO2,
  WOA18_predictors_surface)

predictors_surface <- predictors_surface %>% 
  drop_na()

rm(GLODAP_predictors_CO2, WOA18_predictors_surface)

3.1 Control plots

3.1.1 Maps

Three maps are generated to control successful merging of data sets.

p_map_climatology_continous(predictors, "phosphate")

p_map_climatology_continous(predictors, "tem")

3.1.2 Maps surface

Three maps are generated to control successful merging of data sets.

p_map_climatology_continous(predictors_surface, "TAlk")

p_map_climatology_continous(predictors_surface, "TCO2")

p_map_climatology_continous(predictors_surface, "sal")

p_map_climatology_continous(predictors_surface, "tem")

3.1.3 Predictor profiles

Likewise, predictor profiles for the North Atlantic (40.5 / 335.5) are plotted to control successful merging of the data sets.

N_Atl <- predictors %>% 
  filter(lat == parameters$lat_Atl_profile,
         lon == parameters$lon_Atl_section)

N_Atl <- N_Atl %>% 
  select(-c(basin, basin_AIP)) %>% 
  pivot_longer(oxygen:gamma, names_to = "parameter", values_to = "value")

N_Atl %>% 
  ggplot(aes(value, depth)) +
  geom_path() +
  geom_point() +
  scale_y_reverse() +
  facet_wrap(~parameter,
             scales = "free_x",
             ncol = 2)

rm(N_Atl)

4 Prepare predictor fields

4.1 PO4* calculation

The predictor PO4* was be calculated according to Clement and Gruber (2018), ie based on oxygen. Please note that an errornous equations for PO4* calculation is given in the supplement of Gruber et al (2019), based on nitrate.

predictors <- predictors %>% 
  mutate(phosphate_star = b_phosphate_star(phosphate, oxygen))

4.1.1 Maps

p_map_climatology_divergent(predictors, "phosphate_star")

4.1.2 Sections

p_section_global_divergent(predictors, "phosphate_star")

4.2 AOU

4.2.1 Calculation

AOU was calculated as the difference between saturation concentration and observed concentration. CAVEAT: Algorithms used to calculate oxygen saturation concentration are not yet identical in GLODAP data set (fitting) and predictor climatologies (mapping).

predictors <- predictors %>% 
  mutate(aou = b_aou(sal, tem, depth, oxygen))

4.2.2 Maps

p_map_climatology_continous(predictors, "aou")

4.2.3 Sections

p_section_global_divergent(predictors, "aou")

4.3 Isoneutral slabs

The following boundaries for isoneutral slabs were defined:

  • Atlantic: -, 26, 26.5, 26.75, 27, 27.25, 27.5, 27.75, 27.85, 27.95, 28.05, 28.1, 28.15, 28.2,
  • Indo-Pacific: -, 26, 26.5, 26.75, 27, 27.25, 27.5, 27.75, 27.85, 27.95, 28.05, 28.1,

Continuous neutral density (gamma) values based on WOA18 are grouped into isoneutral slabs.

predictors <- m_cut_gamma(predictors, "gamma")

5 Plot al predictor sections

5.1 Deep waters

Predictor sections along with lines are shown below for each (potential) predictor variable.

map +
  geom_bin2d(data = predictors,
             aes(lon, lat),
             binwidth = c(1,1)) +
  geom_vline(xintercept = parameters$longitude_sections_regular,
             col = "white") +
  scale_fill_viridis_c(direction = -1) +
  theme(legend.position = "bottom")

vars <-
  c(
    "gamma",
    "sal",
    "tem",
    "phosphate",
    "phosphate_star",
    "oxygen",
    "aou",
    "silicate"
  )

# i_var <- vars[1]

for (i_var in vars) {
  print(p_section_climatology_regular_continous(predictors, i_var))
}

5.2 Surface waters

Predictor sections along with lines are shown below for each (potential) predictor variable.

map +
  geom_bin2d(data = predictors_surface,
             aes(lon, lat),
             binwidth = c(1,1)) +
  geom_vline(xintercept = parameters$longitude_sections_regular,
             col = "white") +
  scale_fill_viridis_c(direction = -1) +
  theme(legend.position = "bottom")

vars <-
  c(
    "gamma",
    "sal",
    "tem",
    "TCO2",
    "TAlk"
  )

for (i_var in vars) {
  print(p_section_climatology_regular_continous(predictors_surface, i_var))
}

6 Write csv

predictors %>%
    write_csv(here::here("data/mapping",
                         "W18_st_G16_opsn.csv"))

predictors_surface %>%
    write_csv(here::here("data/mapping",
                         "W18_st_G16_opsn_surface.csv"))

sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-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] gsw_1.0-5       testthat_2.3.2  marelac_2.1.10  shape_1.4.4    
 [5] metR_0.7.0      scico_1.2.0     patchwork_1.0.1 collapse_1.3.2 
 [9] forcats_0.5.0   stringr_1.4.0   dplyr_1.0.0     purrr_0.3.4    
[13] readr_1.3.1     tidyr_1.1.0     tibble_3.0.3    ggplot2_3.3.2  
[17] tidyverse_1.3.0 workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] httr_1.4.2        viridisLite_0.3.0 jsonlite_1.7.0    here_0.1         
 [5] modelr_0.1.8      Formula_1.2-3     assertthat_0.2.1  blob_1.2.1       
 [9] cellranger_1.1.0  yaml_2.2.1        pillar_1.4.6      backports_1.1.8  
[13] lattice_0.20-41   glue_1.4.1        digest_0.6.25     promises_1.1.1   
[17] checkmate_2.0.0   rvest_0.3.6       colorspace_1.4-1  sandwich_2.5-1   
[21] htmltools_0.5.0   httpuv_1.5.4      Matrix_1.2-18     pkgconfig_2.0.3  
[25] broom_0.7.0       seacarb_3.2.13    haven_2.3.1       xtable_1.8-4     
[29] scales_1.1.1      whisker_0.4       later_1.1.0.1     git2r_0.27.1     
[33] farver_2.0.3      generics_0.0.2    ellipsis_0.3.1    withr_2.2.0      
[37] cli_2.0.2         magrittr_1.5      crayon_1.3.4      readxl_1.3.1     
[41] evaluate_0.14     fs_1.4.2          fansi_0.4.1       xml2_1.3.2       
[45] oce_1.2-0         tools_4.0.2       data.table_1.13.0 hms_0.5.3        
[49] lifecycle_0.2.0   munsell_0.5.0     reprex_0.3.0      isoband_0.2.2    
[53] compiler_4.0.2    lfe_2.8-5.1       rlang_0.4.7       grid_4.0.2       
[57] rstudioapi_0.11   labeling_0.3      rmarkdown_2.3     gtable_0.3.0     
[61] DBI_1.1.0         R6_2.4.1          zoo_1.8-8         lubridate_1.7.9  
[65] knitr_1.30        rprojroot_1.3-2   stringi_1.4.6     parallel_4.0.2   
[69] Rcpp_1.0.5        vctrs_0.3.2       dbplyr_1.4.4      tidyselect_1.1.0 
[73] xfun_0.16