Last updated: 2024-03-12

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 8c60127. 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

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/pCO2_products.Rmd) and HTML (docs/pCO2_products.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 8c60127 jens-daniel-mueller 2024-03-12 quadratic regression model added
html 0473a50 jens-daniel-mueller 2024-03-12 Build site.
Rmd cab2d84 jens-daniel-mueller 2024-03-12 regression trends in annual and monthly means
html f3b86fa jens-daniel-mueller 2024-03-12 Build site.
Rmd d0a504d jens-daniel-mueller 2024-03-12 biome seasonality plots
html 3f11106 jens-daniel-mueller 2024-03-12 Build site.
Rmd 65f52e0 jens-daniel-mueller 2024-03-12 all climatology and anomaly maps
html cfe3967 jens-daniel-mueller 2024-03-11 Build site.
Rmd a67e799 jens-daniel-mueller 2024-03-11 regional analysis for SOM-FFN started
html 45a623c jens-daniel-mueller 2024-03-11 Build site.
Rmd f4af74f jens-daniel-mueller 2024-03-11 started pCO2 products analysis

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

path_pCO2_products <-
  "/nfs/kryo/work/datasets/gridded/ocean/2d/observation/pco2/"

path_reccap2 <-
  "/nfs/kryo/work/datasets/gridded/ocean/interior/reccap2/"
region_masks_all <-
  read_ncdf(
    paste(
      path_reccap2,
      "supplementary/RECCAP2_region_masks_all_v20221025.nc",
      sep = ""
    )
  ) %>%
  as_tibble()
library(ncdf4)
nc <-
  nc_open(paste0(
    path_pCO2_products,
    "VLIZ-SOM_FFN/VLIZ-SOM_FFN_vBAMS2024.nc"
  ))

print(nc)
SOM_FFN <-
  read_ncdf(
    paste0(
      path_pCO2_products,
      "VLIZ-SOM_FFN/VLIZ-SOM_FFN_vBAMS2024.nc"
    ),
    var = c("dco2", "atm_co2", "sol", "kw", "spco2_smoothed", "fgco2_smoothed"),
    make_units = FALSE
  )

SOM_FFN <- SOM_FFN %>%
  as_tibble()

SOM_FFN <-
  SOM_FFN %>%
  mutate(across(dco2:fgco2_smoothed, ~ replace(., . >= 1e+19, NA)))

SOM_FFN <-
  SOM_FFN %>%
  mutate(area = earth_surf(lat, lon),
         year = year(time),
         month = month(time))

SOM_FFN <-
  SOM_FFN %>% 
  mutate(lon = if_else(lon < 0, lon + 360, lon))

Biome mask

land_mask <- region_masks_all %>%
  filter(seamask == 0)

map <- ggplot(land_mask,
              aes(lon, lat)) +
  geom_tile(fill = "grey80") +
  coord_quickmap(expand = 0) +
  theme(axis.title = element_blank())


region_masks_all <- region_masks_all %>%
  filter(seamask == 1) %>% 
  select(lon, lat, atlantic:southern) %>% 
  pivot_longer(atlantic:southern,
               names_to = "region",
               values_to = "biome") %>%
  mutate(biome = as.character(biome))

region_masks_all <- region_masks_all %>%
  filter(biome != "0")

region_masks_all <- region_masks_all %>%
  mutate(biome = paste(region, biome, sep = "_"))


# map +
#   geom_raster(data = region_masks_all,
#               aes(lon, lat, fill = biome))


region_masks_all <- region_masks_all  %>% 
  mutate(biome = case_when(
    biome == "atlantic_1" ~ "NA-SPSS",
    biome == "atlantic_2" ~ "NA-STSS",
    biome == "atlantic_3" ~ "NA-STPS",
    biome == "atlantic_4" ~ "AEQU",
    biome == "atlantic_5" ~ "SA-STPS",
    biome == "atlantic_6" ~ "MED",
    biome == "pacific_1" ~ "NP-SPSS",
    biome == "pacific_2" ~ "NP-STSS",
    biome == "pacific_3" ~ "NP-STPS",
    biome == "pacific_4" ~ "PEQU-W",
    biome == "pacific_5" ~ "PEQU-E",
    biome == "pacific_6" ~ "SP-STSS",
    biome == "indian_1" ~ "Arabian Sea",
    biome == "indian_2" ~ "Bay of Bengal",
    biome == "indian_3" ~ "Equatorial Indian",
    biome == "indian_4" ~ "Southern Indian",
    # biome == "arctic_1" ~ "ARCTIC-ICE",
    # biome == "arctic_2" ~ "NP-ICE",
    # biome == "arctic_3" ~ "NA-ICE",
    # biome == "arctic_4" ~ "Barents",
    str_detect(biome, "arctic") ~ "Arctic",
    biome == "southern_1" ~ "SO-STSS",
    biome == "southern_2" ~ "SO-SPSS",
    biome == "southern_3" ~ "SO-ICE",
    TRUE ~ "other"
  ))

region_masks_all <-
  region_masks_all %>%
  filter(biome != "other")


map +
  geom_tile(data = region_masks_all,
            aes(lon, lat, fill = region)) +
  scale_fill_muted()

Version Author Date
3f11106 jens-daniel-mueller 2024-03-12
region_masks_all %>%
  group_split(region) %>%
  # head(2) %>%
  map(~ map +
        geom_tile(data = .x,
                    aes(lon, lat, fill = biome)) +
        labs(title = .x$region) +
        scale_fill_okabeito())
[[1]]

Version Author Date
3f11106 jens-daniel-mueller 2024-03-12

[[2]]

Version Author Date
3f11106 jens-daniel-mueller 2024-03-12

[[3]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[4]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[5]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12
key_biomes <- c("global",
                "NA-SPSS",
                "NA-STPS",
                "NP-SPSS",
                "PEQU-E",
                "SO-SPSS")


map +
  geom_tile(data = region_masks_all %>% filter(biome %in% key_biomes),
            aes(lon, lat, fill = biome)) +
  labs(title = "Selected key biomes") +
  scale_fill_muted()

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

pCO2 products

Climatology maps

SOM_FFN_annual_mean_maps <-
  SOM_FFN %>%
  group_by(year, lon, lat) %>%
  summarise(across(dco2:fgco2_smoothed,
                   ~ mean(.))) %>%
  ungroup()

SOM_FFN_climatology <-
  SOM_FFN_annual_mean_maps %>%
  filter(year >= 1990,
         year <= 2022) %>%
  group_by(lon, lat) %>%
  summarise(across(dco2:fgco2_smoothed,
                   ~ mean(.))) %>%
  ungroup()

SOM_FFN_2023_anomaly <-
  bind_rows(
    SOM_FFN_climatology %>% mutate(reference = "climatology"),
    SOM_FFN_annual_mean_maps %>%
      filter(year == 2023) %>%
      select(-year) %>% 
      mutate(reference = "2023")
  )

SOM_FFN_2023_anomaly <-
  SOM_FFN_2023_anomaly %>%
  pivot_longer(-c(lon, lat, reference)) %>%
  pivot_wider(names_from = reference,
              values_from = value) %>%
  mutate(anomaly = `2023` - climatology)

SOM_FFN_2023_anomaly %>%
  group_split(name) %>%
  # head(1) %>%
  map(~ map +
        geom_tile(data = .x,
                  aes(lon, lat, fill = climatology)) +
        labs(title = .x$name) +
        scale_fill_viridis_c())
[[1]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[2]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[3]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[4]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[5]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[6]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

Anomaly maps

SOM_FFN_2023_anomaly %>%
  group_split(name) %>%
  # head(1) %>%
  map(~ map +
        geom_tile(data = .x,
                  aes(lon, lat, fill = anomaly)) +
        labs(title = .x$name) +
        scale_fill_divergent())
[[1]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[2]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[3]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[4]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[5]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[6]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

Regional means and integrals

SOM_FFN <-
  inner_join(SOM_FFN,
             region_masks_all)

SOM_FFN_monthly_global <-
  SOM_FFN %>%
  group_by(time) %>% 
  summarise(across(dco2:spco2_smoothed, 
                   ~weighted.mean(., area, na.rm = TRUE)),
            across(fgco2_smoothed, 
                   ~sum(. * area, na.rm = TRUE) * 12.01 * 1e-15)) %>% 
  ungroup()

SOM_FFN_monthly_biome <-
  SOM_FFN %>%
  group_by(time, region, biome) %>% 
  summarise(across(dco2:spco2_smoothed, 
                   ~weighted.mean(., area, na.rm = TRUE)),
            across(fgco2_smoothed, 
                   ~sum(. * area, na.rm = TRUE) * 12.01 * 1e-15)) %>% 
  ungroup()
  
SOM_FFN_monthly <- 
  bind_rows(SOM_FFN_monthly_global %>% 
              mutate(biome = "global",
                     region = "global"),
            SOM_FFN_monthly_biome)

rm(SOM_FFN_monthly_global,
   SOM_FFN_monthly_biome)


SOM_FFN_monthly <-
SOM_FFN_monthly %>%
  mutate(year = year(time),
         month = month(time),
         .after = time)

SOM_FFN_monthly <-
  SOM_FFN_monthly %>%
  pivot_longer(-c(time:month, biome, region))

Seasonality

SOM_FFN_monthly %>%
  filter(biome %in% key_biomes) %>%
  ggplot(aes(month, value, group = as.factor(year))) +
  geom_path(data = . %>% filter(year < 2022),
            aes(col = year)) +
  scale_color_grayC() +
  new_scale_color() +
  geom_path(data = . %>% filter(year >= 2022),
            aes(col = as.factor(year)),
            linewidth = 1) +
  scale_color_manual(values = c("orange", "red"),
                     guide = guide_legend(reverse = TRUE,
                                          order = 1)) +
  scale_x_continuous(breaks = seq(1, 12, 3), expand = c(0, 0)) +
  facet_grid(name ~ biome, scales = "free_y") +
  theme(legend.title = element_blank(),
        axis.title.y = element_blank())

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12
SOM_FFN_monthly %>%
  filter(biome %in% key_biomes) %>%
  group_split(biome) %>%
  # head(1) %>%
  map(
    ~ ggplot(data = .x,
             aes(month, value, group = as.factor(year))) +
      geom_path(data = . %>% filter(year < 2022),
                aes(col = year)) +
      scale_color_grayC() +
      new_scale_color() +
      geom_path(
        data = . %>% filter(year >= 2022),
        aes(col = as.factor(year)),
        linewidth = 1
      ) +
      scale_color_manual(
        values = c("orange", "red"),
        guide = guide_legend(reverse = TRUE,
                             order = 1)
      ) +
      scale_x_continuous(breaks = seq(1, 12, 3), expand = c(0, 0)) +
      facet_grid(name ~ biome, scales = "free_y") +
      theme(legend.title = element_blank(),
            axis.title.y = element_blank())
  )
[[1]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[2]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[3]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[4]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[5]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12

[[6]]

Version Author Date
f3b86fa jens-daniel-mueller 2024-03-12