Last updated: 2022-01-07

Checks: 7 0

Knit directory: bgc_argo_r_argodata/

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(20211008) 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 e9ad067. 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:    output/

Unstaged changes:
    Modified:   analysis/loading_data.Rmd
    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/extreme_pH.Rmd) and HTML (docs/extreme_pH.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 e9ad067 jens-daniel-mueller 2022-01-07 code review
html 343689f pasqualina-vonlanthendinenna 2022-01-06 Build site.
Rmd f53cc2d pasqualina-vonlanthendinenna 2022-01-06 updated profile page
html b8a6482 pasqualina-vonlanthendinenna 2022-01-03 Build site.
Rmd 054f8a6 pasqualina-vonlanthendinenna 2022-01-03 added Argo profiles

Task

Compare depth profiles of normal pH and of extreme pH, as identified in the surface OceanSODA pH data product

theme_set(theme_bw())
HNL_colors <- c("H" = "#b2182b",
                "N" = "#636363",
                "L" = "#2166ac")

Load data

path_argo <- '/nfs/kryo/work/updata/bgc_argo_r_argodata'
path_argo_preprocessed <- paste0(path_argo, "/preprocessed_bgc_data")
path_emlr_utilities <- "/nfs/kryo/work/jenmueller/emlr_cant/utilities/files/"
# RECCAP2-ocean region mask
region_masks_all_1x1 <- read_rds(file = paste0(path_argo_preprocessed,
                                               "/region_masks_all_1x1.rds"))

region_masks_all_1x1 <- region_masks_all_1x1 %>%
  rename(biome = value) %>% 
  filter(region == 'southern',
         biome != 0) %>% 
  select(-region) %>% 
  mutate(coast = as.character(coast))

# WOA 18 basin mask

basinmask <-
  read_csv(
    paste(path_emlr_utilities,
          "basin_mask_WOA18.csv",
          sep = ""),
    col_types = cols("MLR_basins" = col_character())
  )

basinmask <- basinmask %>%
  filter(MLR_basins == unique(basinmask$MLR_basins)[1]) %>%
  select(lon, lat, basin_AIP)


# OceanSODA
OceanSODA <- read_rds(file = paste0(path_argo_preprocessed, "/OceanSODA.rds"))

OceanSODA <- OceanSODA %>%
  mutate(month = month(date))

# load in the full argo data
full_argo <- read_rds(file = paste0(path_argo_preprocessed, "/bgc_merge_pH_qc_1.rds"))

# change the date format for compatibility with OceanSODA pH data
full_argo <- full_argo %>%
  mutate(year = year(date),
         month = month(date)) %>%
  mutate(date = ymd(format(date, "%Y-%m-15")))

Regions

Biomes

basemap(limits = -32) +
  geom_spatial_tile(
    data = region_masks_all_1x1,
    aes(x = lon,
        y = lat,
        fill = biome),
    col = 'transparent'
  ) +
  scale_fill_brewer(palette = "Dark2")

Coast

basemap(limits = -32) +
  geom_spatial_tile(
    data = region_masks_all_1x1,
    aes(x = lon,
        y = lat,
        fill = coast),
    col = 'transparent'
  ) +
  scale_fill_brewer(palette = "Dark2")

Apply region masks

region_masks_all_1x1 <- region_masks_all_1x1 %>% 
  filter(coast == "0")
# keep only Southern Ocean data
OceanSODA_SO <- inner_join(region_masks_all_1x1, OceanSODA)

# add in basin separations
OceanSODA_SO <- inner_join(OceanSODA_SO, basinmask)

# keep only Southern Ocean argo data
full_argo_SO <- inner_join(full_argo, region_masks_all_1x1)

# add in basin separations
full_argo_SO <- inner_join(full_argo_SO, basinmask)

OceanSODA pH anomalies

Grid level

Climatological thresholds

Climatological monthly OceanSODA pH and the 5th and 95th percentiles, calculated for 2013-2021, with the full spatial OceanSODA data

# calculate climatological average OceanSODA pH
# and the 95th percentile of the monthly OceanSODA pH

OceanSODA_SO_clim_grid <- OceanSODA_SO %>%
  group_by(lon, lat, month) %>%
  summarise(
    ph_mean = mean(ph_total, na.rm = TRUE),
    ph_threshold_high = quantile(ph_total, 0.95, na.rm = TRUE),
    ph_threshold_low = quantile(ph_total, 0.05, na.rm = TRUE)
  ) %>%
  ungroup()

OceanSODA_SO_extreme_grid <- inner_join(OceanSODA_SO, OceanSODA_SO_clim_grid)

Anomaly identification

Calculate OceanSODA pH anomalies: L for abnormally low, H for abnormally high, N for normal pH

# when the in-situ OceanSODA pH is lower than the 5th percentile, assign 'L' for low extreme
# when the in-situ OceanSODA pH exceeds the 95th percentile, assign 'H' for high extreme
# when the in-situ OceanSODA pH is within 95% of the range, then assign 'N' for normal pH
OceanSODA_SO_extreme_grid <- OceanSODA_SO_extreme_grid %>%
  mutate(
    ph_extreme = case_when(
      ph_total < ph_threshold_low ~ 'L',
      ph_total > ph_threshold_high ~ 'H',
      TRUE ~ 'N'
    )
  ) %>%
  drop_na()

OceanSODA_SO_extreme_grid <- OceanSODA_SO_extreme_grid %>%
  mutate(ph_extreme = fct_relevel(ph_extreme, "H", "N", "L"))
OceanSODA_SO_extreme_grid %>%
  group_split(lon, lat, month) %>%
  head(6) %>%
  map(~ ggplot(data = .x) +
        geom_hline(aes(yintercept = ph_threshold_high), linetype = 2) +
        geom_hline(aes(yintercept = ph_threshold_low), linetype = 2) +
        geom_hline(aes(yintercept = ph_mean)) +
        geom_point(
          aes(x = year, y = ph_total, col = ph_extreme)) +
        labs(title = paste(
          "lon:", unique(.x$lon),
          "| lat:", unique(.x$lat),
          "| month:", unique(.x$month)
          )) +
        scale_color_manual(values = HNL_colors))
[[1]]


[[2]]


[[3]]


[[4]]


[[5]]


[[6]]

Anomaly maps

Location of OceanSODA pH extremes

OceanSODA_SO_extreme_grid %>% 
  group_split(year) %>% 
  # head(1) %>%
  map(
    ~ basemap(limits = -32, data = .x)+
      geom_spatial_tile(data = .x,
                        aes(x = lon,
                            y = lat,
                            fill = ph_extreme),
                        linejoin = 'mitre',
                        col = 'transparent',
                        detail = 60
                        ) +
      scale_fill_manual(values = HNL_colors) +
      facet_wrap(~month, ncol = 2)+
      labs(title = paste("Year:", unique(.x$year)),
           fill = 'pH')
  )
[[1]]


[[2]]


[[3]]


[[4]]


[[5]]


[[6]]


[[7]]


[[8]]

Anomaly time series

# calculate a regional mean pH for each biome, basin, and ph extreme (H/L/N) and plot a timeseries 

OceanSODA_SO_extreme_grid %>% 
  group_by(date, biome, basin_AIP, ph_extreme) %>% 
  summarise(ph_regional = mean(ph_total, na.rm = TRUE)) %>% 
  ungroup() %>% 
  ggplot(aes(x = date, y = ph_regional, col = ph_extreme))+
  geom_point(size = 0.3)+
  geom_line()+
  scale_color_manual(values = HNL_colors) +
  facet_grid(basin_AIP~biome)+
  labs(x = 'date',
       y = 'regional mean pH',
       col = 'pH anomaly') +
  theme(legend.position = 'bottom')

Anomaly histogram

OceanSODA_SO_extreme_grid %>%
  ggplot(aes(ph_total, col = ph_extreme)) +
  geom_density() +
  scale_color_manual(values = HNL_colors) +
  facet_grid(basin_AIP ~ biome) +
  coord_cartesian(xlim = c(8, 8.2)) +
  labs(x = 'date',
       y = 'regional mean pH',
       col = 'pH anomaly') +
  theme(legend.position = 'bottom')

Threshold histogram

OceanSODA_SO_clim_grid %>%
  pivot_longer(starts_with("ph_"),
               names_to = "level",
               values_to = "value") %>% 
  ggplot(aes(value, col = level)) +
  geom_density() +
  coord_cartesian(xlim = c(8, 8.2)) +
  theme(legend.position = 'bottom')

Biome level

Climatological thresholds

Climatological monthly OceanSODA pH and the 5th and 95th percentiles, calculated for 2013-2021, with the full spatial OceanSODA data

# calculate climatological average OceanSODA pH
# and the 95th percentile of the monthly OceanSODA pH

OceanSODA_SO_clim_biome <- OceanSODA_SO %>%
  group_by(biome, basin_AIP, month) %>%
  summarise(
    ph_mean = mean(ph_total, na.rm = TRUE),
    ph_threshold_high = quantile(ph_total, 0.95, na.rm = TRUE),
    ph_threshold_low = quantile(ph_total, 0.05, na.rm = TRUE)
  ) %>%
  ungroup()

OceanSODA_SO_extreme_biome <- inner_join(OceanSODA_SO, OceanSODA_SO_clim_biome)

Anomaly identification

Calculate OceanSODA pH anomalies: L for abnormally low, H for abnormally high, N for normal pH

# when the in-situ OceanSODA pH is lower than the 5th percentile, assign 'L' for low extreme
# when the in-situ OceanSODA pH exceeds the 95th percentile, assign 'H' for high extreme
# when the in-situ OceanSODA pH is within 95% of the range, then assign 'N' for normal pH
OceanSODA_SO_extreme_biome <- OceanSODA_SO_extreme_biome %>%
  mutate(
    ph_extreme = case_when(
      ph_total < ph_threshold_low ~ 'L',
      ph_total > ph_threshold_high ~ 'H',
      TRUE ~ 'N'
    )
  ) %>%
  drop_na()

OceanSODA_SO_extreme_biome <- OceanSODA_SO_extreme_biome %>%
  mutate(ph_extreme = fct_relevel(ph_extreme, "H", "N", "L"))
OceanSODA_SO_extreme_biome %>%
  group_split(biome, basin_AIP, month) %>%
  head(6) %>%
  map(~ ggplot(data = .x) +
        geom_hline(aes(yintercept = ph_threshold_high), linetype = 2) +
        geom_hline(aes(yintercept = ph_threshold_low), linetype = 2) +
        geom_hline(aes(yintercept = ph_mean)) +
        geom_point(
          aes(x = year, y = ph_total, col = ph_extreme)) +
        labs(title = paste(
          "lon:", unique(.x$biome),
          "| lat:", unique(.x$basin_AIP),
          "| month:", unique(.x$month)
          )) +
        scale_color_manual(values = HNL_colors))
[[1]]


[[2]]


[[3]]


[[4]]


[[5]]


[[6]]

Anomaly maps

Location of OceanSODA pH extremes

OceanSODA_SO_extreme_biome %>% 
  group_split(year) %>% 
  # head(1) %>%
  map(
    ~ basemap(limits = -32, data = .x)+
      geom_spatial_tile(data = .x,
                        aes(x = lon,
                            y = lat,
                            fill = ph_extreme),
                        linejoin = 'mitre',
                        col = 'transparent',
                        detail = 60
                        ) +
      scale_fill_manual(values = HNL_colors) +
      facet_wrap(~month, ncol = 2)+
      labs(title = paste("Year:", unique(.x$year)),
           fill = 'pH')
  )
[[1]]


[[2]]


[[3]]


[[4]]


[[5]]


[[6]]


[[7]]


[[8]]

Anomaly time series

# calculate a regional mean pH for each biome, basin, and ph extreme (H/L/N) and plot a timeseries 

OceanSODA_SO_extreme_biome %>% 
  group_by(date, biome, basin_AIP, ph_extreme) %>% 
  summarise(ph_regional = mean(ph_total, na.rm = TRUE)) %>% 
  ungroup() %>% 
  ggplot(aes(x = date, y = ph_regional, col = ph_extreme))+
  geom_point(size = 0.3)+
  geom_line()+
  scale_color_manual(values = HNL_colors) +
  facet_grid(basin_AIP~biome)+
  labs(x = 'date',
       y = 'regional mean pH',
       col = 'pH anomaly') +
  theme(legend.position = 'bottom')

Anomaly histogram

OceanSODA_SO_extreme_biome %>%
  ggplot(aes(ph_total, col = ph_extreme)) +
  geom_density() +
  scale_color_manual(values = HNL_colors) +
  facet_grid(basin_AIP ~ biome) +
  coord_cartesian(xlim = c(8, 8.2)) +
  labs(x = 'date',
       y = 'regional mean pH',
       col = 'pH anomaly') +
  theme(legend.position = 'bottom')

Threshold histogram

OceanSODA_SO_clim_biome %>%
  pivot_longer(starts_with("ph_"),
               names_to = "level",
               values_to = "value") %>% 
  ggplot(aes(value, col = level)) +
  geom_density() +
  coord_cartesian(xlim = c(8, 8.2)) +
  theme(legend.position = 'bottom')

Argo

Join OceanSODA

# rename OceanSODA columns
OceanSODA_SO_extreme <- OceanSODA_SO_extreme_biome %>%
  rename(OceanSODA_ph_uncert = ph_total_uncert,
         OceanSODA_ph = ph_total)

# combine the argo profile data to the surface extreme data
profile_extreme <- inner_join(full_argo_SO, OceanSODA_SO_extreme)

Mean monthly profiles

# calculate mean profiles in each basin and biome, for each month between 2014 and 2021 

profile_extreme_monthly <- profile_extreme %>% 
  mutate(depth = cut(depth, seq(0,2000,10), seq(5,2000,10)),
         depth = as.numeric(as.character(depth))) %>%
  group_by(month, biome, basin_AIP, ph_extreme, depth) %>% 
  summarise(mean_ph = mean(ph_in_situ_total_adjusted, na.rm = TRUE),
            mean_temp = mean(temp_adjusted, na.rm = TRUE)) %>% 
  ungroup()

Plot profiles

Argo profiles plotted according to the surface OceanSODA pH

L profiles correspond to a surface acidification event (low pH), as recorded in OceanSODA

H profiles correspond to an event of high surface pH, as recorded in OceanSODA

N profiles correspond to normal surface OceanSODA pH

pH

profile_extreme %>%
  group_split(biome, basin_AIP, year) %>%
  # head(1) %>%
  map(
    ~ ggplot(
      data = .x,
      aes(
        x = ph_in_situ_total_adjusted,
        y = depth,
        group = ph_extreme,
        col = ph_extreme
      )
    ) +
      geom_point(pch = 19, size = 0.5) +
      scale_y_reverse() +
      scale_color_manual(values = HNL_colors) +
      facet_wrap( ~ month, ncol = 6) +
      labs(
        x = 'Argo pH (total scale)',
        y = 'depth (m)',
        title = paste(
          unique(.x$basin_AIP),
          "|",
          unique(.x$year),
          "| biome:",
          unique(.x$biome)
        ),
        col = 'OceanSODA pH \nanomaly'
      )
  )
[[1]]


[[2]]


[[3]]


[[4]]


[[5]]


[[6]]


[[7]]


[[8]]


[[9]]


[[10]]


[[11]]


[[12]]


[[13]]


[[14]]


[[15]]


[[16]]


[[17]]


[[18]]


[[19]]


[[20]]


[[21]]


[[22]]


[[23]]


[[24]]


[[25]]


[[26]]


[[27]]


[[28]]


[[29]]


[[30]]


[[31]]


[[32]]


[[33]]


[[34]]


[[35]]


[[36]]


[[37]]


[[38]]


[[39]]


[[40]]


[[41]]


[[42]]


[[43]]


[[44]]


[[45]]


[[46]]


[[47]]


[[48]]


[[49]]


[[50]]


[[51]]


[[52]]


[[53]]


[[54]]


[[55]]


[[56]]


[[57]]


[[58]]


[[59]]

Temperature

# plot temperature profiles for the Atlantic
profile_extreme %>%
  group_split(biome, basin_AIP, year) %>%
  # head(1) %>%
  map(
    ~ ggplot(
      data = .x,
      aes(
        x = temp_adjusted,
        y = depth,
        group = ph_extreme,
        col = ph_extreme
      )
    ) +
      geom_point(pch = 19, size = 0.5) +
      scale_y_reverse() +
      scale_color_manual(values = HNL_colors) +
      facet_wrap( ~ month, ncol = 6) +
      labs(
        x = 'Argo temperature (°C)',
        y = 'depth (m)',
        title = paste(
          unique(.x$basin_AIP),
          "|",
          unique(.x$year),
          "| biome:",
          unique(.x$biome)
        ),
        col = 'OceanSODA\npH\nanomaly'
      )
  )
[[1]]


[[2]]


[[3]]


[[4]]


[[5]]


[[6]]


[[7]]


[[8]]


[[9]]


[[10]]


[[11]]


[[12]]


[[13]]


[[14]]


[[15]]


[[16]]


[[17]]


[[18]]


[[19]]


[[20]]


[[21]]


[[22]]


[[23]]


[[24]]


[[25]]


[[26]]


[[27]]


[[28]]


[[29]]


[[30]]


[[31]]


[[32]]


[[33]]


[[34]]


[[35]]


[[36]]


[[37]]


[[38]]


[[39]]


[[40]]


[[41]]


[[42]]


[[43]]


[[44]]


[[45]]


[[46]]


[[47]]


[[48]]


[[49]]


[[50]]


[[51]]


[[52]]


[[53]]


[[54]]


[[55]]


[[56]]


[[57]]


[[58]]


[[59]]

Plot monthly profiles

pH

profile_extreme_monthly %>%
  arrange(depth) %>% 
  group_split(month) %>%
  # head(1) %>%
  map(
    ~ ggplot(data = .x,
             aes(
               x = mean_ph,
               y = depth,
               group = ph_extreme,
               col = ph_extreme
             )) +
      geom_path() +
      scale_color_manual(values = HNL_colors) +
      labs(title = paste("month:", unique(.x$month)),
           col = 'OceanSODA\npH\nanomaly') +
      scale_y_reverse() +
      facet_grid(basin_AIP ~ biome)
  )
[[1]]


[[2]]


[[3]]


[[4]]


[[5]]


[[6]]


[[7]]


[[8]]


[[9]]


[[10]]


[[11]]


[[12]]


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

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] ggOceanMaps_0.4.3 ggspatial_1.1.5   lubridate_1.7.9   forcats_0.5.0    
 [5] stringr_1.4.0     dplyr_1.0.5       purrr_0.3.4       readr_1.4.0      
 [9] tidyr_1.1.3       tibble_3.1.3      ggplot2_3.3.5     tidyverse_1.3.0  
[13] workflowr_1.6.2  

loaded via a namespace (and not attached):
 [1] smoothr_0.1.2         fs_1.5.0              sf_0.9-8             
 [4] RColorBrewer_1.1-2    httr_1.4.2            rprojroot_2.0.2      
 [7] tools_4.0.3           backports_1.1.10      bslib_0.2.5.1        
[10] utf8_1.1.4            rgdal_1.5-18          R6_2.5.0             
[13] KernSmooth_2.23-17    rgeos_0.5-5           DBI_1.1.0            
[16] colorspace_2.0-2      raster_3.4-5          withr_2.3.0          
[19] sp_1.4-4              tidyselect_1.1.0      compiler_4.0.3       
[22] git2r_0.27.1          cli_3.0.1             rvest_0.3.6          
[25] xml2_1.3.2            labeling_0.4.2        sass_0.4.0           
[28] scales_1.1.1          classInt_0.4-3        ggOceanMapsData_1.0.1
[31] digest_0.6.27         rmarkdown_2.10        pkgconfig_2.0.3      
[34] htmltools_0.5.1.1     highr_0.8             dbplyr_1.4.4         
[37] rlang_0.4.11          readxl_1.3.1          rstudioapi_0.13      
[40] jquerylib_0.1.4       generics_0.1.0        farver_2.0.3         
[43] jsonlite_1.7.1        magrittr_1.5          Rcpp_1.0.5           
[46] munsell_0.5.0         fansi_0.4.1           abind_1.4-5          
[49] lifecycle_1.0.0       stringi_1.5.3         whisker_0.4          
[52] yaml_2.2.1            grid_4.0.3            blob_1.2.1           
[55] parallel_4.0.3        promises_1.1.1        crayon_1.3.4         
[58] lattice_0.20-41       haven_2.3.1           stars_0.5-2          
[61] hms_0.5.3             knitr_1.33            pillar_1.6.2         
[64] codetools_0.2-16      reprex_0.3.0          glue_1.4.2           
[67] evaluate_0.14         modelr_0.1.8          vctrs_0.3.8          
[70] httpuv_1.5.4          cellranger_1.1.0      gtable_0.3.0         
[73] assertthat_0.2.1      xfun_0.25             lwgeom_0.2-5         
[76] broom_0.7.9           e1071_1.7-4           later_1.2.0          
[79] class_7.3-17          units_0.6-7           ellipsis_0.3.2