Last updated: 2022-04-26
Checks: 7 0
Knit directory: emlr_obs_preprocessing/
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). 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 d145737. 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: .Rhistory
Ignored: .Rproj.user/
Ignored: analysis/figure/
Ignored: data/
Ignored: output/
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/read_Gruber_2019.Rmd
) and HTML (docs/read_Gruber_2019.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 | d145737 | jens-daniel-mueller | 2022-04-26 | write published, unmasked column inventories of G19 to files |
html | e949567 | jens-daniel-mueller | 2022-04-13 | Build site. |
html | aea9afe | jens-daniel-mueller | 2022-04-07 | Build site. |
Rmd | af08e38 | jens-daniel-mueller | 2022-04-07 | rerun all with lat max 65N and without arcic |
html | f088f55 | jens-daniel-mueller | 2022-04-01 | Build site. |
html | dde77eb | jens-daniel-mueller | 2022-04-01 | Build site. |
Rmd | a1ea47d | jens-daniel-mueller | 2022-04-01 | rerun all including arctic and North Atlantic biome |
html | 6e65117 | jens-daniel-mueller | 2022-02-16 | Build site. |
html | f2871b9 | jens-daniel-mueller | 2021-11-20 | Build site. |
html | 0908ee5 | jens-daniel-mueller | 2021-11-15 | Build site. |
html | 61af6e7 | jens-daniel-mueller | 2021-10-12 | Build site. |
Rmd | 730f19a | jens-daniel-mueller | 2021-10-12 | prepare G19 data for RECCAP2 |
html | 2dad8c7 | jens-daniel-mueller | 2021-10-12 | Build site. |
Rmd | 1268707 | jens-daniel-mueller | 2021-10-12 | prepare G19 data for RECCAP2 |
html | 6cef0b0 | jens-daniel-mueller | 2021-09-26 | Build site. |
Rmd | 984ccac | jens-daniel-mueller | 2021-09-26 | read all Gruber 2019 cases |
html | e49875a | jens-daniel-mueller | 2021-07-07 | Build site. |
html | 6312bd4 | jens-daniel-mueller | 2021-07-07 | Build site. |
Rmd | 4905409 | jens-daniel-mueller | 2021-07-07 | rerun with new setup_obs.Rmd file |
html | 58bc706 | jens-daniel-mueller | 2021-07-06 | Build site. |
Rmd | 0db89e1 | jens-daniel-mueller | 2021-07-06 | rerun with revised variable names |
Here, we use the standard case V101 for public and raw data sets.
The publicly available data sets contain only positive Cant estimates.
# open file
dcant <- tidync(paste(
path_gruber_2019,
"dcant_emlr_cstar_gruber_94-07_vs1.nc",
sep = ""
))
# read gamma field as tibble
dcant <- dcant %>% activate(GAMMA_DENS)
dcant_gamma <- dcant %>% hyper_tibble()
# read delta cant field
dcant <- dcant %>% activate(DCANT_01)
dcant <- dcant %>% hyper_tibble()
# join cant and gamma fields
dcant <- left_join(dcant, dcant_gamma)
# harmonize column names and coordinates
dcant <- dcant %>%
rename(lon = LONGITUDE,
lat = LATITUDE,
depth = DEPTH,
gamma = GAMMA_DENS,
dcant_pos = DCANT_01) %>%
mutate(lon = if_else(lon < 20, lon + 360, lon))
rm(dcant_gamma)
dcant_inv_publ <- tidync(paste(
path_gruber_2019,
"inv_dcant_emlr_cstar_gruber_94-07_vs1.nc",
sep = ""
))
dcant_inv_publ <- dcant_inv_publ %>% activate(DCANT_INV01)
dcant_inv_publ <- dcant_inv_publ %>% hyper_tibble()
# harmonize column names and coordinates
dcant_inv_publ <- dcant_inv_publ %>%
rename(lon = LONGITUDE,
lat = LATITUDE,
dcant_pos = DCANT_INV01) %>%
mutate(lon = if_else(lon < 20, lon + 360, lon))
dcant_inv_publ_all <- read_ncdf(
paste(
path_gruber_2019,
"inv_dcant_emlr_cstar_gruber_94-07_vs1.nc",
sep = ""
),
var = sprintf("DCANT_INV%02d", seq(1, 14, 1)),
make_units = FALSE
)
dcant_inv_publ_all <- dcant_inv_publ_all %>% as_tibble()
dcant_inv_publ_all <- dcant_inv_publ_all %>%
pivot_longer(DCANT_INV01:DCANT_INV14,
names_to = "Version_ID",
values_to = "dcant_pos",
names_prefix = "DCANT_INV")
# harmonize column names and coordinates
dcant_inv_publ_all <- dcant_inv_publ_all %>%
rename(lon = LONGITUDE,
lat = LATITUDE) %>%
mutate(lon = if_else(lon < 20, lon + 360, lon))
Internally available data sets also contain negative Cant estimates, as they are generated in the “raw” output of the eMLR mapping step.
# open v 101 file
V101 <- tidync(paste(path_gruber_2019,
"Cant_V101new.nc",
sep = ""))
# create tibble
V101 <- V101 %>% activate(Cant)
V101 <- V101 %>% hyper_tibble()
# harmonize column names and coordinates
V101 <- V101 %>%
rename(lon = longitude,
lat = latitude,
dcant = Cant) %>%
filter(dcant != -999) %>%
mutate(lon = if_else(lon < 20, lon + 360, lon))
# use only three basin to assign general basin mask
# ie this is not specific to the MLR fitting
basinmask <- basinmask %>%
filter(MLR_basins == "2") %>%
select(lat, lon, basin_AIP)
dcant <- inner_join(dcant, basinmask)
dcant_inv_publ_masked <- inner_join(dcant_inv_publ, basinmask)
dcant_inv_publ_all <- inner_join(dcant_inv_publ_all, basinmask)
V101 <- inner_join(V101, basinmask)
ggplot() +
geom_tile(data = dcant_inv_publ,
aes(lon, lat, fill = "basin mask not applied")) +
geom_tile(data = dcant_inv_publ_masked,
aes(lon, lat, fill = "basin mask applied")) +
coord_quickmap()
# join files
dcant_3d <- inner_join(dcant, V101)
rm(dcant, V101)
dcant_zonal <- m_zonal_mean_sd(dcant_3d)
dcant_inv_layers <- m_dcant_inv(dcant_3d)
dcant_inv <- dcant_inv_layers %>%
filter(inv_depth == params_global$inventory_depth_standard)
p_map_cant_inv(
df = dcant_inv,
var = "dcant",
col = "divergent")
p_map_cant_inv(
df = dcant_inv,
var = "dcant_pos")
p_map_cant_inv(
df = dcant_inv_publ_all %>% mutate(dcant_pos = dcant_pos*(10/13)),
var = "dcant_pos") +
facet_wrap(~ Version_ID, ncol = 2)
p_map_cant_inv(
df = dcant_inv_publ,
var = "dcant_pos",
title_text = "Published column inventories - unmasked")
p_map_cant_inv(
df = dcant_inv_publ_masked,
var = "dcant_pos",
title_text = "Published column inventories - masked")
# join published and calculated data sets
dcant_inv_offset <- inner_join(
dcant_inv %>% rename(dcant_re = dcant_pos),
dcant_inv_publ_masked %>% rename(dcant_pub = dcant_pos)
)
# calculate offset
dcant_inv_offset <- dcant_inv_offset %>%
mutate(dcant_offset = dcant_re - dcant_pub)
# plot map
p_map_cant_inv(
df = dcant_inv_offset,
var = "dcant_offset",
col = "bias",
breaks = seq(-3, 3, 0.25)
)
rm(dcant_inv_offset)
p_map_climatology(
df = dcant_3d,
var = "dcant",
col = "divergent")
p_map_climatology(
df = dcant_3d,
var = "dcant_pos")
dcant_zonal %>%
group_split(basin_AIP) %>%
# head(1) %>%
map(
~ p_section_zonal(
df = .x,
var = "dcant_pos_mean",
plot_slabs = "n",
subtitle_text = paste("Basin:", unique(.x$basin_AIP))
)
)
[[1]]
[[2]]
[[3]]
p_section_global(
df = dcant_3d,
var = "dcant",
col = "divergent")
p_section_climatology_regular(
df = dcant_3d,
var = "dcant",
col = "divergent")
p_section_climatology_regular(
df = dcant_3d,
var = "dcant_pos")
dcant_3d %>%
write_csv(paste(path_preprocessing,
"G19_dcant_3d.csv",
sep = ""))
dcant_inv %>%
write_csv(paste(path_preprocessing,
"G19_dcant_inv.csv",
sep = ""))
dcant_inv_publ %>%
write_csv(paste(path_preprocessing,
"G19_dcant_inv_publ.csv",
sep = ""))
dcant_inv_publ_all %>%
write_csv(paste(path_preprocessing,
"G19_dcant_inv_all.csv",
sep = ""))
dcant_zonal %>%
write_csv(paste(path_preprocessing,
"G19_dcant_zonal.csv",
sep = ""))
# extract coordinate reference system
G19_raster <- raster::brick(paste0(
path_gruber_2019,
"dcant_emlr_cstar_gruber_94-07_vs1.nc"))
coord_ref <- raster::crs(G19_raster)
rm(G19_raster)
# open nc file for data extraction
dcant_nc <- tidync(paste(
path_gruber_2019,
"dcant_emlr_cstar_gruber_94-07_vs1.nc",
sep = ""
))
# read delta cant field
dcant <- dcant_nc %>%
activate(DCANT_01) %>%
hyper_tibble(na.rm = FALSE)
# read delta cant field
gamma <- dcant_nc %>%
activate(GAMMA_DENS) %>%
hyper_tibble(na.rm = FALSE)
# join gamma and dcant
dcant <- full_join(dcant, gamma)
rm(gamma)
# harmonize column names and coordinates
dcant <- dcant %>%
rename(lon = LONGITUDE,
lat = LATITUDE,
depth = DEPTH,
dcant = DCANT_01,
gamma = GAMMA_DENS) %>%
mutate(gamma = if_else(is.na(dcant), NaN, gamma))
# convert dcant unit from "µmol kg-1" to "mol m-3"
dcant <- dcant %>%
mutate(dens = (1000 + gamma) / 1000,
dcant = dcant * dens * 1e-3)
# create volume grid
dcant <- dcant %>%
m_layer_thickness() %>%
mutate(surface_area = marelac::earth_surf(lat, lon),
volume = layer_thickness * surface_area,
volume = if_else(is.na(dcant), NaN, volume))
# check total volume
dcant %>%
summarise(total_ocean_volume = sum(volume, na.rm = TRUE))
# check total dcant
dcant %>%
filter(depth <= 3000) %>%
mutate(dcant_inv = dcant * volume) %>%
summarise(total_dcant = sum(dcant_inv, na.rm = TRUE)*12*1e-15)
# select relevant columns
dcant <- dcant %>%
select(lon, lat, depth, dcant, volume)
# create raster objects
volume_raster <- dcant %>%
select(lon, lat, volume) %>%
base::split(dcant$depth) %>%
lapply(raster::rasterFromXYZ) %>%
raster::brick() %>%
raster::setZ(z = unique(dcant$depth), name = "volume")
dcant_raster <- dcant %>%
select(lon, lat, dcant) %>%
base::split(dcant$depth) %>%
lapply(raster::rasterFromXYZ) %>%
raster::brick() %>%
raster::setZ(z = unique(dcant$depth), name = "dcant")
# assign coordinate reference system
raster::crs(dcant_raster) <- coord_ref
raster::crs(volume_raster) <- coord_ref
# assign NA values
raster::NAvalue(dcant_raster) <- -9999
raster::NAvalue(dcant_raster)
raster::NAvalue(volume_raster) <- -9999
raster::NAvalue(volume_raster)
# check object
dim(dcant_raster)
raster::nbands(dcant_raster)
raster::nlayers(dcant_raster)
names(dcant_raster) #get the names of layers
raster::getZ(dcant_raster)
# write netcdf file
raster::writeRaster(
dcant_raster,
filename = paste0(path_preprocessing,
"dcant_Gruber2019_1994-2007_v20211012.nc"),
overwrite = T
)
raster::writeRaster(
volume_raster,
filename = paste0(path_preprocessing,
"volume_Gruber2019_1994-2007_v20211012.nc"),
overwrite = T
)
# modify created netcdf files
library(ncdf4)
# dcant file
# open file in writing mode
dcant_reopen <- nc_open(
paste0(path_preprocessing,
"dcant_Gruber2019_1994-2007_v20211012.nc"),
write = TRUE)
dcant_reopen
print(dcant_reopen)
names(dcant_reopen$var)
# add units
ncatt_get(dcant_reopen, varid = "dcant")
ncatt_put(dcant_reopen, varid = "dcant",
attname = "units", attval = "mol m-3")
ncatt_get(dcant_reopen, varid = "z")
ncatt_put(dcant_reopen, varid = "z",
attname = "units", attval = "metres")
nc_close(dcant_reopen)
# volume file
# open file in writing mode
volume_reopen <- nc_open(
paste0(path_preprocessing,
"volume_Gruber2019_1994-2007_v20211012.nc"),
write = TRUE)
volume_reopen
print(volume_reopen)
names(volume_reopen$var)
# add units
ncatt_get(volume_reopen, varid = "volume")
ncatt_put(volume_reopen, varid = "volume",
attname = "units", attval = "m3")
ncatt_get(volume_reopen, varid = "z")
ncatt_put(volume_reopen, varid = "z",
attname = "units", attval = "metres")
nc_close(volume_reopen)
# final check dcant
dcant_reopen <- tidync(
paste0(path_preprocessing,
"dcant_Gruber2019_1994-2007_v20211012.nc")) %>%
hyper_tibble()
dcant_reopen %>%
filter(z == 0) %>%
ggplot(aes(longitude, latitude, fill=dcant)) +
geom_raster() +
scale_fill_viridis_c()
dcant_reopen %>%
filter(longitude == 200.5) %>%
ggplot(aes(latitude, z, z=dcant)) +
scale_y_reverse() +
geom_contour_filled() +
scale_fill_viridis_d()
dcant_reopen <- read_ncdf(
paste0(path_preprocessing,
"dcant_Gruber2019_1994-2007_v20211012.nc"))
plot(dcant_reopen,
axes = TRUE)
# final check volume
volume_reopen <- tidync(
paste0(path_preprocessing,
"volume_Gruber2019_1994-2007_v20211012.nc")) %>%
hyper_tibble()
volume_reopen %>%
filter(z == 0) %>%
ggplot(aes(longitude, latitude, fill=volume)) +
geom_raster() +
scale_fill_viridis_c()
volume_reopen %>%
filter(longitude == 200.5) %>%
ggplot(aes(latitude, z, z=volume)) +
scale_y_reverse() +
geom_contour_filled() +
scale_fill_viridis_d()
volume_reopen <- read_ncdf(
paste0(path_preprocessing,
"volume_Gruber2019_1994-2007_v20211012.nc"))
plot(volume_reopen,
axes = TRUE)
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: openSUSE Leap 15.3
Matrix products: default
BLAS: /usr/local/R-4.1.2/lib64/R/lib/libRblas.so
LAPACK: /usr/local/R-4.1.2/lib64/R/lib/libRlapack.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] stars_0.5-5 sf_1.0-5 abind_1.4-5 tidync_0.2.4
[5] colorspace_2.0-2 marelac_2.1.10 shape_1.4.6 ggforce_0.3.3
[9] metR_0.11.0 scico_1.3.0 patchwork_1.1.1 collapse_1.7.0
[13] forcats_0.5.1 stringr_1.4.0 dplyr_1.0.7 purrr_0.3.4
[17] readr_2.1.1 tidyr_1.1.4 tibble_3.1.6 ggplot2_3.3.5
[21] tidyverse_1.3.1 workflowr_1.7.0
loaded via a namespace (and not attached):
[1] fs_1.5.2 bit64_4.0.5 lubridate_1.8.0 gsw_1.0-6
[5] httr_1.4.2 rprojroot_2.0.2 tools_4.1.2 backports_1.4.1
[9] bslib_0.3.1 utf8_1.2.2 R6_2.5.1 KernSmooth_2.23-20
[13] DBI_1.1.2 withr_2.4.3 tidyselect_1.1.1 processx_3.5.2
[17] bit_4.0.4 compiler_4.1.2 git2r_0.29.0 cli_3.1.1
[21] rvest_1.0.2 RNetCDF_2.5-2 xml2_1.3.3 isoband_0.2.5
[25] labeling_0.4.2 sass_0.4.0 scales_1.1.1 checkmate_2.0.0
[29] classInt_0.4-3 proxy_0.4-26 SolveSAPHE_2.1.0 callr_3.7.0
[33] digest_0.6.29 rmarkdown_2.11 oce_1.5-0 pkgconfig_2.0.3
[37] htmltools_0.5.2 highr_0.9 dbplyr_2.1.1 fastmap_1.1.0
[41] rlang_0.4.12 readxl_1.3.1 rstudioapi_0.13 jquerylib_0.1.4
[45] generics_0.1.1 farver_2.1.0 jsonlite_1.7.3 vroom_1.5.7
[49] magrittr_2.0.1 ncmeta_0.3.0 Rcpp_1.0.8 munsell_0.5.0
[53] fansi_1.0.2 lifecycle_1.0.1 stringi_1.7.6 whisker_0.4
[57] yaml_2.2.1 MASS_7.3-55 grid_4.1.2 parallel_4.1.2
[61] promises_1.2.0.1 crayon_1.4.2 haven_2.4.3 hms_1.1.1
[65] seacarb_3.3.0 knitr_1.37 ps_1.6.0 pillar_1.6.4
[69] reprex_2.0.1 glue_1.6.0 evaluate_0.14 getPass_0.2-2
[73] data.table_1.14.2 modelr_0.1.8 vctrs_0.3.8 tzdb_0.2.0
[77] tweenr_1.0.2 httpuv_1.6.5 cellranger_1.1.0 gtable_0.3.0
[81] polyclip_1.10-0 assertthat_0.2.1 xfun_0.29 lwgeom_0.2-8
[85] broom_0.7.11 e1071_1.7-9 later_1.3.0 viridisLite_0.4.0
[89] class_7.3-20 ncdf4_1.19 units_0.7-2 ellipsis_0.3.2