Last updated: 2020-09-14
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 1a13af4. 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 | 1a13af4 | jens-daniel-mueller | 2020-09-14 | replace all model sections plots chunk |
html | da91d98 | jens-daniel-mueller | 2020-09-10 | Build site. |
html | a34a239 | jens-daniel-mueller | 2020-09-10 | Build site. |
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 | 148db18 | jens-daniel-mueller | 2020-09-07 | Build site. |
Rmd | 0bea059 | jens-daniel-mueller | 2020-09-07 | plotted predictor contribution zonal mean |
html | a50f053 | jens-daniel-mueller | 2020-09-07 | Build site. |
html | da445a6 | jens-daniel-mueller | 2020-09-04 | Build site. |
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)
basinmask <-
read_csv(
here::here(
"data/World_Ocean_Atlas_2018/_summarized_files",
"basin_mask_WOA18.csv"
)
)
basinmask_AIP <-
read_csv(
here::here(
"data/World_Ocean_Atlas_2018/_summarized_files",
"basin_mask_WOA18_AIP.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"))
lm_all_wide <-
read_csv(here::here("data/eMLR",
"lm_all_wide.csv"))
lm_all_wide <- lm_all_wide %>%
mutate(model = str_remove(model, "Cstar ~ "))
Cant <- full_join(predictors, lm_all_wide)
rm(predictors, lm_all_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)
Cant <- Cant %>%
mutate(Cant_intercept = `delta_coeff_(Intercept)`,
Cant_aou = delta_coeff_aou * aou,
Cant_oxygen = delta_coeff_oxygen * oxygen,
Cant_phosphate = delta_coeff_phosphate * phosphate,
Cant_phosphate_star = delta_coeff_phosphate_star * phosphate_star,
Cant_silicate = delta_coeff_silicate * silicate,
Cant_sal = delta_coeff_sal * sal,
Cant_tem = delta_coeff_tem * tem,
Cant_sum = Cant_intercept +
Cant_aou +
Cant_oxygen +
Cant_phosphate +
Cant_phosphate_star +
Cant_silicate +
Cant_sal +
Cant_tem)
Zonal sections plots are produced for every 20° longitude, each era and for all models individually and can be downloaded here.
library(scales)
for (i_eras in unique(Cant$eras)) {
# i_eras <- unique(Cant$eras)[2]
Cant_eras <- Cant %>%
filter(eras == i_eras)
for (i_lon in seq(20.5, 360, 20)) {
# i_lon <- seq(20.5, 360, 20)[7]
Cant_eras_lon <- Cant_eras %>%
filter(lon == i_lon)
Cant_eras_lon %>%
ggplot(aes(lat, depth, col = Cant)) +
geom_point() +
scale_color_gradient2(
name = "Cant",
high = muted("red"),
mid = "grey",
low = muted("blue")
) +
scale_y_reverse(limits = c(parameters$inventory_depth, NA)) +
scale_x_continuous(limits = c(-75, 65)) +
coord_cartesian(expand = 0) +
guides(fill = guide_colorsteps(barheight = unit(10, "cm"))) +
labs(title = paste("eras:", i_eras, "| lon:", i_lon)) +
facet_wrap( ~ model, ncol = 5)
ggsave(
here::here(
"output/figure/mapping",
paste(i_eras,
"lon",
i_lon,
"model_Cant.png",
sep = "_")
),
width = 17,
height = 9
)
}
}
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_predictor_average <- Cant %>%
mutate(Cant_pos = if_else(Cant < 0, 0, Cant)) %>%
group_by(lon, lat, depth, eras, basin) %>%
summarise(Cant_intercept = mean(Cant_intercept, na.rm = TRUE),
Cant_aou = mean(Cant_aou, na.rm = TRUE),
Cant_oxygen = mean(Cant_oxygen, na.rm = TRUE),
Cant_phosphate = mean(Cant_phosphate, na.rm = TRUE),
Cant_phosphate_star = mean(Cant_phosphate_star, na.rm = TRUE),
Cant_silicate = mean(Cant_silicate, na.rm = TRUE),
Cant_tem = mean(Cant_tem, na.rm = TRUE),
Cant_sal = mean(Cant_sal, na.rm = TRUE),
Cant_sum = mean(Cant_sum, na.rm = TRUE),
gamma_mean = mean(gamma, na.rm = TRUE)
) %>%
ungroup()
Cant_predictor_average_Atl <- Cant_predictor_average %>%
filter(basin == "Atlantic") %>%
mutate(gamma_slab = cut(gamma_mean, parameters$slabs_Atl))
Cant_predictor_average_Ind_Pac <- Cant_predictor_average %>%
filter(basin == "Indo-Pacific") %>%
mutate(gamma_slab = cut(gamma_mean, parameters$slabs_Ind_Pac))
Cant_predictor_average <- bind_rows(Cant_predictor_average_Atl, Cant_predictor_average_Ind_Pac)
rm(Cant_predictor_average_Atl, Cant_predictor_average_Ind_Pac)
# 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(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 <- left_join(Cant_average,
basinmask_AIP %>% 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)
For each basin and era combination, the zonal mean Cant is calculated by model coefficient.
Cant_predictor_average <- full_join(Cant_predictor_average,
basinmask_AIP %>% select(-basin))
Cant_predictor_average_zonal <- Cant_predictor_average %>%
group_by(lat, depth, eras, basin, basin_AIP) %>%
summarise(across(
Cant_intercept:gamma_mean,
list(mean = ~ mean(.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_predictor_average_zonal_Atl <- Cant_predictor_average_zonal %>%
filter(basin == "Atlantic") %>%
mutate(gamma_slab = cut(gamma_mean_mean, parameters$slabs_Atl))
Cant_predictor_average_zonal_Ind_Pac <- Cant_predictor_average_zonal %>%
filter(basin == "Indo-Pacific") %>%
mutate(gamma_slab = cut(gamma_mean_mean, parameters$slabs_Ind_Pac))
Cant_predictor_average_zonal <- bind_rows(Cant_predictor_average_zonal_Atl, Cant_predictor_average_zonal_Ind_Pac)
rm(Cant_predictor_average_zonal_Atl, Cant_predictor_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_predictor_average %>%
write_csv(here::here("data/mapping/_summarized_files",
"Cant_predictor_average.csv"))
Cant_average_zonal %>%
write_csv(here::here("data/mapping/_summarized_files",
"Cant_average_zonal.csv"))
Cant_predictor_average_zonal %>%
write_csv(here::here("data/mapping/_summarized_files",
"Cant_predictor_average_zonal.csv"))
Cant_inv %>%
write_csv(here::here("data/mapping/_summarized_files",
"Cant_inv.csv"))
rm(Cant,
Cant_average,
Cant_predictor_average,
Cant_average_zonal,
Cant_predictor_average_zonal,
Cant_inv)
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