Last updated: 2021-06-18

Checks: 7 0

Knit directory: emlr_obs_v_XXX/

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 9a6e1b8. 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/

Unstaged changes:
    Modified:   code/Workflowr_project_managment.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/mapping_cant_mod_truth.Rmd) and HTML (docs/mapping_cant_mod_truth.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 a4075ac jens-daniel-mueller 2021-06-16 Build site.
Rmd 3347668 jens-daniel-mueller 2021-06-16 write cant files
html 4be8cf5 jens-daniel-mueller 2021-06-16 Build site.
Rmd b9839eb jens-daniel-mueller 2021-06-16 cant constant climate model
html 9dca16b jens-daniel-mueller 2021-06-15 Build site.
Rmd d4461ca jens-daniel-mueller 2021-06-15 revise plots
html 993d705 jens-daniel-mueller 2021-06-15 Build site.
Rmd d603f12 jens-daniel-mueller 2021-06-15 revise plots
html 3052a6c jens-daniel-mueller 2021-06-15 Build site.
html 3cb64bd jens-daniel-mueller 2021-06-15 Build site.
html 0d159f9 jens-daniel-mueller 2021-06-15 Build site.
Rmd 6873303 jens-daniel-mueller 2021-06-15 alpha model truth analysed
html c6b3da6 jens-daniel-mueller 2021-06-14 Build site.
html 48c73fc jens-daniel-mueller 2021-06-14 Build site.
html 439ee80 jens-daniel-mueller 2021-06-11 Build site.
html 33ffcab jens-daniel-mueller 2021-06-10 Build site.
html 7e1f407 jens-daniel-mueller 2021-06-10 Build site.
html 2cbe18c jens-daniel-mueller 2021-06-10 added zonal mean section control plots
html 69c79d0 jens-daniel-mueller 2021-06-08 Build site.
html 1772903 jens-daniel-mueller 2021-06-07 Build site.
html 594ed9a jens-daniel-mueller 2021-06-04 Build site.
html db7df0e jens-daniel-mueller 2021-06-04 rebuild without overlapping eras
html 2edc791 jens-daniel-mueller 2021-06-04 Build site.
html 207339d jens-daniel-mueller 2021-06-03 Build site.
html 315710b jens-daniel-mueller 2021-06-03 include anomalous changes
html be90356 jens-daniel-mueller 2021-06-02 Build site.
html d37a85d jens-daniel-mueller 2021-05-31 Build site.
html 4b7a5ee jens-daniel-mueller 2021-05-28 Build site.
html 12b455a jens-daniel-mueller 2021-05-27 Build site.
Rmd ee13efb jens-daniel-mueller 2021-05-27 optional source of local params fully implemented
html 8c736a6 jens-daniel-mueller 2021-05-27 Build site.
Rmd dc8e4e1 jens-daniel-mueller 2021-05-27 optional source of local params implemented
html 25bd183 jens-daniel-mueller 2021-05-26 Build site.
html b79cb2d jens-daniel-mueller 2021-05-20 Build site.
html 62bd574 jens-daniel-mueller 2021-05-20 Build site.
html 7c56c39 jens-daniel-mueller 2021-05-19 Build site.
html 0de759e jens-daniel-mueller 2021-05-13 Build site.
html 52e7583 jens-daniel-mueller 2021-05-12 Build site.
html 969e631 jens-daniel-mueller 2021-05-12 Build site.
html d2a83bc jens-daniel-mueller 2021-04-16 Build site.
html c0a47df jens-daniel-mueller 2021-04-16 Build site.
html 50290e8 jens-daniel-mueller 2021-04-16 overlapping eras
html a00ec94 jens-daniel-mueller 2021-04-16 Build site.
Rmd 82df560 jens-daniel-mueller 2021-04-16 corrected tref assignment
html b6fe355 jens-daniel-mueller 2021-04-16 Build site.
html 81b7c6d jens-daniel-mueller 2021-04-16 Build site.
html 0a6099c jens-daniel-mueller 2021-04-16 Build site.
html ddec5b7 jens-daniel-mueller 2021-04-15 Build site.
html 29edae5 jens-daniel-mueller 2021-04-14 Build site.
html 099d566 jens-daniel-mueller 2021-04-14 Build site.
html bb44686 jens-daniel-mueller 2021-04-14 Build site.
html bf40480 jens-daniel-mueller 2021-04-13 Build site.
html 9f31fe3 jens-daniel-mueller 2021-04-13 Build site.
Rmd 80e1ee3 jens-daniel-mueller 2021-04-13 rerun post-2000 with model data
html f6ed7de jens-daniel-mueller 2021-04-13 Build site.
Rmd 3efd03e jens-daniel-mueller 2021-04-13 included model data
html f8ce165 jens-daniel-mueller 2021-04-13 Build site.
Rmd b7d14dc jens-daniel-mueller 2021-04-13 included model data

1 Version ID

The results displayed on this site correspond to the Version_ID: v_XXX

2 Required data

2.1 Predictor fields

tref  <-
  read_csv(paste(path_version_data,
                 "tref.csv",
                 sep = ""))

cant_tref_1 <-
  read_csv(
    paste(
      path_model_preprocessing,
      "cant_annual_field_AD",
      "/cant_",
      unique(tref$median_year[1]),
      ".csv",
      sep = ""
    )
  )

cant_tref_1 <- cant_tref_1 %>%
  rename(cant_tref_1 = cant_total) %>%
  select(-year)

cant_tref_2 <-
  read_csv(
    paste(
      path_model_preprocessing,
      "cant_annual_field_AD",
      "/cant_",
      unique(tref$median_year[2]),
      ".csv",
      sep = ""
    )
  )

cant_tref_2 <- cant_tref_2 %>%
  rename(cant_tref_2 = cant_total) %>%
  select(-year)
cant_cc_tref_1 <-
  read_csv(
    paste(
      path_model_preprocessing,
      "cant_annual_field_CB",
      "/cant_",
      unique(tref$median_year[1]),
      ".csv",
      sep = ""
    )
  )

cant_cc_tref_1 <- cant_cc_tref_1 %>%
  rename(cant_tref_1 = cant_total) %>%
  select(-year)

cant_cc_tref_2 <-
  read_csv(
    paste(
      path_model_preprocessing,
      "cant_annual_field_CB",
      "/cant_",
      unique(tref$median_year[2]),
      ".csv",
      sep = ""
    )
  )

cant_cc_tref_2 <- cant_cc_tref_2 %>%
  rename(cant_tref_2 = cant_total) %>%
  select(-year)
climatology <-
  read_csv(paste(path_model_preprocessing, "climatology_runA_2007.csv", sep = ""))

climatology <- climatology %>%
  select(lon,lat,depth, gamma)
cant_average <- left_join(cant_tref_1, cant_tref_2) %>%
  mutate(cant = cant_tref_2 - cant_tref_1)

rm(cant_tref_1, cant_tref_2)

cant_average <- cant_average %>%
  mutate(cant_pos = if_else(cant <= 0, 0, cant))

cant_average <- inner_join(basinmask, cant_average)

cant_average <- full_join(cant_average, climatology)

cant_average <-
  m_cant_model_average(cant_average %>% mutate(eras = "blank"))

cant_average <- m_cut_gamma(cant_average, "gamma")

cant_average_vc <- cant_average %>% 
  mutate(data_source = "mod_truth") %>% 
  select(lon, lat, depth, eras, basin, basin_AIP, data_source,
            cant_tref_1, cant, cant_pos, cant_sd, cant_pos_sd,
            gamma, gamma_sd, gamma_slab)
cant_average <- left_join(cant_cc_tref_1, cant_cc_tref_2) %>%
  mutate(cant = cant_tref_2 - cant_tref_1)

rm(cant_cc_tref_1, cant_cc_tref_2)

cant_average <- cant_average %>%
  mutate(cant_pos = if_else(cant <= 0, 0, cant))

cant_average <- inner_join(basinmask, cant_average)

cant_average <- full_join(cant_average, climatology)

cant_average <-
  m_cant_model_average(cant_average %>% mutate(eras = "blank"))

cant_average <- m_cut_gamma(cant_average, "gamma")

cant_average_cc <- cant_average %>% 
  mutate(data_source = "mod_truth_cc") %>% 
  select(lon, lat, depth, eras, basin, basin_AIP, data_source,
            cant_tref_1, cant, cant_pos, cant_sd, cant_pos_sd,
            gamma, gamma_sd, gamma_slab)

rm(climatology, cant_average)
cant_average <- bind_rows(
  cant_average_cc,
  cant_average_vc
)

rm(
  cant_average_cc,
  cant_average_vc
)

2.2 Average model Cant

cant_average %>%
  group_split(data_source) %>%
  # head(1) %>%
  map(~ p_map_climatology(
    df = .x,
    var = "cant_pos",
    subtitle_text = paste("Climate: ", .x$data_source)
  ))
[[1]]

Version Author Date
4be8cf5 jens-daniel-mueller 2021-06-16
7e1f407 jens-daniel-mueller 2021-06-10
2cbe18c jens-daniel-mueller 2021-06-10
1772903 jens-daniel-mueller 2021-06-07
594ed9a jens-daniel-mueller 2021-06-04
db7df0e jens-daniel-mueller 2021-06-04
207339d jens-daniel-mueller 2021-06-03
315710b jens-daniel-mueller 2021-06-03
be90356 jens-daniel-mueller 2021-06-02
969e631 jens-daniel-mueller 2021-05-12
d2a83bc jens-daniel-mueller 2021-04-16
c0a47df jens-daniel-mueller 2021-04-16
50290e8 jens-daniel-mueller 2021-04-16
a00ec94 jens-daniel-mueller 2021-04-16
b6fe355 jens-daniel-mueller 2021-04-16
ddec5b7 jens-daniel-mueller 2021-04-15
29edae5 jens-daniel-mueller 2021-04-14
9f31fe3 jens-daniel-mueller 2021-04-13
f8ce165 jens-daniel-mueller 2021-04-13

[[2]]

Version Author Date
4be8cf5 jens-daniel-mueller 2021-06-16
cant_average %>%
  group_split(data_source) %>%
  # head(1) %>%
  map(~ p_section_climatology_regular(
    df = .x,
    var = "cant_pos",
    subtitle_text = paste("Climate: ", .x$data_source)
  ))
[[1]]

Version Author Date
4be8cf5 jens-daniel-mueller 2021-06-16
7e1f407 jens-daniel-mueller 2021-06-10
2cbe18c jens-daniel-mueller 2021-06-10
594ed9a jens-daniel-mueller 2021-06-04
db7df0e jens-daniel-mueller 2021-06-04
207339d jens-daniel-mueller 2021-06-03
315710b jens-daniel-mueller 2021-06-03
969e631 jens-daniel-mueller 2021-05-12
d2a83bc jens-daniel-mueller 2021-04-16
c0a47df jens-daniel-mueller 2021-04-16
50290e8 jens-daniel-mueller 2021-04-16
a00ec94 jens-daniel-mueller 2021-04-16
b6fe355 jens-daniel-mueller 2021-04-16
ddec5b7 jens-daniel-mueller 2021-04-15
29edae5 jens-daniel-mueller 2021-04-14
9f31fe3 jens-daniel-mueller 2021-04-13
f8ce165 jens-daniel-mueller 2021-04-13

[[2]]

Version Author Date
4be8cf5 jens-daniel-mueller 2021-06-16

2.3 Zonal mean sections

cant_average_zonal <- m_cant_zonal_mean_data_source(cant_average)
cant_average_zonal <- m_cut_gamma(cant_average_zonal, "gamma_mean")

2.4 Inventory calculation

To calculate Cant column inventories, we:

  1. Convert Cant concentrations to volumetric units
  2. Multiply layer thickness with volumetric Cant concentration to get a layer inventory
  3. For each horizontal grid cell and era, sum cant layer inventories for different inventory depths (100, 500, 1000, 3000, 10^{4} m)

Step 2 is performed separately for all Cant and positive Cant values only.

cant_inv <- m_cant_inv_data_source(cant_average)

p_map_cant_inv(df = cant_inv,
               var = "cant_pos_inv",
               subtitle_text = "for predefined integration depths") +
  facet_grid(inv_depth ~ data_source)

Version Author Date
4be8cf5 jens-daniel-mueller 2021-06-16
7e1f407 jens-daniel-mueller 2021-06-10
2cbe18c jens-daniel-mueller 2021-06-10
1772903 jens-daniel-mueller 2021-06-07
594ed9a jens-daniel-mueller 2021-06-04
db7df0e jens-daniel-mueller 2021-06-04
207339d jens-daniel-mueller 2021-06-03
315710b jens-daniel-mueller 2021-06-03
be90356 jens-daniel-mueller 2021-06-02
969e631 jens-daniel-mueller 2021-05-12
d2a83bc jens-daniel-mueller 2021-04-16
c0a47df jens-daniel-mueller 2021-04-16
50290e8 jens-daniel-mueller 2021-04-16
a00ec94 jens-daniel-mueller 2021-04-16
b6fe355 jens-daniel-mueller 2021-04-16
ddec5b7 jens-daniel-mueller 2021-04-15
29edae5 jens-daniel-mueller 2021-04-14
9f31fe3 jens-daniel-mueller 2021-04-13
f8ce165 jens-daniel-mueller 2021-04-13
cant_total_inv <- m_cant_inv_data_source(
  cant_average %>%
    select(-c(cant, cant_pos)) %>%
    rename(cant = cant_tref_1) %>%
    mutate(cant_pos = if_else(cant <= 0, 0, cant))
)

p_map_cant_inv(df = cant_total_inv,
               var = "cant_pos_inv",
               subtitle_text = "for predefined integration depths",
               breaks = seq(0,50,5)) +
  facet_grid(inv_depth ~ data_source)

Version Author Date
4be8cf5 jens-daniel-mueller 2021-06-16
0d159f9 jens-daniel-mueller 2021-06-15

3 Alpha

3.1 3d fields

alpha_3d <- cant_average %>% 
  mutate(alpha = cant / cant_tref_1,
         alpha = if_else(cant <= 0 | cant_tref_1 <= 0,
                         NaN, alpha))

alpha_3d %>%
  filter(alpha < 1) %>%
  ggplot(aes(alpha)) +
  geom_histogram() +
  facet_grid(basin_AIP ~ data_source) +
  scale_x_continuous(breaks = seq(0, 1, 0.1))

Version Author Date
4be8cf5 jens-daniel-mueller 2021-06-16
0d159f9 jens-daniel-mueller 2021-06-15
median_alpha <- 
  alpha_3d %>% 
  group_by(depth, basin_AIP, data_source) %>% 
  summarise(alpha_median = median(alpha, na.rm = TRUE),
            alpha_mean = weighted.mean(alpha, cant_tref_1, na.rm = TRUE)) %>% 
  ungroup()

alpha_3d %>%
  filter(alpha < 1) %>%
  ggplot(aes(alpha, depth)) +
  geom_bin2d(binwidth = c(0.01, 200)) +
  geom_path(data = median_alpha,
            aes(alpha_median, depth, col="Median")) +
  geom_path(data = median_alpha,
            aes(alpha_mean, depth, col="Weighted mean")) +
  scale_color_manual(name = "Alpha",
                     values = c("red", "orange")) +
  scale_y_reverse() +
  scale_x_continuous(breaks = seq(0, 1, 0.1)) +
  scale_fill_viridis_c(trans = "log10") +
  coord_cartesian(expand = 0) +
  facet_grid(basin_AIP~data_source)

Version Author Date
4be8cf5 jens-daniel-mueller 2021-06-16
993d705 jens-daniel-mueller 2021-06-15
0d159f9 jens-daniel-mueller 2021-06-15
print(paste("mean:",
            round(mean(
              alpha_3d$alpha, na.rm = TRUE
            ), 3)))
[1] "mean: 0.36"
print(paste("mean, weighted with Cant:",
            round(
              weighted.mean(
                x = alpha_3d$alpha,
                w = alpha_3d$cant_tref_1,
                na.rm = TRUE
              ),
              3
            )))
[1] "mean, weighted with Cant: 0.166"
print(paste("median:",
            round(median(
              alpha_3d$alpha, na.rm = TRUE
            ), 3)))
[1] "median: 0.172"

3.2 Inventory maps

alpha_inv <- bind_rows(
  cant_inv %>% mutate(estimate = "delta_cant"),
  cant_total_inv %>% mutate(estimate = "total_cant")
)

alpha_inv <- alpha_inv %>%
  select(lon, lat, cant_inv, inv_depth, estimate, data_source) %>%
  pivot_wider(names_from = estimate,
              values_from = cant_inv)

alpha_inv <- alpha_inv %>% 
  mutate(alpha = delta_cant / total_cant)


map +
  geom_raster(data = alpha_inv #%>% filter(inv_depth == params_global$inventory_depth_standard)
              ,
              aes(lon, lat, fill = alpha)) +
  facet_grid(inv_depth ~ data_source) +
  scale_fill_divergent(
    midpoint = median(alpha_inv$alpha)
  )

Version Author Date
4be8cf5 jens-daniel-mueller 2021-06-16
9dca16b jens-daniel-mueller 2021-06-15
993d705 jens-daniel-mueller 2021-06-15
0d159f9 jens-daniel-mueller 2021-06-15

4 Write csv

cant_average <- cant_average %>%
  select(-c(cant_tref_1))

cant_average %>%
  filter(data_source == "mod_truth") %>%
  write_csv(paste(path_version_data,
                  "cant_3d_mod_truth.csv", sep = ""))

cant_average %>%
  filter(data_source == "mod_truth_cc") %>%
  write_csv(paste(path_version_data,
                  "cant_3d_mod_truth_cc.csv", sep = ""))

cant_average_zonal %>%
  filter(data_source == "mod_truth_cc") %>%
  write_csv(paste(path_version_data,
                  "cant_zonal_mod_truth_cc.csv", sep = ""))

cant_average_zonal %>%
  filter(data_source == "mod_truth") %>%
  write_csv(paste(path_version_data,
                  "cant_zonal_mod_truth.csv", sep = ""))

cant_inv %>%
  filter(data_source == "mod_truth") %>%
  write_csv(paste(path_version_data,
                  "cant_inv_mod_truth.csv", sep = ""))

cant_inv %>%
  filter(data_source == "mod_truth_cc") %>%
  write_csv(paste(path_version_data,
                  "cant_inv_mod_truth_cc.csv", sep = ""))

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: openSUSE Leap 15.2

Matrix products: default
BLAS:   /usr/local/R-4.0.3/lib64/R/lib/libRblas.so
LAPACK: /usr/local/R-4.0.3/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] metR_0.9.0      scico_1.2.0     patchwork_1.1.1 collapse_1.5.0 
 [5] forcats_0.5.0   stringr_1.4.0   dplyr_1.0.5     purrr_0.3.4    
 [9] readr_1.4.0     tidyr_1.1.2     tibble_3.0.4    ggplot2_3.3.3  
[13] tidyverse_1.3.0 workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] httr_1.4.2               jsonlite_1.7.1           viridisLite_0.3.0       
 [4] here_0.1                 modelr_0.1.8             assertthat_0.2.1        
 [7] blob_1.2.1               cellranger_1.1.0         yaml_2.2.1              
[10] pillar_1.4.7             backports_1.1.10         lattice_0.20-41         
[13] glue_1.4.2               RcppEigen_0.3.3.7.0      digest_0.6.27           
[16] promises_1.1.1           checkmate_2.0.0          rvest_0.3.6             
[19] colorspace_1.4-1         htmltools_0.5.0          httpuv_1.5.4            
[22] Matrix_1.2-18            pkgconfig_2.0.3          broom_0.7.5             
[25] haven_2.3.1              scales_1.1.1             whisker_0.4             
[28] later_1.1.0.1            git2r_0.27.1             generics_0.0.2          
[31] farver_2.0.3             ellipsis_0.3.1           withr_2.3.0             
[34] cli_2.1.0                magrittr_1.5             crayon_1.3.4            
[37] readxl_1.3.1             evaluate_0.14            fs_1.5.0                
[40] fansi_0.4.1              xml2_1.3.2               RcppArmadillo_0.10.1.2.0
[43] tools_4.0.3              data.table_1.13.2        hms_0.5.3               
[46] lifecycle_1.0.0          munsell_0.5.0            reprex_0.3.0            
[49] isoband_0.2.2            compiler_4.0.3           rlang_0.4.10            
[52] grid_4.0.3               rstudioapi_0.11          labeling_0.4.2          
[55] rmarkdown_2.5            gtable_0.3.0             DBI_1.1.0               
[58] R6_2.5.0                 lubridate_1.7.9          knitr_1.30              
[61] rprojroot_2.0.2          stringi_1.5.3            parallel_4.0.3          
[64] Rcpp_1.0.5               vctrs_0.3.5              dbplyr_1.4.4            
[67] tidyselect_1.1.0         xfun_0.18