Last updated: 2020-11-10
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 8e21e4d. 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/
Untracked files:
Untracked: code/globe_3d.R
Untracked: code/mapping_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/eMLR_data_preparation.Rmd
) and HTML (docs/eMLR_data_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 | 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. |
html | 1f3319a | jens-daniel-mueller | 2020-09-16 | Build site. |
Rmd | ae561aa | jens-daniel-mueller | 2020-09-16 | rebuild all after merging in surface estimates |
html | ebadd96 | jens-daniel-mueller | 2020-09-16 | Build site. |
Rmd | 1835aca | jens-daniel-mueller | 2020-09-16 | Cant surface water calculated |
html | da91d98 | jens-daniel-mueller | 2020-09-10 | Build site. |
html | a34a239 | jens-daniel-mueller | 2020-09-10 | Build site. |
Rmd | 143fbd7 | jens-daniel-mueller | 2020-09-10 | global section plot added |
html | c3ffdfd | jens-daniel-mueller | 2020-09-08 | Build site. |
html | 5ccd96a | jens-daniel-mueller | 2020-09-08 | Build site. |
Rmd | dd12155 | jens-daniel-mueller | 2020-09-08 | cleaned and Cstar naming corrected |
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. |
Rmd | da4907d | jens-daniel-mueller | 2020-09-02 | all flagged variables |
html | 429aab3 | jens-daniel-mueller | 2020-09-01 | Build site. |
Rmd | b7a8f92 | jens-daniel-mueller | 2020-09-01 | fitted MLR models with oxygen based PO4* |
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 | b610bf7 | jens-daniel-mueller | 2020-08-27 | Build site. |
Rmd | 96ab537 | jens-daniel-mueller | 2020-08-27 | revised |
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 |
html | 0772e79 | jens-daniel-mueller | 2020-08-21 | Build site. |
Rmd | e04b03d | jens-daniel-mueller | 2020-08-21 | Individual cruise plots with all relevant parameters and histograms in eMLR |
html | 5ffe187 | jens-daniel-mueller | 2020-08-20 | Build site. |
html | 1064ef8 | jens-daniel-mueller | 2020-08-19 | Build site. |
Rmd | 94f9375 | jens-daniel-mueller | 2020-08-19 | split emlr into data preparation, assumption testing, and model fitting |
html | 828f44e | jens-daniel-mueller | 2020-08-19 | Build site. |
Rmd | 77b2dc1 | jens-daniel-mueller | 2020-08-19 | split emlr into data preparation, assumption testing, and model fitting |
library(tidyverse)
library(lubridate)
library(patchwork)
library(marelac)
Required are:
GLODAP <-
read_csv(
here::here(
"data/GLODAPv2_2020/_summarized_data_files",
"GLODAPv2.2020_clean.csv"
)
)
GLODAP_obs_grid <-
read_csv(
here::here(
"data/GLODAPv2_2020/_summarized_data_files",
"GLODAPv2.2020_clean_obs_grid.csv"
)
)
Cant_clim <-
read_csv(
here::here(
"data/GLODAPv2_2016b_MappedClimatologies/_summarized_files",
"Cant.csv"
)
)
co2_atm <-
read_csv(here::here(
"data/pCO2_atmosphere/_summarized_data_files",
"co2_atm.csv"
))
Cant_clim <- Cant_clim %>%
rename(cant = Cant)
C* serves as a conservative tracer of anthropogenic CO2 uptake. It is derived from measured DIC by removing the impact of
Contributions of those processes are estimated from phosphate and alkalinity concentrations.
rCP <- 117
rNP <- 16
The stoichiometric nutrient ratios for the production and mineralization of organic matter were set to:
C* is calculated as:
print("Cstar = tco2 + rCP_phosphate + talk_05 + rNP_phosphate_05")
[1] "Cstar = tco2 + rCP_phosphate + talk_05 + rNP_phosphate_05"
GLODAP <- GLODAP %>%
mutate(rCP_phosphate = -rCP * phosphate,
talk_05 = -0.5 * talk,
rNP_phosphate_05 = -0.5 * rNP * phosphate,
Cstar = tco2 + rCP_phosphate + talk_05 + rNP_phosphate_05)
rm(rCP, rNP)
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.
GLODAP <- GLODAP %>%
mutate(phosphate_star = phosphate + (oxygen / 170) - 1.95)
The reference year adjustment relies on an apriori estimate of Cant at a given location and depth, which is used as a scaling factor for the concurrent change in atmospheric CO2. The underlying assumption is a transient steady state for the oceanic Cant uptake. Here, Cant from the GLODAP mapped Climatology was used.
Note that eq. 6 in Clement and Gruber (2018) misses pCO2 pre-industrial in the denominator. Here we use the equation published in Gruber et al. (2019).
Cant_clim_obs <- left_join(GLODAP_obs_grid, Cant_clim)
Cant_clim_obs <- Cant_clim_obs %>%
group_by(lon, lat) %>%
mutate(n = n()) %>%
ungroup()
# Cant_clim_obs %>%
# filter(n <= 1) %>%
# ggplot(aes(lon,lat)) +
# geom_point(data = GLODAP_obs_grid, aes(lon, lat)) +
# geom_point(col = "red")
rm(Cant_clim, GLODAP_obs_grid)
GLODAP_Cant_obs <- full_join(GLODAP, Cant_clim_obs)
rm(GLODAP, Cant_clim_obs)
GLODAP_Cant_obs <- GLODAP_Cant_obs %>%
group_by(lon, lat) %>%
mutate(n = mean(n, na.rm = TRUE)) %>%
ungroup()
The mapped Cant product was merged with GLODAP observation by:
# GLODAP_Cant_obs <- full_join(GLODAP_Cant_obs, Cant_clim_obs_nr)
GLODAP_Cant_obs <- GLODAP_Cant_obs %>%
filter(n > 1) %>%
group_by(lat, lon) %>%
arrange(depth) %>%
mutate(cant_int = approxfun(depth, cant, rule = 2)(depth)) %>%
ungroup()
# GLODAP_Cant_obs_set <- GLODAP_Cant_obs %>%
# filter(n_cant == 1) %>%
# group_by(lat, lon) %>%
# arrange(depth) %>%
# mutate(cant_int = mean(cant, na.rm = TRUE)) %>%
# ungroup()
ggplot() +
geom_path(
data = GLODAP_Cant_obs %>%
filter(lat == 48.5, lon == 165.5,!is.na(cant)) %>%
arrange(depth),
aes(cant, depth, col = "mapped")
) +
geom_point(
data = GLODAP_Cant_obs %>%
filter(lat == 48.5, lon == 165.5,!is.na(cant)) %>%
arrange(depth),
aes(cant, depth, col = "mapped")
) +
geom_point(
data = GLODAP_Cant_obs %>%
filter(lat == 48.5, lon == 165.5, date == ymd("2018-06-27")),
aes(cant_int, depth, col = "interpolated")
) +
scale_y_reverse() +
scale_color_brewer(palette = "Dark2", name = "") +
labs(title = "Cant interpolation to sampling depth - example profile")
# remove cant data at grid cells without observations
GLODAP <- GLODAP_Cant_obs %>%
filter(!is.na(Cstar)) %>%
mutate(cant = cant_int) %>%
select(-cant_int, n)
rm(GLODAP_Cant_obs)
GLODAP observations were merged with mean annual atmospheric pCO2 levels by year.
GLODAP <- left_join(GLODAP, co2_atm)
GLODAP <- GLODAP %>%
group_by(era) %>%
mutate(tref = median(year)) %>%
ungroup()
tref <- GLODAP %>%
group_by(era) %>%
summarise(year = median(year)) %>%
ungroup()
co2_atm_tref <- right_join(co2_atm, tref) %>%
select(-year) %>%
rename(pCO2_tref = pCO2)
GLODAP <- full_join(GLODAP, co2_atm_tref)
rm(co2_atm, tref)
GLODAP <- GLODAP %>%
mutate(Cstar_tref_delta =
((pCO2 - pCO2_tref) / (pCO2_tref - 280)) * cant,
Cstar_tref = Cstar - Cstar_tref_delta)
GLODAP %>%
ggplot(aes(Cstar_tref_delta)) +
geom_histogram()
GLODAP %>%
sample_n(1e4) %>%
ggplot(aes(year, Cstar_tref_delta, col = cant)) +
geom_point() +
scale_color_viridis_c() +
labs(title = "random subsample 1e4")
A selected section is plotted to demonstrate the magnitude of various parameters and corrections relevant to C*.
GLODAP_cruise <- GLODAP %>%
filter(cruise %in% parameters$cruises_meridional)
GLODAP_cruise %>%
arrange(date) %>%
ggplot(aes(lon, lat)) +
geom_raster(data = landmask,
aes(lon, lat), fill = "grey80") +
geom_path() +
geom_point(aes(col = date)) +
coord_quickmap(expand = 0) +
scale_color_viridis_c(trans = "date") +
labs(title = paste("Cruise year:", mean(GLODAP_cruise$year))) +
theme(axis.title = element_blank())
lat_section <-
GLODAP_cruise %>%
ggplot(aes(lat, depth)) +
scale_y_reverse() +
scale_color_viridis_c() +
theme(axis.title.x = element_blank())
lat_section +
geom_point(aes(col = tco2))
lat_section +
geom_point(aes(col = rCP_phosphate))
lat_section +
geom_point(aes(col = talk_05))
lat_section +
geom_point(aes(col = rNP_phosphate_05))
lat_section +
geom_point(aes(col = Cstar))
lat_section +
geom_point(aes(col = -Cstar_tref_delta))
rm(lat_section, GLODAP_cruise)
GLODAP <- GLODAP %>%
select(-c(rCP_phosphate:Cstar, cant:Cstar_tref_delta))
The following boundaries for isoneutral slabs were defined:
Continuous neutral densities (gamma) values from GLODAP are grouped into isoneutral slabs.
GLODAP_Atl <- GLODAP %>%
filter(basin == "Atlantic") %>%
mutate(gamma_slab = cut(gamma, parameters$slabs_Atl))
GLODAP_Ind_Pac <- GLODAP %>%
filter(basin == "Indo-Pacific") %>%
mutate(gamma_slab = cut(gamma, parameters$slabs_Ind_Pac))
GLODAP <- bind_rows(GLODAP_Atl, GLODAP_Ind_Pac)
rm(GLODAP_Atl, GLODAP_Ind_Pac)
GLODAP_cruise <- GLODAP %>%
filter(cruise %in% parameters$cruises_meridional)
lat_section <-
GLODAP_cruise %>%
ggplot(aes(lat, depth)) +
scale_y_reverse() +
theme(legend.position = "bottom")
lat_section +
geom_point(aes(col = gamma_slab)) +
scale_color_viridis_d()
rm(lat_section, GLODAP_cruise)
GLODAP_cruise <- GLODAP %>%
filter(cruise %in% parameters$cruises_meridional)
library(oce)
library(gsw)
# calculate pressure from depth
GLODAP_cruise <- GLODAP_cruise %>%
mutate(CTDPRS = gsw_p_from_z(-depth,
lat))
GLODAP_cruise <- GLODAP_cruise %>%
mutate(THETA = swTheta(salinity = sal,
temperature = tem,
pressure = CTDPRS,
referencePressure = 0,
longitude = lon-180,
latitude = lat))
GLODAP_cruise <- GLODAP_cruise %>%
rename(LATITUDE = lat,
LONGITUDE = lon,
SALNTY = sal,
gamma_provided = gamma)
library(reticulate)
source_python(here::here("code/python_scripts",
"Gamma_GLODAP_python.py"))
GLODAP_cruise <- calculate_gamma(GLODAP_cruise)
GLODAP_cruise <- GLODAP_cruise %>%
mutate(gamma_delta = gamma_provided - GAMMA)
lat_section <-
GLODAP_cruise %>%
ggplot(aes(LATITUDE, CTDPRS)) +
scale_y_reverse() +
theme(legend.position = "bottom")
lat_section +
geom_point(aes(col = gamma_delta)) +
scale_color_viridis_c()
GLODAP_cruise %>%
ggplot(aes(gamma_delta))+
geom_histogram()
rm(lat_section, GLODAP_cruise, cruises_meridional)
GLODAP <- GLODAP %>%
mutate(era = factor(era, c("JGOFS_WOCE", "GO_SHIP", "new_era"))) %>%
mutate(gamma_slab = factor(gamma_slab),
gamma_slab = factor(gamma_slab, levels = rev(levels(gamma_slab))))
GLODAP %>%
filter(basin == "Atlantic") %>%
ggplot(aes(lat, gamma_slab)) +
geom_bin2d(binwidth = 5) +
scale_fill_viridis_c(option = "magma", direction = -1, trans = "log10") +
scale_x_continuous(breaks = seq(-100,100,20)) +
facet_grid(era~basin)
GLODAP %>%
filter(basin == "Indo-Pacific") %>%
ggplot(aes(lat, gamma_slab)) +
geom_bin2d(binwidth = 5) +
scale_fill_viridis_c(option = "magma", direction = -1, trans = "log10") +
scale_x_continuous(breaks = seq(-100,100,20)) +
facet_grid(era~basin)
Zonal and meridional section plots are produce for each cruise individually and can be downloaded here.
cruises <- GLODAP %>%
group_by(cruise) %>%
summarise(date_mean = mean(date, na.rm = TRUE),
n = n()) %>%
ungroup() %>%
arrange(date_mean)
GLODAP <- full_join(GLODAP, cruises)
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(lon, lat)) +
geom_raster(data = landmask,
aes(lon, lat), fill = "grey80") +
geom_point(aes(col=date)) +
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(lon, 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))
lon_oxygen <- lon_section+
geom_point(aes(col=oxygen))
lon_aou <- lon_section+
geom_point(aes(col=aou))
lon_phosphate_star <- lon_section+
geom_point(aes(col=phosphate_star))
lon_nitrate <- lon_section+
geom_point(aes(col=nitrate))
lon_Cstar <- lon_section+
geom_point(aes(col=Cstar))
lat_section <- GLODAP_cruise %>%
ggplot(aes(lat, 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))
lat_oxygen <- lat_section+
geom_point(aes(col=oxygen))
lat_aou <- lat_section+
geom_point(aes(col=aou))
lat_phosphate_star <- lat_section+
geom_point(aes(col=phosphate_star))
lat_nitrate <- lat_section+
geom_point(aes(col=nitrate))
lat_Cstar <- lat_section+
geom_point(aes(col=Cstar))
hist_tco2 <- GLODAP_cruise %>%
ggplot(aes(tco2)) +
geom_histogram()
hist_talk <- GLODAP_cruise %>%
ggplot(aes(talk)) +
geom_histogram()
hist_phosphate <- GLODAP_cruise %>%
ggplot(aes(phosphate)) +
geom_histogram()
hist_oxygen <- GLODAP_cruise %>%
ggplot(aes(oxygen)) +
geom_histogram()
hist_aou <- GLODAP_cruise %>%
ggplot(aes(aou)) +
geom_histogram()
hist_phosphate_star <- GLODAP_cruise %>%
ggplot(aes(phosphate_star)) +
geom_histogram()
hist_nitrate <- GLODAP_cruise %>%
ggplot(aes(nitrate)) +
geom_histogram()
hist_Cstar <- GLODAP_cruise %>%
ggplot(aes(Cstar)) +
geom_histogram()
(map /
((hist_tco2 / hist_talk / hist_phosphate / hist_Cstar) |
(hist_oxygen / hist_phosphate_star / hist_nitrate / hist_aou)
)) |
((lat_tco2 / lat_talk / lat_phosphate / lat_oxygen / lat_aou / lat_phosphate_star / lat_nitrate / lat_Cstar) |
(lon_tco2 / lon_talk / lon_phosphate / lon_oxygen / lon_aou /lon_phosphate_star / lon_nitrate / lon_Cstar))
ggsave(here::here("output/figure/eMLR/data_preparation/all_cruises_clean",
paste("GLODAP_cruise_date",
cruises_cruise$date_mean,
"n",
cruises_cruise$n,
"cruise",
cruises_cruise$cruise,
".png",
sep = "_")),
width = 20, height = 12)
rm(map,
lon_section, lat_section,
lat_tco2, lat_talk, lat_phosphate, lon_tco2, lon_talk, lon_phosphate,
GLODAP_cruise, cruises_cruise)
}
GLODAP <- GLODAP %>%
rename(Cstar = Cstar_tref)
GLODAP %>% write_csv(here::here("data/GLODAPv2_2020/_summarized_data_files",
"GLODAP_MLR_fitting_ready.csv"))
co2_atm_tref %>%
write_csv(here::here(
"data/pCO2_atmosphere/_summarized_data_files",
"co2_atm_tref.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] marelac_2.1.10 shape_1.4.4 patchwork_1.0.1 lubridate_1.7.9
[5] forcats_0.5.0 stringr_1.4.0 dplyr_1.0.0 purrr_0.3.4
[9] readr_1.3.1 tidyr_1.1.0 tibble_3.0.3 ggplot2_3.3.2
[13] tidyverse_1.3.0 workflowr_1.6.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 here_0.1 assertthat_0.2.1 rprojroot_1.3-2
[5] digest_0.6.25 R6_2.4.1 cellranger_1.1.0 backports_1.1.8
[9] reprex_0.3.0 evaluate_0.14 httr_1.4.2 pillar_1.4.6
[13] rlang_0.4.7 readxl_1.3.1 rstudioapi_0.11 whisker_0.4
[17] blob_1.2.1 rmarkdown_2.3 labeling_0.3 munsell_0.5.0
[21] broom_0.7.0 compiler_4.0.2 httpuv_1.5.4 modelr_0.1.8
[25] xfun_0.16 pkgconfig_2.0.3 htmltools_0.5.0 tidyselect_1.1.0
[29] viridisLite_0.3.0 fansi_0.4.1 crayon_1.3.4 dbplyr_1.4.4
[33] withr_2.2.0 later_1.1.0.1 gsw_1.0-5 grid_4.0.2
[37] jsonlite_1.7.0 gtable_0.3.0 lifecycle_0.2.0 DBI_1.1.0
[41] git2r_0.27.1 magrittr_1.5 seacarb_3.2.13 scales_1.1.1
[45] cli_2.0.2 stringi_1.4.6 oce_1.2-0 farver_2.0.3
[49] fs_1.4.2 promises_1.1.1 testthat_2.3.2 xml2_1.3.2
[53] ellipsis_0.3.1 generics_0.0.2 vctrs_0.3.2 RColorBrewer_1.1-2
[57] tools_4.0.2 glue_1.4.1 hms_0.5.3 yaml_2.2.1
[61] colorspace_1.4-1 rvest_0.3.6 knitr_1.30 haven_2.3.1