Last updated: 2022-10-24

Checks: 7 0

Knit directory: emlr_mod_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 e855cad. 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/

Untracked files:
    Untracked:  code/backup_analysis_scripts/Cant_CB_annual_all_models_backup_20220704.Rmd

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/co2_atm.Rmd) and HTML (docs/co2_atm.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 e829a11 jens-daniel-mueller 2022-07-05 Build site.
Rmd 923e07e jens-daniel-mueller 2022-07-04 rerun for all models
html 89cbb74 jens-daniel-mueller 2022-05-26 Build site.
html 42bbb89 jens-daniel-mueller 2022-05-24 Build site.
Rmd e82a302 jens-daniel-mueller 2022-05-23 bug fixes for 5 models
html 40863a2 jens-daniel-mueller 2022-05-22 Build site.
Rmd d9d4d68 jens-daniel-mueller 2022-05-21 rebuild with revised output structure and all models
html df15df5 jens-daniel-mueller 2022-05-12 Build site.
Rmd b1c9920 jens-daniel-mueller 2022-05-12 read data from all models and write individual files
html 1e7641d jens-daniel-mueller 2022-05-12 Build site.
Rmd f91b22d jens-daniel-mueller 2022-05-12 read data from all models
html 06054b2 jens-daniel-mueller 2022-05-10 Build site.
Rmd d43e8c0 jens-daniel-mueller 2022-05-10 rerun all with multi model subsetting

1 Read data

models <- list.files(path_cmorized)

models <-
  models[!str_detect(models, pattern = "\\.t|\\.z|.p")]

models <-
  models[str_detect(
    models,
    pattern = c(
      "CESM|CNRM|EC-Earth3|FESOM_REcoM_LR|MOM6-Princeton|MRI-ESM2-1|NorESM-OC1.2|ORCA025-GEOMAR|ORCA1-LIM3-PISCES|planktom12"
    )
  )]

# no Atm_CO2 data provided
models <-
  models[!str_detect(models, pattern = "NorESM-OC1.2")]

# no Atm_CO2 data provided
models <-
  models[!str_detect(models, pattern = "ORCA1-LIM3-PISCES")]
# models <- models[1]

for (i_model in models) {
  # i_model <- models[7]
  print(i_model)
  
  # read list of all files
  file <-
    list.files(path = paste0(path_cmorized, i_model),
               pattern = "CO2")[1]
  
  print(file)
  
  # read in data
  if (i_model %in% c(
    "CESM-ETHZ_Ancillary_data_v20211122",
    "MOM6-Princeton_Ancillary_data_v20220125",
    "ORCA025-GEOMAR_Ancillary_data_v20210804"
  )) {
    variable_data <-
      read_ncdf(paste(paste0(path_cmorized, i_model),
                      file,
                      sep = "/"),
                var = "Atm_CO2",
                make_units = FALSE)
  } else if (i_model == "CNRM-ESM2-1_Ancillary_data_v20211208") {
    variable_data <-
      read_delim(paste(paste0(path_cmorized, i_model),
                       file,
                       sep = "/"),
                 delim = " ") %>%
      rename(year = Year,
             Atm_CO2 = atmCO2)
    
  } else if (i_model == "EC-Earth3_Ancillary_data_v20220323") {
    variable_data <-
      read_table(paste(paste0(path_cmorized, i_model),
                       file,
                       sep = "/"),
                 col_names = FALSE) %>%
      rename(year = X1,
             Atm_CO2 = X2)
  } else if (i_model == "MRI-ESM2-1_Ancillary_data_v20220502") {
    variable_data <-
      tidync(paste(paste0(path_cmorized, i_model),
                   file,
                   sep = "/")) %>%
      activate("D0") %>%
      hyper_tibble() %>%
      mutate(time = as.Date(time, origin = "1980-01-01"))
  } else if (i_model == "planktom12_ancillary_data_v20220404") {
    variable_data <-
      read_table(paste(paste0(path_cmorized, i_model),
                       file,
                       sep = "/"),
                 col_names = FALSE) %>%
      select(year = X1,
             Atm_CO2 = X2)
  } else {
    variable_data <-
      read_ncdf(paste(paste0(path_cmorized, i_model),
                      file,
                      sep = "/"),
                make_units = FALSE)
  }
  
  # convert to tibble
  variable_data_tibble <- variable_data %>%
    as_tibble()
  
  # remove open link to nc file
  rm(variable_data)
  
  if (i_model == "CESM-ETHZ_Ancillary_data_v20211122") {
    variable_data_tibble <- variable_data_tibble %>%
      rename(time = time_ann)
  }
  
  if (i_model == "FESOM_REcoM_LR_Ancillary_data_v20211119") {
    variable_data_tibble <-
      variable_data_tibble %>%
      pivot_longer(
        cols = -NumberOfMonths,
        names_to = "year",
        values_to = "Atm_CO2",
        names_prefix = "AtmCO2_"
      ) %>%
      mutate(year = as.numeric(year))
  }
  
  # mutate variables
  if (!(
    i_model %in% c(
      "CNRM-ESM2-1_Ancillary_data_v20211208",
      "EC-Earth3_Ancillary_data_v20220323",
      "FESOM_REcoM_LR_Ancillary_data_v20211119",
      "planktom12_ancillary_data_v20220404"
    )
  )) {
    variable_data_tibble <- variable_data_tibble %>%
      mutate(year = year(time)) %>%
      select(-time)
  }
  
  variable_data_tibble <- variable_data_tibble %>%
    mutate(model = i_model)
  
  
  if (exists("atm_co2")) {
    atm_co2 <- bind_rows(atm_co2, variable_data_tibble)
  }
  
  if (!exists("atm_co2")) {
    atm_co2 <- variable_data_tibble
  }
  
}
[1] "CESM-ETHZ_Ancillary_data_v20211122"
[1] "Atm_CO2_CESM-ETHZ_1_gr_1980-2018_v20211122.nc"
[1] "CNRM-ESM2-1_Ancillary_data_v20211208"
[1] "Atm_CO2"
[1] "EC-Earth3_Ancillary_data_v20220323"
[1] "Atm_CO2_EC-Earth3_v20220323.txt"
[1] "FESOM_REcoM_LR_Ancillary_data_v20211119"
[1] "MonthlyAtmCO2_gcb2020.nc"
[1] "MOM6-Princeton_Ancillary_data_v20220125"
[1] "Atm_CO2_MOM6-Princeton_A_1_gr_1980-2018_v20220125.nc"
[1] "MRI-ESM2-1_Ancillary_data_v20220502"
[1] "Atm_CO2_MRI-ESM2-1_A_1_gm_1980-2018_v20220502.nc"
[1] "ORCA025-GEOMAR_Ancillary_data_v20210804"
[1] "Atm_CO2_ORCA025-GEOMAR_1_1980-2018_v20210804.nc"
[1] "planktom12_ancillary_data_v20220404"
[1] "Atm_CO2_PlankTOM12_v20220404.nc"
atm_co2 <- atm_co2 %>%
  mutate(year = round(year)) %>%
  filter(year > 1979, year < 2019) %>%
  group_by(model, year) %>%
  summarise(Atm_CO2 = mean(Atm_CO2)) %>%
  ungroup()

atm_co2 <- atm_co2 %>%
  mutate(
    model = str_remove(model, "Ancillary_data_"),
    model = str_remove(model, "ancillary_data_")
  )

2 Time series

atm_co2 %>% 
  ggplot(aes(year, Atm_CO2, col = model)) +
  geom_path() +
  geom_point() +
  scale_color_brewer(palette = "Dark2") +
  theme(legend.position = "bottom",
        legend.direction = "vertical")

Version Author Date
e829a11 jens-daniel-mueller 2022-07-05
1e7641d jens-daniel-mueller 2022-05-12
06054b2 jens-daniel-mueller 2022-05-10

3 Write files

atm_co2 %>%
  group_by(model) %>%
  group_walk( ~ write_csv(.x, paste0(
    path_preprocessing,
    .y$model,
    "_co2_atm.csv"
  )))

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] lubridate_1.8.0    geomtextpath_0.1.0 colorspace_2.0-2   marelac_2.1.10    
 [9] shape_1.4.6        ggforce_0.3.3      metR_0.11.0        scico_1.3.0       
[13] patchwork_1.1.1    collapse_1.7.0     forcats_0.5.1      stringr_1.4.0     
[17] dplyr_1.0.7        purrr_0.3.4        readr_2.1.1        tidyr_1.1.4       
[21] tibble_3.1.6       ggplot2_3.3.5      tidyverse_1.3.1    workflowr_1.7.0   

loaded via a namespace (and not attached):
 [1] ellipsis_0.3.2     class_7.3-20       rprojroot_2.0.2    fs_1.5.2          
 [5] rstudioapi_0.13    proxy_0.4-26       farver_2.1.0       bit64_4.0.5       
 [9] fansi_1.0.2        xml2_1.3.3         ncdf4_1.19         knitr_1.37        
[13] polyclip_1.10-0    jsonlite_1.7.3     gsw_1.0-6          broom_0.7.11      
[17] dbplyr_2.1.1       compiler_4.1.2     httr_1.4.2         backports_1.4.1   
[21] assertthat_0.2.1   fastmap_1.1.0      cli_3.1.1          later_1.3.0       
[25] tweenr_1.0.2       htmltools_0.5.2    tools_4.1.2        gtable_0.3.0      
[29] glue_1.6.0         Rcpp_1.0.8         cellranger_1.1.0   jquerylib_0.1.4   
[33] RNetCDF_2.5-2      vctrs_0.3.8        lwgeom_0.2-8       xfun_0.29         
[37] ps_1.6.0           rvest_1.0.2        lifecycle_1.0.1    ncmeta_0.3.0      
[41] oce_1.5-0          getPass_0.2-2      MASS_7.3-55        scales_1.1.1      
[45] vroom_1.5.7        hms_1.1.1          promises_1.2.0.1   parallel_4.1.2    
[49] RColorBrewer_1.1-2 yaml_2.2.1         sass_0.4.0         stringi_1.7.6     
[53] highr_0.9          e1071_1.7-9        checkmate_2.0.0    rlang_1.0.2       
[57] pkgconfig_2.0.3    systemfonts_1.0.3  evaluate_0.14      SolveSAPHE_2.1.0  
[61] labeling_0.4.2     bit_4.0.4          processx_3.5.2     tidyselect_1.1.1  
[65] seacarb_3.3.0      magrittr_2.0.1     R6_2.5.1           generics_0.1.1    
[69] DBI_1.1.2          pillar_1.6.4       haven_2.4.3        whisker_0.4       
[73] withr_2.4.3        units_0.7-2        modelr_0.1.8       crayon_1.4.2      
[77] KernSmooth_2.23-20 utf8_1.2.2         tzdb_0.2.0         rmarkdown_2.11    
[81] grid_4.1.2         readxl_1.3.1       data.table_1.14.2  callr_3.7.0       
[85] git2r_0.29.0       reprex_2.0.1       digest_0.6.29      classInt_0.4-3    
[89] httpuv_1.6.5       textshaping_0.3.6  munsell_0.5.0      bslib_0.3.1