Last updated: 2021-07-30

Checks: 7 0

Knit directory: emlr_obs_analysis/

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(20210412) 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 e5db677. 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:    data/
    Ignored:    output/Gruber_2019_comparison/
    Ignored:    output/publication/

Unstaged changes:
    Modified:   analysis/_site.yml
    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/column_inventories.Rmd) and HTML (docs/column_inventories.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 964b616 jens-daniel-mueller 2021-07-30 Build site.
html 0a09f3e jens-daniel-mueller 2021-07-30 Build site.
html 3a48c91 jens-daniel-mueller 2021-07-27 Build site.
html b32149b jens-daniel-mueller 2021-07-27 Build site.
Rmd e71970f jens-daniel-mueller 2021-07-27 rebuildt with budget analysis
html 3402949 jens-daniel-mueller 2021-07-26 Build site.
Rmd fe80715 jens-daniel-mueller 2021-07-26 added ensemble analysis
html d0441c4 jens-daniel-mueller 2021-07-26 Build site.
Rmd d298b24 jens-daniel-mueller 2021-07-26 added ensemble analysis
html 7a1b358 jens-daniel-mueller 2021-07-26 Build site.
Rmd 51e22f6 jens-daniel-mueller 2021-07-26 cleaned code and output
html 860126c jens-daniel-mueller 2021-07-26 Build site.
Rmd 123c854 jens-daniel-mueller 2021-07-26 cleaned code and output
html 432df8a jens-daniel-mueller 2021-07-26 Build site.
Rmd 310fd35 jens-daniel-mueller 2021-07-26 cleaned code and output
html 93a27dd jens-daniel-mueller 2021-07-26 Build site.
Rmd f000466 jens-daniel-mueller 2021-07-26 rebuildt with latest results
html 7493389 jens-daniel-mueller 2021-07-05 Build site.
html 8b2e4d3 jens-daniel-mueller 2021-06-22 Build site.
html 8756c6f jens-daniel-mueller 2021-06-02 Build site.
Rmd 9881e98 jens-daniel-mueller 2021-06-02 include GLODAP beta 2021 based results
html 4d8b4e7 jens-daniel-mueller 2021-06-02 Build site.
Rmd 05184e5 jens-daniel-mueller 2021-06-02 include GLODAP beta 2021 based results
html 878aef7 jens-daniel-mueller 2021-05-28 Build site.
Rmd 2c347cd jens-daniel-mueller 2021-05-28 plotted C* rmse, MLR target, vif max
html 92cae2e jens-daniel-mueller 2021-05-28 Build site.
Rmd 87a8c49 jens-daniel-mueller 2021-05-28 plotted Canyon B max
html 998f4a6 jens-daniel-mueller 2021-05-28 Build site.
Rmd 3c6f0f4 jens-daniel-mueller 2021-05-28 including cases 109-116
html a28ce5c jens-daniel-mueller 2021-05-28 Build site.
Rmd 2f6d0c0 jens-daniel-mueller 2021-05-28 including cases 109-116
html 3454b72 jens-daniel-mueller 2021-05-28 Build site.
Rmd 1b46b2a jens-daniel-mueller 2021-05-28 including cases 109-116
html db22706 jens-daniel-mueller 2021-05-28 Build site.
Rmd 9bb2f7a jens-daniel-mueller 2021-05-28 plot global budgets
html 87481da jens-daniel-mueller 2021-05-28 Build site.
Rmd 154a8fc jens-daniel-mueller 2021-05-28 plot global budgets
html bd4af9d jens-daniel-mueller 2021-05-28 Build site.
Rmd cdd2cc8 jens-daniel-mueller 2021-05-28 plot global budgets
html ee5b15d jens-daniel-mueller 2021-05-27 Build site.
Rmd 83f3e37 jens-daniel-mueller 2021-05-27 plot bias maps
html e8bd251 jens-daniel-mueller 2021-05-27 Build site.
Rmd f642ef2 jens-daniel-mueller 2021-05-27 plot bias maps
html ea0153f jens-daniel-mueller 2021-05-27 Build site.
Rmd 8b38db1 jens-daniel-mueller 2021-05-27 plot bias maps
html cf3365a jens-daniel-mueller 2021-05-27 Build site.
Rmd 2eb7603 jens-daniel-mueller 2021-05-27 plot bias maps
html 57ddd1f jens-daniel-mueller 2021-05-27 Build site.
Rmd f403434 jens-daniel-mueller 2021-05-27 sensitivity case comparison included

1 Read files

# identify required version IDs

# Version_IDs <- list.files(
#   path = "/nfs/kryo/work/jenmueller/emlr_cant/observations",
#   pattern = "v_")[1:34]

Version_IDs_1 <- list.files(
  path = "/nfs/kryo/work/jenmueller/emlr_cant/observations",
  pattern = "v_10")[1:4]

Version_IDs_2 <- list.files(
  path = "/nfs/kryo/work/jenmueller/emlr_cant/observations",
  pattern = "v_20")[1:4]

Version_IDs <- c(Version_IDs_1, Version_IDs_2)
rm(Version_IDs_1, Version_IDs_2)

# Version_IDs <- Version_IDs[1:length(Version_IDs)-1]

for (i_Version_IDs in Version_IDs) {
  # i_Version_IDs <- Version_IDs[1]
  
  print(i_Version_IDs)
  
  path_version_data     <-
  paste(path_observations,
        i_Version_IDs,
        "/data/",
        sep = "")
  
  # load and join data files
  
  dcant_inv <-
    read_csv(paste(path_version_data,
                   "dcant_inv.csv",
                   sep = ""))
  
  dcant_inv_mod_truth <-
    read_csv(paste(path_version_data,
                   "dcant_inv_mod_truth.csv",
                   sep = "")) %>% 
    filter(method == "total") %>% 
    select(-method)
  
  dcant_inv_bias <-
    read_csv(paste(path_version_data,
                   "dcant_inv_bias.csv",
                   sep = ""))
  
  dcant_inv <- bind_rows(dcant_inv,
                         dcant_inv_mod_truth)
  
  dcant_inv <- dcant_inv %>% 
    mutate(Version_ID = i_Version_IDs)
  
  dcant_inv_bias <- dcant_inv_bias %>% 
    mutate(Version_ID = i_Version_IDs)
  
  params_local <-
    read_rds(paste(path_version_data,
                   "params_local.rds",
                   sep = ""))
  
  params_local <- bind_cols(
    Version_ID = i_Version_IDs,
    MLR_basins = params_local$MLR_basins,
    tref1 = params_local$tref1,
    tref2 = params_local$tref2,
    gap_filling = params_local$gap_filling,
    rarefication = params_local$rarefication,
    rarefication_threshold = params_local$rarefication_threshold,
    MLR_predictors = str_c(params_local$MLR_predictors, collapse = "+"),
    vif_max = params_local$vif_max
  )
  
  tref <- read_csv(paste(path_version_data,
                         "tref.csv",
                         sep = ""))
  
  params_local <- params_local %>% 
    mutate(median_year_1 = sort(tref$median_year)[1],
           median_year_2 = sort(tref$median_year)[2],
           duration = median_year_2 - median_year_1,
           period = paste(median_year_1, "-", median_year_2))
  
  if (exists("dcant_inv_all")) {
    dcant_inv_all <- bind_rows(dcant_inv_all, dcant_inv)
  }
  
  if (!exists("dcant_inv_all")) {
    dcant_inv_all <- dcant_inv
  }

  if (exists("dcant_inv_bias_all")) {
    dcant_inv_bias_all <- bind_rows(dcant_inv_bias_all, dcant_inv_bias)
  }
  
  if (!exists("dcant_inv_bias_all")) {
    dcant_inv_bias_all <- dcant_inv_bias
  }

  if (exists("params_local_all")) {
    params_local_all <- bind_rows(params_local_all, params_local)
  }
  
  if (!exists("params_local_all")) {
    params_local_all <- params_local
  }
  
  
}
[1] "v_101"
[1] "v_102"
[1] "v_103"
[1] "v_104"
[1] "v_201"
[1] "v_202"
[1] "v_203"
[1] "v_204"
rm(dcant_inv, dcant_inv_bias, dcant_inv_mod_truth,
   params_local, tref)

dcant_inv_all <- full_join(dcant_inv_all,
                           params_local_all)

dcant_inv_bias_all <- full_join(dcant_inv_bias_all,
                                params_local_all)
dcant_inv_all <- dcant_inv_all %>%
  filter(inv_depth == params_global$inventory_depth_standard)

2 Individual cases

2.1 Absoulte values

dcant_inv_all %>%
  filter(data_source %in% c("mod", "obs")) %>%
  group_by(period) %>%
  group_split() %>%
  # head(1) %>% 
  map(
    ~ p_map_cant_inv(df = .x,
                     var = "dcant",
                     subtitle_text = paste("period:",
                                           unique(.x$period))) +
      facet_grid(MLR_basins ~ data_source)
  )
[[1]]

Version Author Date
432df8a jens-daniel-mueller 2021-07-26

[[2]]

Version Author Date
432df8a jens-daniel-mueller 2021-07-26

2.2 Biases

dcant_inv_bias_all %>%
  p_map_cant_inv(var = "dcant_bias",
                 col = "bias",
                 subtitle_text = "data_source: mod - mod_truth") +
  facet_grid(MLR_basins ~ period)

Version Author Date
432df8a jens-daniel-mueller 2021-07-26

3 Ensemble

dcant_inv_ensemble <- dcant_inv_all %>% 
  filter(data_source %in% c("mod", "obs")) %>% 
  group_by(lat, lon, data_source, period) %>% 
  summarise(dcant_mean = mean(dcant),
            dcant_sd = sd(dcant),
            dcant_range = max(dcant)- min(dcant)) %>% 
  ungroup()

3.1 Mean

p_map_cant_inv(df = dcant_inv_ensemble,
                     var = "dcant_mean",
                     subtitle_text = paste("Ensemble means")) +
      facet_grid(period ~ data_source)

Version Author Date
860126c jens-daniel-mueller 2021-07-26
432df8a jens-daniel-mueller 2021-07-26

3.2 Mean bias

dcant_inv_ensemble_bias <- full_join(
  dcant_inv_ensemble %>%
    filter(data_source == "mod") %>% 
    select(lat, lon, period, dcant_mean, dcant_sd),
  dcant_inv_all %>%
    filter(data_source == "mod_truth",
           MLR_basins == "2") %>% 
    select(lat, lon, period, dcant)
)

dcant_inv_ensemble_bias <- dcant_inv_ensemble_bias %>% 
  mutate(dcant_mean_bias = dcant_mean - dcant)

dcant_inv_ensemble_bias %>%
  p_map_cant_inv(var = "dcant_mean_bias",
                 col = "bias",
                 subtitle_text = "Ensemble mean - mod_truth") +
  facet_grid(. ~ period)

Version Author Date
7a1b358 jens-daniel-mueller 2021-07-26

3.3 Standard deviation

p_map_cant_inv(
  df = dcant_inv_ensemble,
  var = "dcant_sd",
  breaks = c(seq(0,4,0.4), Inf),
  subtitle_text = paste("Ensemble SD")
) +
  facet_grid(period ~ data_source)

Version Author Date
d0441c4 jens-daniel-mueller 2021-07-26
860126c jens-daniel-mueller 2021-07-26

3.4 SD vs bias

dcant_inv_ensemble_bias %>% 
  ggplot(aes(dcant_mean_bias, dcant_sd)) +
  geom_bin2d() +
  scale_fill_viridis_c() +
  facet_grid(. ~ period)

Version Author Date
d0441c4 jens-daniel-mueller 2021-07-26
dcant_inv_ensemble_bias %>% 
  select(dcant_mean, dcant_mean_bias, period) %>% 
  pivot_longer(dcant_mean:dcant_mean_bias,
               names_to = "estimate",
               values_to = "value") %>% 
  ggplot(aes(value, col=estimate, linetype = period)) +
  scale_color_brewer(palette = "Set1") +
  geom_density()

Version Author Date
3402949 jens-daniel-mueller 2021-07-26
d0441c4 jens-daniel-mueller 2021-07-26
dcant_inv_ensemble %>% 
  ggplot(aes(dcant_sd)) +
  geom_histogram() +
  facet_grid(data_source ~ period) +
  coord_cartesian(ylim = c(0,50))

Version Author Date
3402949 jens-daniel-mueller 2021-07-26
d0441c4 jens-daniel-mueller 2021-07-26

3.5 Range

p_map_cant_inv(
  df = dcant_inv_ensemble,
  var = "dcant_range",
  breaks = c(seq(0,8,0.8), Inf),
  subtitle_text = paste("Ensemble range")
) +
  facet_grid(period ~ data_source)

Version Author Date
860126c jens-daniel-mueller 2021-07-26

4 Cases vs ensemble

4.1 Offset from mean

dcant_inv_all <- full_join(dcant_inv_all,
                           dcant_inv_ensemble)

dcant_inv_all <- dcant_inv_all %>% 
  mutate(dcant_offset = dcant - dcant_mean)

dcant_inv_all %>%
  filter(data_source %in% c("mod", "obs")) %>%
  group_by(period) %>%
  group_split() %>%
  # head(1) %>%
  map(
    ~ p_map_cant_inv(df = .x,
                     var = "dcant_offset",
                     col = "bias",
                     subtitle_text = paste("period:",
                                           unique(.x$period))) +
      facet_grid(MLR_basins ~ data_source)
  )
[[1]]

Version Author Date
7a1b358 jens-daniel-mueller 2021-07-26

[[2]]

Version Author Date
7a1b358 jens-daniel-mueller 2021-07-26

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] ggforce_0.3.3   metR_0.9.0      scico_1.2.0     patchwork_1.1.1
 [5] collapse_1.5.0  forcats_0.5.0   stringr_1.4.0   dplyr_1.0.5    
 [9] purrr_0.3.4     readr_1.4.0     tidyr_1.1.2     tibble_3.0.4   
[13] ggplot2_3.3.3   tidyverse_1.3.0 workflowr_1.6.2

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