Last updated: 2020-08-26

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 b577ec6. 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/GLODAPv1_1/
    Ignored:    data/GLODAPv2_2016b_MappedClimatologies/
    Ignored:    data/GLODAPv2_2020/
    Ignored:    data/Gruber_2019/
    Ignored:    data/WOCE/
    Ignored:    data/World_Ocean_Atlas_2013_Clement/
    Ignored:    data/World_Ocean_Atlas_2018/
    Ignored:    data/eMLR/
    Ignored:    data/mapping/
    Ignored:    data/pCO2_atmosphere/
    Ignored:    dump/

Unstaged changes:
    Modified:   analysis/_site.yml
    Deleted:    analysis/analysis.Rmd

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
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

library(tidyverse)
library(metR)
library(marelac)
# library(lubridate)
# library(oce)
# library(reticulate)
basinmask <- read_csv(here::here("data/World_Ocean_Atlas_2018/_summarized_files",
                                 "basin_mask_WOA18.csv"))

landmask <- read_csv(here::here("data/World_Ocean_Atlas_2018/_summarized_files",
                                 "land_mask_WOA18.csv"))

1 Required data

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

1.1 GLODAPv2_2016b_MappedClimatologies

Following variables are currently used:

  • Salinity
  • Temperature
  • Phosphate (+Phosphate*)
  • Silicate
  • Oxygen (+AOU)
variables <-
  c("salinity", "temperature", "oxygen", "PO4", "silicate", "NO3")

for (i_variable in variables) {
  temp <- read_csv(
    here::here(
      "data/GLODAPv2_2016b_MappedClimatologies/_summarized_files",
      paste(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)

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

GLODAP_predictors <- GLODAP_predictors %>%
  rename(sal = salinity,
         tem = temperature)

1.2 World Ocean Atlas 2018

  • Neutral density
  • Basin mask
WOA18_predictors <-
  read_csv(
    here::here(
      "data/World_Ocean_Atlas_2018/_summarized_files",
      "WOA18_predictors.csv"
    )
  )

1.3 WOA13

Neutral densities and the basin mask based on WOA13 and provided by Dominic Clement are currently not used.

WOA13 <-
  read_csv(
    here::here(
      "data/World_Ocean_Atlas_2013_Clement/_summarized_files",
      "WOA13_mask_gamma.csv"
    )
  )

WOA13_gamma <- WOA13 %>%
  select(-mask)

rm(WOA13)

2 Join predictor climatologies

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

2.1 Control plots

Maps of number of observations per horizontal grid cell, which reflects the number of depth levels.

2.1.1 GLODAP climatology

GLODAP_predictors %>% 
  ggplot(aes(lon, lat)) +
  geom_bin2d(binwidth = 1) +
  scale_fill_viridis_c(direction = -1) +
  coord_quickmap(expand = 0) +
  theme(legend.position = "bottom")

2.1.2 WOA18 climatology

WOA18_predictors <- WOA18_predictors %>% 
  filter(depth %in% parameters$depth_levels_33)

WOA18_predictors %>% 
  ggplot(aes(lon, lat)) +
  geom_bin2d(binwidth = 1) +
  scale_fill_viridis_c(direction = -1) +
  coord_quickmap(expand = 0) +
  theme(legend.position = "bottom")

2.1.3 Neutral density zonal mean section

WOA18_predictors_zonal <- WOA18_predictors %>%
  group_by(lat, depth, basin) %>%
  summarise(gamma_mean = mean(gamma)) %>%
  ungroup()

WOA18_predictors_zonal_Atl <- WOA18_predictors_zonal %>%
  filter(basin == "Atlantic") %>%
  mutate(gamma_slab = cut(gamma_mean, parameters$slabs_Atl))

WOA18_predictors_zonal_Ind_Pac <- WOA18_predictors_zonal %>%
  filter(basin == "Indo-Pacific") %>%
  mutate(gamma_slab = cut(gamma_mean, parameters$slabs_Ind_Pac))

WOA18_predictors_zonal <- bind_rows(WOA18_predictors_zonal_Atl, WOA18_predictors_zonal_Ind_Pac)

rm(WOA18_predictors_zonal_Atl, WOA18_predictors_zonal_Ind_Pac)

slab_breaks <- c(parameters$slabs_Atl[1:12], Inf)

WOA18_predictors_zonal %>%
  filter(depth <= parameters$inventory_depth) %>%
  ggplot(aes(lat, depth, z = gamma_mean)) +
  geom_contour_filled(breaks = slab_breaks) +
  geom_contour(breaks = slab_breaks,
               col = "white") +
  geom_text_contour(breaks = slab_breaks,
                    col = "white",
                    skip = 1) +
  scale_fill_viridis_d(name = "Gamma",
                       direction = -1) +
  scale_y_reverse() +
  coord_cartesian(expand = 0) +
  guides(fill = guide_colorsteps(barheight = unit(10, "cm"))) +
  facet_grid(basin ~ .)

rm(WOA18_predictors_zonal, slab_breaks)

2.2 WOA18 + GLODAP

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

predictors <- full_join(
  GLODAP_predictors %>% select(-c(sal,tem)),
  WOA18_predictors)

predictors <- predictors %>% 
  drop_na()

# rm(GLODAP_predictors, WOA18_predictors)

2.2.1 Control plots

2.2.1.1 Maps

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

map_climatology(predictors, "PO4")

map_climatology(predictors, "tem")

predictors %>%
  ggplot(aes(lon, lat)) +
  geom_bin2d(binwidth = c(1,1)) +
  scale_fill_viridis_c(direction = -1) +
  coord_quickmap(expand = 0) +
  theme(legend.position = "bottom")

2.2.1.2 Predictor profiles

Likewise, predictor profiles for the North Atlantic 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(-basin) %>% 
  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)

2.2.1.3 Neutral density zonal mean section

predictors_zonal <- predictors %>%
  group_by(lat, depth, basin) %>%
  summarise(gamma_mean = mean(gamma)) %>%
  ungroup()

predictors_zonal_Atl <- predictors_zonal %>%
  filter(basin == "Atlantic") %>%
  mutate(gamma_slab = cut(gamma_mean, parameters$slabs_Atl))

predictors_zonal_Ind_Pac <- predictors_zonal %>%
  filter(basin == "Indo-Pacific") %>%
  mutate(gamma_slab = cut(gamma_mean, parameters$slabs_Ind_Pac))

predictors_zonal <- bind_rows(predictors_zonal_Atl, predictors_zonal_Ind_Pac)

rm(predictors_zonal_Atl, predictors_zonal_Ind_Pac)

slab_breaks <- c(parameters$slabs_Atl[1:12], Inf)

predictors_zonal %>%
  filter(depth <= parameters$inventory_depth) %>%
  ggplot(aes(lat, depth, z = gamma_mean)) +
  geom_contour_filled(breaks = slab_breaks) +
  geom_contour(breaks = slab_breaks,
               col = "white") +
  geom_text_contour(breaks = slab_breaks,
                    col = "white",
                    skip = 1) +
  scale_fill_viridis_d(name = "Gamma",
                       direction = -1) +
  scale_y_reverse() +
  coord_cartesian(expand = 0) +
  guides(fill = guide_colorsteps(barheight = unit(10, "cm"))) +
  facet_grid(basin ~ .)

rm(predictors_zonal, slab_breaks)

3 Prepare predictor fields

3.1 PO4*

3.1.1 Calculation

Currently, the predictor PO4* is calculated according to Clement and Gruber (2018), ie based on oxygen rather than nitrate.

predictors <- predictors %>% 
  rename(phosphate = PO4) %>% 
  mutate(phosphate_star_oxy = phosphate + (oxygen / 170)  - 1.95,
         phosphate_star_nit = phosphate - NO3 / 16  + 2.9)

3.1.2 Maps

map_climatology(predictors, "phosphate_star_nit")

map_climatology(predictors, "phosphate_star_oxy")

3.1.3 Sections

section_climatology(predictors, "phosphate_star_nit")

section_climatology(predictors, "phosphate_star_oxy")

3.2 AOU

3.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(oxygen_sat = gas_satconc(S = sal,
                                  t = tem,
                                  P = 1.013253,
                                  species = "O2"),
         aou = oxygen_sat - oxygen) %>% 
  select(-oxygen_sat)

3.2.2 Maps

map_climatology(predictors, "aou")

3.2.3 Sections

section_climatology(predictors, "aou")

3.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_Atl <- predictors %>% 
  filter(basin == "Atlantic") %>% 
  mutate(gamma_slab = cut(gamma, parameters$slabs_Atl))

predictors_Ind_Pac <- predictors %>% 
  filter(basin == "Indo-Pacific") %>% 
  mutate(gamma_slab = cut(gamma, parameters$slabs_Ind_Pac))

predictors <- bind_rows(predictors_Atl, predictors_Ind_Pac)

rm(predictors_Atl, predictors_Ind_Pac)

4 Write csv

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

4.1 WOA13 + GLODAP

Currently not used.

predictors <- full_join(GLODAP_predictors, WOA13_gamma)
GLODAP_depths <- unique(GLODAP_predictors$depth)

rm(GLODAP_predictors, WOA13_gamma)

predictors <- predictors %>% 
  group_by(lat, lon) %>% 
  mutate(n_oxygen = sum(!is.na(oxygen)),
         n_PO4 = sum(!is.na(PO4)),
         n_silicate = sum(!is.na(silicate)),
         n_sal = sum(!is.na(sal)),
         n_tem = sum(!is.na(tem)),
         n_gamma = sum(!is.na(gamma))) %>% 
  ungroup()

predictors <- predictors %>% 
  filter(n_oxygen > 0,
         n_PO4 > 0,
         n_silicate > 0, 
         n_sal > 0, 
         n_tem > 0, 
         n_gamma > 0) %>% 
  select(-c(n_oxygen, 
            n_PO4, 
            n_silicate, 
            n_sal, 
            n_tem,
            n_gamma))

predictors <- predictors %>% 
  drop_na()

5 Open tasks

  • Check PO4* calculation
  • Harmonize AOU calculation in fitting and mapping

6 Open questions


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] marelac_2.1.10  shape_1.4.4     metR_0.7.0      forcats_0.5.0  
 [5] stringr_1.4.0   dplyr_1.0.0     purrr_0.3.4     readr_1.3.1    
 [9] tidyr_1.1.0     tibble_3.0.3    ggplot2_3.3.2   tidyverse_1.3.0
[13] workflowr_1.6.2

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