Last updated: 2020-09-04
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 6a302ca. 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/
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_cant_calculation.Rmd
) and HTML (docs/mapping_cant_calculation.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 | 6a302ca | jens-daniel-mueller | 2020-09-04 | rebuild after new data cleaning and mapping Cant to surface |
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. |
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 | b6d0e6a | jens-daniel-mueller | 2020-08-27 | Build site. |
html | f40e48b | jens-daniel-mueller | 2020-08-26 | Build site. |
Rmd | b577ec6 | jens-daniel-mueller | 2020-08-26 | Analysis split in this and previous studies |
html | 882b358 | jens-daniel-mueller | 2020-08-26 | Build site. |
Rmd | db9fb4b | jens-daniel-mueller | 2020-08-26 | Cant mean zonal sections separate for Indian and Pacific |
Rmd | ccacd26 | jens-daniel-mueller | 2020-08-25 | updated with PO4* oxygen based |
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(lubridate)
# library(oce)
# library(marelac)
# 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"))
Currently, we use combined predictor fields:
predictors <-
read_csv(here::here("data/mapping/predictor_fields",
"W18_st_G16_opsn.csv"))
Only predictors were taken into consideration with:
The minimum sampling depth of 150m was only taken into account when gamma is >= 26.
predictors <- predictors %>%
filter(depth >= parameters$depth_min | gamma >= 26)
predictors <- predictors %>%
filter(lat <= parameters$lat_max)
predictors_grid <- predictors %>%
group_by(lat, lon) %>%
summarise(bottomdepth = max(depth)) %>%
ungroup()
predictors <- full_join(predictors, predictors_grid)
predictors <- predictors %>%
filter(bottomdepth >= parameters$bottomdepth_min) %>%
select(-bottomdepth)
predictors <- predictors %>% drop_na()
all_lm_wide <-
read_csv(here::here("data/eMLR",
"all_lm_wide.csv"))
all_lm_wide <- all_lm_wide %>%
mutate(model = str_remove(model, "Cstar ~ "))
Cant <- full_join(predictors, all_lm_wide)
#rm(predictors, all_lm_wide)
Cant <- Cant %>%
mutate(Cant = `delta_coeff_(Intercept)` +
delta_coeff_aou * aou +
delta_coeff_oxygen * oxygen +
delta_coeff_phosphate * phosphate +
delta_coeff_phosphate_star * phosphate_star +
delta_coeff_silicate * silicate +
delta_coeff_sal * sal +
delta_coeff_tem * tem)
Mean and sd are calculated for Cant in each grid cell (XYZ), basin and era combination. Calculations are performed for all Cant values vs positive values only. This averaging step summarizes the information derived from ten best fitting MLRs.
Cant <- Cant %>%
select(lon, lat, depth, eras, basin, Cant, gamma, model)
# Cant_average <- Cant %>%
# mutate(Cant_pos = if_else(Cant < 0, 0, Cant)) %>%
# group_by(lon, lat, depth, eras, basin) %>%
# summarise(across(c("Cant", "Cant_pos", "gamma"),
# list(
# mean = ~ mean(.x, na.rm = TRUE),
# sd = ~ sd(.x, na.rm = TRUE)
# ))) %>%
# ungroup()
Cant_average <- Cant %>%
mutate(Cant_pos = if_else(Cant < 0, 0, Cant)) %>%
group_by(lon, lat, depth, eras, basin) %>%
summarise(Cant_mean = mean(Cant, na.rm = TRUE),
Cant_sd = sd(Cant, na.rm = TRUE),
Cant_pos_mean = mean(Cant_pos, na.rm = TRUE),
Cant_pos_sd = sd(Cant_pos, na.rm = TRUE),
gamma_mean = mean(gamma, na.rm = TRUE),
gamma_sd = sd(gamma, na.rm = TRUE)) %>%
ungroup()
Cant_average_Atl <- Cant_average %>%
filter(basin == "Atlantic") %>%
mutate(gamma_slab = cut(gamma_mean, parameters$slabs_Atl))
Cant_average_Ind_Pac <- Cant_average %>%
filter(basin == "Indo-Pacific") %>%
mutate(gamma_slab = cut(gamma_mean, parameters$slabs_Ind_Pac))
Cant_average <- bind_rows(Cant_average_Atl, Cant_average_Ind_Pac)
rm(Cant_average_Atl, Cant_average_Ind_Pac)
For each basin and era combination, the zonal mean Cant is calculated, again for all vs positive only values. Likewise, sd is calculated for the averaging of the mean basin fields.
Cant_average <- full_join(Cant_average,
basinmask %>% select(-basin))
Cant_average_zonal <- Cant_average %>%
group_by(lat, depth, eras, basin, basin_AIP) %>%
summarise(across(
c(
"Cant_mean",
"Cant_pos_mean",
"Cant_sd",
"Cant_pos_sd",
"gamma_mean",
"gamma_sd"
),
list(mean = ~ mean(.x, na.rm = TRUE),
sd = ~ sd(.x, na.rm = TRUE))
)) %>%
ungroup()
# Cant_average_zonal <- Cant_average %>%
# group_by(lat, depth, eras, basin) %>%
# summarise(Cant_mean_sd = sd(Cant_mean, na.rm = TRUE),
# Cant_mean = mean(Cant_mean, na.rm = TRUE),
# Cant_sd_mean = mean(Cant_sd, na.rm = TRUE),
# Cant_pos_mean_sd = sd(Cant_pos_mean, na.rm = TRUE),
# Cant_pos_mean = mean(Cant_pos_mean, na.rm = TRUE),
# Cant_pos_sd_mean = mean(Cant_pos_sd, na.rm = TRUE),
# gamma_mean = mean(gamma_mean)) %>%
# ungroup()
Cant_average_zonal_Atl <- Cant_average_zonal %>%
filter(basin == "Atlantic") %>%
mutate(gamma_slab = cut(gamma_mean_mean, parameters$slabs_Atl))
Cant_average_zonal_Ind_Pac <- Cant_average_zonal %>%
filter(basin == "Indo-Pacific") %>%
mutate(gamma_slab = cut(gamma_mean_mean, parameters$slabs_Ind_Pac))
Cant_average_zonal <- bind_rows(Cant_average_zonal_Atl, Cant_average_zonal_Ind_Pac)
rm(Cant_average_zonal_Atl, Cant_average_zonal_Ind_Pac)
To calculate Cant column inventories, we:
Step 2 is performed again for all Cant and positive Cant values only
depth_level_volume <- tibble(depth = unique(Cant_average$depth))
depth_level_volume <- depth_level_volume %>%
mutate(
layer_thickness_above = replace_na((depth - lag(depth)) / 2, 0),
layer_thickness_below = replace_na((lead(depth) - depth) / 2, 0),
layer_thickness = layer_thickness_above + layer_thickness_below
) %>%
select(-c(layer_thickness_above,
layer_thickness_below))
Cant_average <-
full_join(Cant_average, depth_level_volume)
Cant_average <- Cant_average %>%
mutate(layer_inv = Cant_mean * layer_thickness) %>%
mutate(layer_inv_pos = if_else(layer_inv < 0, 0, layer_inv)) %>%
select(-layer_thickness)
Cant_inv <- Cant_average %>%
filter(depth <= parameters$inventory_depth) %>%
group_by(lon, lat, basin, eras) %>%
summarise(
cant_inv_pos = sum(layer_inv_pos, na.rm = TRUE) / 1000,
cant_inv = sum(layer_inv, na.rm = TRUE) / 1000
) %>%
ungroup()
Cant %>%
write_csv(here::here("data/mapping/_summarized_files",
"Cant.csv"))
Cant_average %>%
write_csv(here::here("data/mapping/_summarized_files",
"Cant_average.csv"))
Cant_average_zonal %>%
write_csv(here::here("data/mapping/_summarized_files",
"Cant_average_zonal.csv"))
Cant_inv %>%
write_csv(here::here("data/mapping/_summarized_files",
"Cant_inv.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] metR_0.7.0 forcats_0.5.0 stringr_1.4.0 dplyr_1.0.0
[5] purrr_0.3.4 readr_1.3.1 tidyr_1.1.0 tibble_3.0.3
[9] ggplot2_3.3.2 tidyverse_1.3.0 workflowr_1.6.2
loaded via a namespace (and not attached):
[1] tidyselect_1.1.0 xfun_0.16 haven_2.3.1 colorspace_1.4-1
[5] vctrs_0.3.2 generics_0.0.2 htmltools_0.5.0 yaml_2.2.1
[9] blob_1.2.1 rlang_0.4.7 later_1.1.0.1 pillar_1.4.6
[13] withr_2.2.0 glue_1.4.1 DBI_1.1.0 dbplyr_1.4.4
[17] modelr_0.1.8 readxl_1.3.1 lifecycle_0.2.0 munsell_0.5.0
[21] gtable_0.3.0 cellranger_1.1.0 rvest_0.3.6 evaluate_0.14
[25] knitr_1.29 httpuv_1.5.4 fansi_0.4.1 broom_0.7.0
[29] Rcpp_1.0.5 checkmate_2.0.0 promises_1.1.1 backports_1.1.8
[33] scales_1.1.1 jsonlite_1.7.0 fs_1.4.2 hms_0.5.3
[37] digest_0.6.25 stringi_1.4.6 rprojroot_1.3-2 grid_4.0.2
[41] here_0.1 cli_2.0.2 tools_4.0.2 magrittr_1.5
[45] crayon_1.3.4 whisker_0.4 pkgconfig_2.0.3 ellipsis_0.3.1
[49] data.table_1.13.0 xml2_1.3.2 reprex_0.3.0 lubridate_1.7.9
[53] assertthat_0.2.1 rmarkdown_2.3 httr_1.4.2 rstudioapi_0.11
[57] R6_2.4.1 git2r_0.27.1 compiler_4.0.2