Last updated: 2024-03-13

Checks: 7 0

Knit directory: heatwave_co2_flux_2023/

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(20240307) 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 39cd191. 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/Workflowr_project_managment.R

Unstaged changes:
    Modified:   .gitignore
    Modified:   analysis/_site.yml
    Deleted:    analysis/about.Rmd
    Deleted:    analysis/license.Rmd
    Modified:   analysis/pCO2_products.Rmd

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/atm_co2.Rmd) and HTML (docs/atm_co2.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 86b52e9 jens-daniel-mueller 2024-03-13 Build site.
html 1e3279c jens-daniel-mueller 2024-03-12 Build site.
html ff205b8 jens-daniel-mueller 2024-03-12 Build site.
html e760672 jens-daniel-mueller 2024-03-12 Build site.
html caeb7f1 jens-daniel-mueller 2024-03-12 Build site.
html b6c0bec jens-daniel-mueller 2024-03-12 Build site.
html 3f69dc8 jens-daniel-mueller 2024-03-12 Build site.
html 0473a50 jens-daniel-mueller 2024-03-12 Build site.
html f3b86fa jens-daniel-mueller 2024-03-12 Build site.
html 3f11106 jens-daniel-mueller 2024-03-12 Build site.
html cfe3967 jens-daniel-mueller 2024-03-11 Build site.
html 45a623c jens-daniel-mueller 2024-03-11 Build site.
Rmd f4af74f jens-daniel-mueller 2024-03-11 started pCO2 products analysis
html 41d435b jens-daniel-mueller 2024-03-11 Build site.
Rmd 8ac0750 jens-daniel-mueller 2024-03-11 included setup source functions
html 581fb88 jens-daniel-mueller 2024-03-08 Build site.
Rmd af44790 jens-daniel-mueller 2024-03-08 atm co2 2023 prediction
html a2ce6d8 jens-daniel-mueller 2024-03-07 Build site.
Rmd 36de8c8 jens-daniel-mueller 2024-03-07 atm co2 2023 prediction
html 5ac6300 jens-daniel-mueller 2024-03-07 Build site.
Rmd dda379e jens-daniel-mueller 2024-03-07 atm co2 data added
html 7d24a99 jens-daniel-mueller 2024-03-07 Build site.
html a9267cc jens-daniel-mueller 2024-03-07 Build site.
Rmd 694c584 jens-daniel-mueller 2024-03-07 added atm co2

center <- -160
boundary <- center + 180
target_crs <- paste0("+proj=robin +over +lon_0=", center)
# target_crs <- paste0("+proj=eqearth +over +lon_0=", center)
# target_crs <- paste0("+proj=eqearth +lon_0=", center)
# target_crs <- paste0("+proj=igh_o +lon_0=", center)

worldmap <- ne_countries(scale = 'small',
                         type = 'map_units',
                         returnclass = 'sf')

worldmap <- worldmap %>% st_break_antimeridian(lon_0 = center)
worldmap_trans <- st_transform(worldmap, crs = target_crs)

# ggplot() +
#   geom_sf(data = worldmap_trans)

coastline <- ne_coastline(scale = 'small', returnclass = "sf")
coastline <- st_break_antimeridian(coastline, lon_0 = 200)
coastline_trans <- st_transform(coastline, crs = target_crs)

# ggplot() +
#   geom_sf(data = worldmap_trans, fill = "grey", col="grey") +
#   geom_sf(data = coastline_trans)


bbox <- st_bbox(c(xmin = -180, xmax = 180, ymax = 65, ymin = -78), crs = st_crs(4326))
bbox <- st_as_sfc(bbox)
bbox_trans <- st_break_antimeridian(bbox, lon_0 = center)

bbox_graticules <- st_graticule(
  x = bbox_trans,
  crs = st_crs(bbox_trans),
  datum = st_crs(bbox_trans),
  lon = c(20, 20.001),
  lat = c(-78,65),
  ndiscr = 1e3,
  margin = 0.001
)

bbox_graticules_trans <- st_transform(bbox_graticules, crs = target_crs)
rm(worldmap, coastline, bbox, bbox_trans)

# ggplot() +
#   geom_sf(data = worldmap_trans, fill = "grey", col="grey") +
#   geom_sf(data = coastline_trans) +
#   geom_sf(data = bbox_graticules_trans)

lat_lim <- ext(bbox_graticules_trans)[c(3,4)]*1.002
lon_lim <- ext(bbox_graticules_trans)[c(1,2)]*1.005

# ggplot() +
#   geom_sf(data = worldmap_trans, fill = "grey90", col = "grey90") +
#   geom_sf(data = coastline_trans) +
#   geom_sf(data = bbox_graticules_trans, linewidth = 1) +
#   coord_sf(crs = target_crs,
#            ylim = lat_lim,
#            xlim = lon_lim,
#            expand = FALSE) +
#   theme(
#     panel.border = element_blank(),
#     axis.text = element_blank(),
#     axis.ticks = element_blank()
#   )

latitude_graticules <- st_graticule(
  x = bbox_graticules,
  crs = st_crs(bbox_graticules),
  datum = st_crs(bbox_graticules),
  lon = c(20, 20.001),
  lat = c(-60,-30,0,30,60),
  ndiscr = 1e3,
  margin = 0.001
)

latitude_graticules_trans <- st_transform(latitude_graticules, crs = target_crs)

latitude_labels <- data.frame(lat_label = c("60°N","30°N","Eq.","30°S","60°S"),
                 lat = c(60,30,0,-30,-60)-4, lon = c(35)-c(0,2,4,2,0))

latitude_labels <- st_as_sf(x = latitude_labels,
               coords = c("lon", "lat"),
               crs = "+proj=longlat")

latitude_labels_trans <- st_transform(latitude_labels, crs = target_crs)

# ggplot() +
#   geom_sf(data = worldmap_trans, fill = "grey", col = "grey") +
#   geom_sf(data = coastline_trans) +
#   geom_sf(data = bbox_graticules_trans) +
#   geom_sf(data = latitude_graticules_trans,
#           col = "grey60",
#           linewidth = 0.2) +
#   geom_sf_text(data = latitude_labels_trans,
#                aes(label = lat_label),
#                size = 3,
#                col = "grey60")

Read data

co2_mm_gl <- read_csv("data/co2_mm_gl.csv", 
    skip = 38)

global_co2_merged <- read_table("data/global_co2_merged.txt", 
    comment = "!",
    col_names = c("decimal", "average"))


atm_co2 <-
  bind_rows(
    co2_mm_gl %>%
      select(decimal, average) %>%
      mutate(source = "NOAA - Global marine surface"),
    global_co2_merged %>%
      mutate(source = "GCB - MLO & SPO")
  )

atm_co2 <- 
atm_co2 %>% 
  mutate(date = date_decimal(decimal),
         year = year(date),
         month = month(date))
atm_co2 %>% 
  filter(decimal > 2010) %>% 
  ggplot(aes(decimal, average, col = source)) +
  geom_path() +
  geom_point() +
  labs(y = expression(Atm.~CO[2]~(ppm))) +
  geom_smooth(method = "lm", se = FALSE) +
  scale_color_okabeito() +
  theme_bw() +
  scale_x_continuous(breaks = seq(1900,2100,2)) +
  theme(axis.title.x = element_blank(),
        legend.title = element_blank(),
        legend.position = c(0.8,0.2))

Version Author Date
5ac6300 jens-daniel-mueller 2024-03-07
atm_co2 <-
  atm_co2 %>%
  filter(year < 2023 | source != "GCB - MLO & SPO")

atm_co2 <-
  atm_co2 %>%
  group_by(year, source) %>%
  mutate(annual_mean = mean(average)) %>%
  ungroup() %>%
  mutate(monthly_anomaly = average - annual_mean)

atm_co2 %>% 
  filter(decimal > 2013,
         decimal < 2023) %>%
  ggplot(aes(month, monthly_anomaly, col = source, group = interaction(source, year))) +
  geom_path() +
  geom_point() +
  labs(y = expression(Monthly~anomaly~from~annual~mean~(ppm)),
       title = expression(Atmospheric~CO[2]~seasonality),
       subtitle = "2013 - 2022") +
  scale_color_manual(values = c("#000000", "#E69F00", "#56B4E9")) +
  theme_bw() +
  scale_x_continuous(breaks = seq(1,12,1), expand = c(0.01,0)) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3,0.2))

Version Author Date
581fb88 jens-daniel-mueller 2024-03-08
a2ce6d8 jens-daniel-mueller 2024-03-07
ggsave(
  here::here(
    paste0(
      "output/atm_CO2_seasonality.png"
    )
  ),
  width = 6,
  height = 4,
  dpi = 600,
  bg = "white"
)


atm_co2 %>% 
  filter(decimal > 1980,
         decimal < 2023) %>% 
  ggplot(aes(month, monthly_anomaly, group = interaction(year), col = year)) +
  geom_path() +
  geom_point() +
  labs(y = expression(Monthly~anomaly~atm.~CO[2]~(ppm))) +
  scale_color_viridis_c() +
  theme_bw() +
  scale_x_continuous(breaks = seq(1,12,3)) +
  facet_wrap(~ source) +
  theme(legend.title = element_blank())

Version Author Date
a2ce6d8 jens-daniel-mueller 2024-03-07
atm_co2_monthly_anomaly <-
  atm_co2 %>%
  filter(decimal > 2013,
         decimal < 2023) %>%
  group_by(source, month) %>%
  summarise(monthly_anomaly = mean(monthly_anomaly),
            decimal_mean = mean(decimal - year)) %>%
  ungroup()


atm_co2_annual_means <-
  atm_co2 %>%
  group_by(source, year) %>%
  summarise(annual_mean = mean(average)) %>%
  ungroup()

atm_co2_annual_means %>% 
  filter(year >= 2013,
         year <= 2022) %>% 
  group_by(source) %>%
  summarise(long_term_mean = mean(annual_mean)) %>%
  ungroup() %>% 
  pull(long_term_mean)
[1] 405.7722 406.2577
annual_mean_2023_predicted <-
  atm_co2 %>%
  filter(decimal > 2013,
         decimal < 2023) %>%
  group_by(source, year) %>%
  summarise(annual_mean = mean(average)) %>%
  ungroup() %>%
  nest(data = -source) %>%
  mutate(fit = map(data, ~ lm(annual_mean ~ year, data = .x)),
         tidied = map(fit, tidy)) %>%
  unnest(tidied) %>%
  select(source, term, estimate) %>%
  pivot_wider(names_from = term,
              values_from = estimate) %>%
  mutate(annual_mean = `(Intercept)` + year * 2023) %>%
  filter(source == "GCB - MLO & SPO") %>%
  pull(annual_mean)

  
atm_co2_monthly_anomaly <-
  atm_co2_monthly_anomaly %>%
  filter(source == "GCB - MLO & SPO") %>%
  mutate(
    year = 2023,
    decimal = year + decimal_mean,
    annual_mean = annual_mean_2023_predicted,
    average =  annual_mean + monthly_anomaly,
    source = "GCB - MLO & SPO (linear prediction)",
    date = date_decimal(decimal)
  ) %>%
  select(-decimal_mean)


atm_co2_predicted <-
  bind_rows(atm_co2 %>% filter(year < 2023 |
                                 source != "GCB - MLO & SPO"),
            atm_co2_monthly_anomaly)

atm_co2_annual_means %>% 
  filter(year > 2021)
# A tibble: 3 × 3
  source                        year annual_mean
  <chr>                        <dbl>       <dbl>
1 GCB - MLO & SPO               2022        416.
2 NOAA - Global marine surface  2022        417.
3 NOAA - Global marine surface  2023        419.
atm_co2_predicted %>% 
  filter(decimal > 2013) %>% 
  ggplot() +
  geom_path(aes(decimal, average, col = source)) +
  geom_point(aes(decimal, average, col = source)) +
  geom_path(aes(decimal, annual_mean, col = source, group = interaction(source, year),
                linetype = "annual mean")) +
  scale_linetype_manual(values = 2) +
  labs(y = expression(CO[2]~(ppm)),
       title = expression(Atmospheric~CO[2]~timeseries),
       subtitle = "2013 - 2022") +
  scale_color_manual(values = c("#000000", "#56B4E9", "#E69F00")) +
  theme_bw() +
  scale_x_continuous(breaks = seq(1900,2100,2), expand = c(0.01,0)) +
  theme(axis.title.x = element_blank(),
        legend.title = element_blank(),
        legend.position = c(0.3,0.7))

Version Author Date
581fb88 jens-daniel-mueller 2024-03-08
a2ce6d8 jens-daniel-mueller 2024-03-07
ggsave(
  here::here(
    paste0(
      "output/atm_CO2_timeseries.png"
    )
  ),
  width = 6,
  height = 4,
  dpi = 600,
  bg = "white"
)

sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: openSUSE Leap 15.5

Matrix products: default
BLAS:   /usr/local/R-4.2.2/lib64/R/lib/libRblas.so
LAPACK: /usr/local/R-4.2.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] broom_1.0.5         khroma_1.9.0        lubridate_1.9.0    
 [4] timechange_0.1.1    terra_1.7-65        sf_1.0-9           
 [7] rnaturalearth_0.1.0 geomtextpath_0.1.1  colorspace_2.0-3   
[10] marelac_2.1.10      shape_1.4.6         ggforce_0.4.1      
[13] metR_0.13.0         scico_1.3.1         patchwork_1.1.2    
[16] collapse_1.8.9      forcats_0.5.2       stringr_1.5.0      
[19] dplyr_1.1.3         purrr_1.0.2         readr_2.1.3        
[22] tidyr_1.3.0         tibble_3.2.1        ggplot2_3.4.4      
[25] tidyverse_1.3.2     workflowr_1.7.0    

loaded via a namespace (and not attached):
  [1] googledrive_2.0.0       ellipsis_0.3.2          class_7.3-20           
  [4] rprojroot_2.0.3         fs_1.5.2                rstudioapi_0.15.0      
  [7] proxy_0.4-27            farver_2.1.1            bit64_4.0.5            
 [10] fansi_1.0.3             xml2_1.3.3              splines_4.2.2          
 [13] codetools_0.2-18        cachem_1.0.6            knitr_1.41             
 [16] polyclip_1.10-4         jsonlite_1.8.3          gsw_1.1-1              
 [19] dbplyr_2.2.1            compiler_4.2.2          httr_1.4.4             
 [22] backports_1.4.1         Matrix_1.5-3            assertthat_0.2.1       
 [25] fastmap_1.1.0           gargle_1.2.1            cli_3.6.1              
 [28] later_1.3.0             tweenr_2.0.2            htmltools_0.5.3        
 [31] tools_4.2.2             rnaturalearthdata_0.1.0 gtable_0.3.1           
 [34] glue_1.6.2              Rcpp_1.0.11             cellranger_1.1.0       
 [37] jquerylib_0.1.4         vctrs_0.6.4             nlme_3.1-160           
 [40] xfun_0.35               ps_1.7.2                rvest_1.0.3            
 [43] lifecycle_1.0.3         googlesheets4_1.0.1     oce_1.7-10             
 [46] getPass_0.2-2           MASS_7.3-58.1           scales_1.2.1           
 [49] vroom_1.6.0             ragg_1.2.4              hms_1.1.2              
 [52] promises_1.2.0.1        parallel_4.2.2          yaml_2.3.6             
 [55] memoise_2.0.1           sass_0.4.4              stringi_1.7.8          
 [58] highr_0.9               e1071_1.7-12            checkmate_2.1.0        
 [61] rlang_1.1.1             pkgconfig_2.0.3         systemfonts_1.0.4      
 [64] evaluate_0.18           lattice_0.20-45         SolveSAPHE_2.1.0       
 [67] labeling_0.4.2          bit_4.0.5               processx_3.8.0         
 [70] tidyselect_1.2.0        here_1.0.1              seacarb_3.3.1          
 [73] magrittr_2.0.3          R6_2.5.1                generics_0.1.3         
 [76] DBI_1.1.3               mgcv_1.8-41             pillar_1.9.0           
 [79] haven_2.5.1             whisker_0.4             withr_2.5.0            
 [82] units_0.8-0             sp_1.5-1                modelr_0.1.10          
 [85] crayon_1.5.2            KernSmooth_2.23-20      utf8_1.2.2             
 [88] tzdb_0.3.0              rmarkdown_2.18          grid_4.2.2             
 [91] readxl_1.4.1            data.table_1.14.6       callr_3.7.3            
 [94] git2r_0.30.1            reprex_2.0.2            digest_0.6.30          
 [97] classInt_0.4-8          httpuv_1.6.6            textshaping_0.3.6      
[100] munsell_0.5.0           viridisLite_0.4.1       bslib_0.4.1