Last updated: 2022-04-13

Checks: 7 0

Knit directory: emlr_obs_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 20ce2b7. 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/

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/read_regions.Rmd) and HTML (docs/read_regions.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 aea9afe jens-daniel-mueller 2022-04-07 Build site.
html 9451c4b jens-daniel-mueller 2022-04-06 Build site.
Rmd 5d7b7c9 jens-daniel-mueller 2022-04-06 rerun all with lat max 65N
html 7e94d73 jens-daniel-mueller 2022-04-06 Build site.
Rmd 8d52a4b jens-daniel-mueller 2022-04-06 rerun all with lat max 65N
html f088f55 jens-daniel-mueller 2022-04-01 Build site.
Rmd d23e425 jens-daniel-mueller 2022-04-01 rerun all including arctic and North Atlantic biome
html dde77eb jens-daniel-mueller 2022-04-01 Build site.
Rmd a1ea47d jens-daniel-mueller 2022-04-01 rerun all including arctic and North Atlantic biome

1 Data source

region_masks_all <-
  read_ncdf(paste(path_reccap2, "RECCAP2_region_masks_all_v20210412.nc", sep = "")) %>%
  as_tibble()

# region_masks_all_seamask <- region_masks_all %>%
#   select(lat, lon, seamask)

region_masks_all <- region_masks_all %>%
  select(-seamask)

region_masks_all <- region_masks_all %>% 
  mutate(arctic = if_else(arctic != 0 & atlantic != 0, 0, arctic),
         southern = if_else(southern != 0 & atlantic != 0, 0, southern),
         southern = if_else(southern != 0 & pacific != 0, 0, southern),
         southern = if_else(southern != 0 & indian != 0, 0, southern))

region_masks_all <- region_masks_all %>%
  pivot_longer(open_ocean:southern,
               names_to = "region",
               values_to = "value") %>%
  mutate(value = as.factor(value)) %>% 
  mutate(lon = if_else(lon < 20, lon + 360, lon))

region_masks_all %>%
  filter(value != 0,
         region != "open_ocean") %>%
  ggplot(aes(lon, lat, fill = region)) +
  geom_raster() +
  scale_fill_brewer(palette = "Dark2") +
  coord_quickmap(expand = 0)

reccap2_region_mask <- region_masks_all %>%
  filter(value != 0,
         region != "open_ocean") %>% 
  select(lon, lat, region)

rm(region_masks_all)

2 WOA Masks

2.1 Land

2.1.1 Read mask

The land sea mask with 1x1° resolution from the file landsea_01.msk was used.

landsea_01 <- read_csv(
  paste(
    path_woa2018,
    "masks/landsea_01.msk",
    sep = ""),
  skip = 1,
  col_types = list(.default = "d"))

2.1.2 Label

According to the WOA18 documentation document:

“The landsea_XX.msk contains the standard depth level number at which the bottom of the ocean is first encountered at each quarter-degree or one-degree square for the entire world. Land will have a value of 1, corresponding to the surface.”

The landmask was derived as coordinates with value 1.

landmask <- landsea_01 %>%
  mutate(region = if_else(Bottom_Standard_Level == "1",
                          "land", "ocean")) %>%
  select(-Bottom_Standard_Level)

landmask <- landmask %>%
  rename(lat = Latitude,
         lon = Longitude) %>%
  mutate(lon = if_else(lon < 20, lon + 360, lon)) %>%
  filter(lat >= params_global$lat_min,
         lat <= params_global$lat_max
         )

landseamask <- landmask

landmask <- landmask %>%
  filter(region == "land") %>%
  select(-region)

rm(landsea_01)

2.2 Basins

2.2.1 Read mask

The surface mask (0m) with 1x1° resolution from the file basinmask_01.msk was used.

basinmask_01 <- read_csv(
  paste(
    path_woa2018,
    "masks/basinmask_01.msk",
    sep = ""),
  skip = 1,
  col_types = list(.default = "d"))

basinmask_01 <- basinmask_01 %>% 
  select(Latitude:Basin_0m) %>% 
  mutate(Basin_0m = as.factor(Basin_0m)) %>% 
  rename(lat = Latitude, lon = Longitude)

2.2.2 Basins for budgets

According to WOA FAQ website and WOA18 documentation, number codes in the mask files were used to assign ocean basins as follows:

Atlantic Ocean:

  • 1: Atlantic Ocean
  • 10: Southern Ocean between 63°W and 20°E
  • 11: Arctic Ocean (restricted by northern latitude limit 65N)

Indian Ocean:

  • 3: Indian Ocean
  • 10: Southern Ocean between 20°E and 147°E
  • 56: Bay of Bengal

Pacific Ocean:

  • 2: Pacific Ocean
  • 10: Southern Ocean between 147°E and 63°W
  • (12: Sea of Japan; currently not included)
# assign basin labels
basinmask_01 <- basinmask_01 %>%
  filter(Basin_0m %in% c("1", "2", "3", "10", "11", "56")) %>%
  mutate(
    basin_AIP = "none",
    basin_AIP = case_when(
      Basin_0m == "1" ~ "Atlantic",
      Basin_0m == "10" & lon >= -63 & lon < 20 ~ "Atlantic",
      Basin_0m == "11" ~ "Atlantic",
      Basin_0m == "3" ~ "Indian",
      Basin_0m == "56" ~ "Indian",
      Basin_0m == "10" & lon >= 20 & lon < 147 ~ "Indian",
      Basin_0m == "2" ~ "Pacific",
      # Basin_0m == "12" ~ "Pacific",
      Basin_0m == "10" &
        lon >= 147 | lon < -63 ~ "Pacific"
    )
  ) %>%
  select(-Basin_0m)

# apply northern latitude boundary
basinmask_01 <- basinmask_01 %>%
  filter(lat <= params_global$lat_max)

# harmonize lon scale
basinmask_01 <- basinmask_01  %>%
  mutate(lon = if_else(lon < 20, lon + 360, lon))
basinmask_01 <- inner_join(basinmask_01,reccap2_region_mask)

basinmask_01 <- basinmask_01 %>% 
  mutate(basin_AIP = if_else(region == "arctic", "Arctic", basin_AIP))
# generate base map, which is further used throughout the project
map <-
  ggplot() +
  geom_tile(data = landmask,
            aes(lon, lat), fill = "grey80") +
  coord_quickmap(expand = 0) +
  theme(axis.title = element_blank())

# plot basin_AIP map
map +
  geom_raster(data = basinmask_01,
              aes(lon, lat, fill = basin_AIP)) +
  scale_fill_brewer(palette = "Dark2")

Version Author Date
9451c4b jens-daniel-mueller 2022-04-06
7e94d73 jens-daniel-mueller 2022-04-06
f088f55 jens-daniel-mueller 2022-04-01
dde77eb jens-daniel-mueller 2022-04-01
# generate base map, which is further used throughout the project
ggplot() +
  geom_raster(data = landseamask,
              aes(lon, lat, fill = region)) +
  coord_quickmap(expand = 0) +
  scale_fill_brewer(palette = "Paired") +
  theme(axis.title = element_blank())

Version Author Date
7e94d73 jens-daniel-mueller 2022-04-06
dde77eb jens-daniel-mueller 2022-04-01

2.2.3 Basins for MLR fitting

For the MLR fitting, ocean basins are further split up, as plotted below.

# basinmask_01 <- basinmask_01 %>% 
#   select(-region)

# 4 basins incl arctic
# basinmask_04 <- basinmask_01 %>%
#   mutate(basin = basin_AIP) %>%
#   mutate(MLR_basins = "4")

# 1 basins
basinmask_01 <- basinmask_01 %>%
  # filter(basin_AIP != "Arctic") %>% 
  mutate(basin = "global",
         MLR_basins = "1")

# 2 basins
basinmask_2 <- basinmask_01 %>%
  mutate(basin = if_else(basin_AIP == "Atlantic",
                         "Atlantic",
                         "Indo-Pacific"),
         MLR_basins = "2")

# 5 basins
basinmask_5 <- basinmask_01 %>%
  mutate(
    basin = case_when(
      basin_AIP ==  "Atlantic" & lat > params_global$lat_equator ~ "N_Atlantic",
      basin_AIP ==  "Atlantic" & lat < params_global$lat_equator ~ "S_Atlantic",
      basin_AIP ==  "Pacific" & lat > params_global$lat_equator ~ "N_Pacific",
      basin_AIP ==  "Pacific" & lat < params_global$lat_equator ~ "S_Pacific",
      basin_AIP ==  "Indian" ~ "Indian"
    )
  ) %>%
  mutate(MLR_basins = "5")

# SO_2 basin separate
basinmask_SO_2 <- basinmask_01 %>%
  mutate(
    basin = if_else(basin_AIP == "Atlantic",
                         "Atlantic",
                         "Indo-Pacific"),
    basin = if_else(
      lat < params_global$lat_min_SO, "SO", basin)
  ) %>%
  mutate(MLR_basins = "SO_2")


# SO_5 basin separate
basinmask_SO_5 <- basinmask_01 %>%
  mutate(
    basin = case_when(
      basin_AIP ==  "Atlantic" & lat > 35 ~ "N_Atlantic",
      basin_AIP ==  "Atlantic" & lat < 35 & lat >= params_global$lat_min_SO ~ "Atlantic",
      basin_AIP ==  "Atlantic" & lat < params_global$lat_min_SO ~ "S_Atlantic",
      basin_AIP ==  "Pacific" & lat > 35 ~ "N_Pacific",
      basin_AIP ==  "Pacific" & lat < 35 & lat >= params_global$lat_min_SO ~ "Pacific",
      basin_AIP ==  "Pacific" & lat < params_global$lat_min_SO ~ "S_Pacific",
      basin_AIP ==  "Indian" & lat >= params_global$lat_min_SO ~ "Indian",
      basin_AIP ==  "Indian" & lat < params_global$lat_min_SO ~ "S_Indian"
    )) %>%
  mutate(MLR_basins = "SO_5")

# SO basin separate, with others being AIP
basinmask_SO_AIP <- basinmask_01 %>%
  mutate(
    basin = if_else(
      lat < params_global$lat_min_SO, "SO", basin_AIP)
  ) %>%
  mutate(MLR_basins = "SO_AIP")

# 3 basins
basinmask_AIP <- basinmask_01 %>%
  mutate(
    basin = basin_AIP) %>%
  mutate(MLR_basins = "AIP")


# join basin masks into one file
basinmask_all <- bind_rows(
  # basinmask_04,
  basinmask_01,
  basinmask_2,
  basinmask_5,
  basinmask_SO_2,
  basinmask_SO_5,
  basinmask_SO_AIP,
  basinmask_AIP
)
for (i_MLR_basins in unique(basinmask_all$MLR_basins)) {
  # i_MLR_basins <- unique(basinmask_all$MLR_basins)[6]
  
  print(
    map +
      geom_raster(
        data = basinmask_all %>% filter(MLR_basins == i_MLR_basins),
        aes(lon, lat, fill = basin)
      ) +
      scale_fill_brewer(palette = "Dark2") +
      labs(title = paste("MLR basin label:", i_MLR_basins))
  )
  
}

Version Author Date
9451c4b jens-daniel-mueller 2022-04-06
7e94d73 jens-daniel-mueller 2022-04-06
dde77eb jens-daniel-mueller 2022-04-01

Version Author Date
9451c4b jens-daniel-mueller 2022-04-06
7e94d73 jens-daniel-mueller 2022-04-06
dde77eb jens-daniel-mueller 2022-04-01

Version Author Date
9451c4b jens-daniel-mueller 2022-04-06
7e94d73 jens-daniel-mueller 2022-04-06
dde77eb jens-daniel-mueller 2022-04-01

Version Author Date
9451c4b jens-daniel-mueller 2022-04-06
7e94d73 jens-daniel-mueller 2022-04-06
dde77eb jens-daniel-mueller 2022-04-01

Version Author Date
9451c4b jens-daniel-mueller 2022-04-06
7e94d73 jens-daniel-mueller 2022-04-06
dde77eb jens-daniel-mueller 2022-04-01

Version Author Date
9451c4b jens-daniel-mueller 2022-04-06
7e94d73 jens-daniel-mueller 2022-04-06
dde77eb jens-daniel-mueller 2022-04-01

Version Author Date
9451c4b jens-daniel-mueller 2022-04-06
7e94d73 jens-daniel-mueller 2022-04-06
dde77eb jens-daniel-mueller 2022-04-01

2.3 Global section

To plot sections from the North Atlantic south to the Southern Ocean, around Antarctica and back North across the Pacific Ocean, corresponding coordinates were subsetted from the basin mask and distances between coordinate grid points calculated.

section <- basinmask_01 %>%
  select(lon, lat)

# subset individual section parts
Atl_NS <- section %>%
  filter(
    lon == params_global$lon_Atl_section,
    lat <= params_global$lat_section_N,
    lat >= params_global$lat_section_S
  ) %>%
  arrange(-lat)

Atl_SO <- section %>%
  filter(lon > params_global$lon_Atl_section,
         lat == params_global$lat_section_S) %>%
  arrange(lon)

Pac_SO <- section %>%
  filter(lon < params_global$lon_Pac_section,
         lat == params_global$lat_section_S) %>%
  arrange(lon)

Pac_SN <- section %>%
  filter(
    lon == params_global$lon_Pac_section,
    lat <= params_global$lat_section_N,
    lat >= params_global$lat_section_S
  ) %>%
  arrange(lat)

# join individual section parts
section_global_coordinates <- bind_rows(Atl_NS,
                     Atl_SO,
                     Pac_SO,
                     Pac_SN)

# convert to regular lon coordinates for distance calculation
section_global_coordinates <- section_global_coordinates %>%
  mutate(lon_180 = if_else(lon > 180, lon - 360, lon))

# calculate distance along section
section_global_coordinates <- section_global_coordinates %>%
  mutate(dist_int = distGeo(cbind(lon_180, lat)) / 1e6) %>%
  mutate(dist = cumsum(dist_int))

section_global_coordinates <- section_global_coordinates %>%
  select(lon, lat, dist) %>% 
  drop_na()

rm(Atl_NS, Atl_SO, Pac_SN, Pac_SO, section)
map +
  geom_point(data = section_global_coordinates,
             aes(lon, lat, col = dist)) +
  scale_colour_viridis_b(name = "Distance (Mm)")

Version Author Date
7e94d73 jens-daniel-mueller 2022-04-06
f088f55 jens-daniel-mueller 2022-04-01
dde77eb jens-daniel-mueller 2022-04-01

2.4 Write files

# land sea mask
landseamask %>%
  write_csv(paste(path_files,
                  "land_sea_mask_WOA18.csv",
                  sep = ""))

# basin mask
basinmask_all %>%
  write_csv(paste(path_files,
                  "basin_mask_WOA18.csv",
                  sep = ""))
# global section
section_global_coordinates %>%
  write_csv(paste(path_files,
                  "section_global_coordinates.csv",
                  sep = ""))

# base map ggplot
map %>%
  write_rds(paste(path_files,
                  "map_landmask_WOA18.rds",
                  sep = ""))

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      patchwork_1.1.1 
 [5] geosphere_1.5-14 oce_1.5-0        gsw_1.0-6        reticulate_1.23 
 [9] tidync_0.2.4     forcats_0.5.1    stringr_1.4.0    dplyr_1.0.7     
[13] purrr_0.3.4      readr_2.1.1      tidyr_1.1.4      tibble_3.1.6    
[17] ggplot2_3.3.5    tidyverse_1.3.1  workflowr_1.7.0 

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