Last updated: 2024-05-16

Checks: 7 0

Knit directory: bgc_argo_r_argodata/analysis/

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(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 1ad5dd9. 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:    .Rproj.user/
    Ignored:    analysis/figure/

Untracked files:
    Untracked:  analysis/draft.Rmd
    Untracked:  load_argo_core_output.txt

Unstaged changes:
    Deleted:    analysis/MHWs_categorisation.Rmd
    Modified:   analysis/_site.yml
    Modified:   analysis/anomaly_SST_2023.Rmd
    Modified:   analysis/child/cluster_analysis_base.Rmd
    Modified:   analysis/coverage_maps_North_Atlantic.Rmd
    Modified:   analysis/load_broullon_DIC_TA_clim.Rmd
    Modified:   code/Workflowr_project_managment.R
    Modified:   code/start_background_job.R
    Modified:   code/start_background_job_load.R
    Modified:   code/start_background_job_partial.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/CESM_comparison.Rmd) and HTML (docs/CESM_comparison.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 1ad5dd9 mlarriere 2024-05-16 monthly vertical anomalies and specific floats
html 0a71d56 mlarriere 2024-05-15 Build site.
Rmd bbf732b mlarriere 2024-05-15 CESM climatology
html 96d4b76 mlarriere 2024-05-14 Build site.
Rmd 91e6028 mlarriere 2024-05-13 adding subsection CESM comparison
html af6594f mlarriere 2024-05-13 Build site.
Rmd 30f9250 mlarriere 2024-05-13 Adding CESM subsection

Task

Dependencies

Outputs

path CESM 2023 data: “/nfs/kryo/work/loher/GlobalMarineHeatwaves/ETHZ_BEC/Heatwaves_RunA.nc” variable for temperature: thetao

path_emlr_utilities <- "/nfs/kryo/work/jenmueller/emlr_cant/utilities/files/"
path_basin_mask <- "/nfs/kryo/work/datasets/gridded/ocean/interior/reccap2/supplementary/"

path_argo_core <- '/nfs/kryo/work/datasets/ungridded/3d/ocean/floats/core_argo_r_argodata_2024-03-13'
path_argo_core_preprocessed <- paste0(path_argo_core, "/preprocessed_core_data")

path_CESM<-"/nfs/kryo/work/loher/GlobalMarineHeatwaves/ETHZ_BEC/"

CESM

Read data

# Read NetCDF file containing CESM outputs (35 variables - 4dim: time, lat, lon, depth)
CESM_temp <- tidync(paste0(path_CESM, "Heatwaves_RunA.nc"))
CESM_temp <- CESM_temp %>%
  hyper_tibble(select_var = "thetao", # thetao: seawater potential temperature [°C]
                       force = TRUE)

CESM_temp <- CESM_temp %>%
  filter(thetao < 1e36) %>% # thetao ~ e36 because??
  rename(temp = thetao)
gc()

CESM_temp <- CESM_temp %>%
  mutate(time = ymd_hms("1980-01-01 00:00:00") + days(time))
gc()

CESM_temp$year <- year(CESM_temp$time)
CESM_temp$month <- month(CESM_temp$time)
gc()

#Area of interest: North Atlantic east - lat:(0,40), lon:(-30,0)
CESM_temp <- CESM_temp %>% 
  mutate(lon = ifelse(lon > 180, lon - 360, lon))

CESM_natlantic_east <- CESM_temp %>% 
  filter(lat>0, lat<40, -30<lon, lon<0)

#Select 2023
CESM_natlantic_east_2023 <- CESM_natlantic_east %>% 
  filter(year==2023)
gc()
#Write to file
write_rds(CESM_natlantic_east_2023,
          file = paste0(path_argo_core_preprocessed,"/", "CESM_temp2023_NorthAtlantic_east.rds"))

# rm(CESM_temp) 
CESM_natlantic_east_2023<- read_rds(file = paste0(path_argo_core_preprocessed,"/", "CESM_temp2023_NorthAtlantic_east.rds"))

# Visualization
CESM_natlantic_east_2023 %>%
  filter(depth == 5) %>%
  ggplot(aes(lon, lat, fill = temp)) +
  geom_raster() +
  scale_fill_viridis_c(option = "magma") +
  labs(title = "Monthly visualisation of CESM seawater potential temperature",
       subtitle = paste0("depth=5m -- Period: 2023"))+
  coord_quickmap(expand = 0)+
  facet_wrap(~month, nrow = 3)


CESM_natlantic_east_2023 %>%
  filter(lat == 30.5) %>%
  ggplot(aes(lon, depth, z = temp)) +
  geom_contour_filled(breaks = seq(-10,40,2)) +
  scale_y_reverse(limits = c(3000, 0)) +
  coord_cartesian(expand = 0) +
  labs(title = "Visualisation of CESM seawater potential temperature",
       subtitle = paste0( "transect section -- lat: 30.5, Period: 2023"))+
  scale_fill_viridis_d(option = "magma")+
  facet_wrap(~month, nrow = 3)

Climatology calculation

We calculate the temperature climatology of CESM over the period 2004-2019 (to match with argo climatology) this operation is done only on the North Atlantic east, for computation efficiency

#Climatology of CESM temp output over the period 2004-2019 (to match with argo climatology) -- only on the North Atlantic east
CESM_2004_2019_natlantic_east<- CESM_natlantic_east %>% 
  filter(year>=2004, year<=2019)

CESM_2004_2019_natlantic_east<-CESM_2004_2019_natlantic_east %>% 
  fgroup_by(lat, lon, depth, month) %>% 
  fsummarize(mean_temp=mean(temp, na.rm=TRUE))

# Visualization
# CESM_2004_2019_natlantic_east %>%
#   filter(depth == 5) %>%
#   ggplot(aes(lon, lat, fill = mean_temp)) +
#   geom_raster() +
#   scale_fill_viridis_c(option = "magma") +
#   labs(title = "Mean CESM seawater potential temperature",
#        subtitle = paste0("depth=5m, Period: 2004-2019"))+
#   coord_quickmap(expand = 0)+
#   facet_wrap(~month, nrow = 3)
# 
# 
# CESM_2004_2019_natlantic_east %>%
#   filter(lat == 30.5) %>%
#   ggplot(aes(lon, depth, z = mean_temp)) +
#   geom_contour_filled(breaks = seq(-10,40,2)) +
#   scale_y_reverse(limits = c(3000, 0)) +
#   coord_cartesian(expand = 0) +
#   labs(title = "Mean CESM seawater potential temperature",
#        subtitle = paste0( "transect section -- lat: 30.5, Period: 2004-2019"))+
#   scale_fill_viridis_d(option = "magma")+
#   facet_wrap(~month, nrow = 3)

# Temperature anomaly
CESM_anomaly_natlantic_east_2023 <- inner_join(CESM_natlantic_east_2023, CESM_2004_2019_natlantic_east, by = c("month", "lat", "lon", "depth")) 


# Calculate temperature anomaly
CESM_anomaly_natlantic_east_2023 <- CESM_anomaly_natlantic_east_2023 %>%
    fmutate(temp_anomaly = temp - mean_temp)

#Write 
write_rds(CESM_anomaly_natlantic_east_2023,
          file = paste0(path_argo_core_preprocessed,"/", "CESM_temp_anomaly2023_NorthAtlantic_east_clim2004-2019.rds"))

# rm(CESM_2004_2019_natlantic_east)
gc()
# Read data
CESM_anomaly_natlantic_east_2023<-read_rds(file = 
                                             paste0(path_argo_core_preprocessed,"/", "CESM_temp_anomaly2023_NorthAtlantic_east_clim2004-2019.rds"))
# Visualization
CESM_anomaly_natlantic_east_2023 %>%
  filter(depth == 5) %>%
  ggplot(aes(lon, lat, fill = temp_anomaly)) +
  geom_raster() +
  scale_fill_viridis_c(option = "magma") +
  labs(title = "CESM temperature anomaly - 2023",
       subtitle = paste0("depth=5m, clim: 2004-2019"))+
  coord_quickmap(expand = 0)+
  facet_wrap(~month, nrow = 3)

# CESM_anomaly_natlantic_east_2023 %>%
#   filter(lat == 30.5) %>%
#   ggplot(aes(lon, depth, z = temp_anomaly)) +
#   geom_contour_filled(breaks = seq(-10,40,0.5)) +
#   scale_y_reverse(limits = c(3000, 0)) +
#   coord_cartesian(expand = 0) +
#   labs(title = "CESM temperature anomaly - 2023",
#        subtitle = paste0( "transect section -- lat: 30.5, clim: 2004-2019"))+
#   scale_fill_viridis_d(option = "magma")+
#   facet_wrap(~month, nrow = 3)

Argo

Read data

Float location

CESM_anomaly_natlantic_east_2023$month<- factor(format(CESM_anomaly_natlantic_east_2023$time, "%m"))

CESM_with_float <- CESM_anomaly_natlantic_east_2023 %>% 
  right_join(core_anomaly_east_2023%>% distinct(lat, lon, month, platform_number, cycle_number), 
            by = c("lat", "lon", "month"))

# Float coverage -- east north atlantic over 2023
platform_counts <- aggregate(platform_number ~ month, data = CESM_with_float, FUN = function(x) length(unique(x)))
cycle_count_per_platform_month <- CESM_with_float %>%
  group_by(month, platform_number) %>%
  summarise(cycle_count = n_distinct(cycle_number))

1 Float

unique_platform<-CESM_with_float %>% 
  filter(platform_number==1902396)

ggplot(unique_platform, aes(x = temp_anomaly , y = depth, color = factor(cycle_number))) +
  geom_path() +
  geom_vline(xintercept = 0) +
  scale_y_reverse() +
  coord_cartesian(xlim = c(-6, 6), ylim = c(200, 0)) +
  labs(title = 'Anomaly profiles by month',
       subtitle= paste0('Platform ', unique(unique_platform$platform_number)),
       x = 'Temperature (°C)', y = 'Depth (m)', color = 'Cycle Number') +
  scale_color_viridis(discrete = TRUE) + 
  facet_wrap(~month, scales = "free", ncol = 3)

Lat/long

#Calculating monthly mean anomaly + std for each lat/lon pair of the area
anomaly_lat_lon <- CESM_with_float %>%
  group_by(lat, lon, depth, month, platform_number, cycle_number) %>%
  summarise(
    temp_count = n(),
    temp_anomaly_mean = mean(temp_anomaly, na.rm = TRUE)
    )

# Longitude - gradient north-south
ggplot(anomaly_lat_lon, aes(x = temp_anomaly_mean, y = depth, group = interaction(platform_number, cycle_number), color = as.numeric(lon))) +
  geom_path() +
  geom_vline(xintercept = 0) +
  scale_y_reverse(limits = c(200, 0)) +
  coord_cartesian(xlim = c(-6, 6)) +
  facet_wrap(~ month, ncol = 3) +
  labs(title = "Anomaly Profiles for all longitudes", 
       subtitle = "All floats and cycles included",
       x = "Temperature (°C)", y = "Depth (m)", color = "Longitude") + 
  scale_color_viridis_c()

# Latitude - gradient west-east
ggplot(anomaly_lat_lon, aes(x = temp_anomaly_mean, y = depth, group = interaction(platform_number, cycle_number), color = as.numeric(lat))) +
  geom_path() +
  geom_vline(xintercept = 0) +
  scale_y_reverse(limits = c(200, 0)) +
  coord_cartesian(xlim = c(-6, 6)) +
  facet_wrap(~ month, ncol = 3) +
  labs(title = "Anomaly Profile for all latitudes", 
       subtitle = "All floats and cycles included",
       x = "Temperature (°C)", y = "Depth (m)", color = "Latitude") +  
  scale_color_viridis_c()

Monthy average - entire extent

# Calculating monthly mean anomaly over the east area by averaging the anomaly of each float present
anomaly_mean <- CESM_with_float %>% 
  group_by(depth, month) %>% 
  summarise(temp_count = n(),
            temp_anomaly_mean = mean(temp_anomaly , na.rm = TRUE),
            temp_anomaly_sd = sd(temp_anomaly , na.rm = TRUE))

# Vertical anomaly profile for the North atlatinc east region - monthly - CESM
anomaly_plot_monthly <- ggplot(anomaly_mean, aes(x = temp_anomaly_mean, y = depth, color = factor(month))) +
  geom_path() +
  geom_ribbon(aes(xmax = temp_anomaly_mean + temp_anomaly_sd,
                  xmin = temp_anomaly_mean - temp_anomaly_sd,
                  y = depth), alpha = 0.2) +
  geom_vline(xintercept = 0) +
  scale_y_reverse() +
  coord_cartesian(xlim = c(-4, 4), ylim = c(200, 0)) +
  labs(title = paste('CESM temperature output - monthly anomaly profile'), 
       subtitle = paste0("Extent: East", "\nfrom surface to 200m"),
       x = 'Temperature (°C)', y = 'Depth (m)') +
  guides(color = FALSE)+
  facet_wrap(~month)

print(anomaly_plot_monthly)


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] collapse_2.0.13    ncdf4_1.22         tidync_0.3.0       marelac_2.1.10    
 [5] shape_1.4.6        RColorBrewer_1.1-3 stars_0.6-0        sf_1.0-9          
 [9] abind_1.4-5        paletteer_1.6.0    cluster_2.1.6      gridExtra_2.3     
[13] viridis_0.6.2      viridisLite_0.4.1  lubridate_1.9.0    timechange_0.1.1  
[17] forcats_0.5.2      stringr_1.5.0      dplyr_1.1.3        purrr_1.0.2       
[21] readr_2.1.3        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] fs_1.5.2            gsw_1.1-1           httr_1.4.4         
 [4] rprojroot_2.0.3     tools_4.2.2         backports_1.4.1    
 [7] bslib_0.4.1         utf8_1.2.2          R6_2.5.1           
[10] KernSmooth_2.23-20  DBI_1.2.2           colorspace_2.0-3   
[13] withr_2.5.0         tidyselect_1.2.0    processx_3.8.0     
[16] compiler_4.2.2      git2r_0.30.1        cli_3.6.1          
[19] rvest_1.0.3         RNetCDF_2.6-1       xml2_1.3.3         
[22] labeling_0.4.2      sass_0.4.4          scales_1.2.1       
[25] classInt_0.4-8      SolveSAPHE_2.1.0    callr_3.7.3        
[28] proxy_0.4-27        digest_0.6.30       oce_1.7-10         
[31] rmarkdown_2.18      pkgconfig_2.0.3     htmltools_0.5.8.1  
[34] highr_0.9           dbplyr_2.2.1        fastmap_1.1.0      
[37] rlang_1.1.1         readxl_1.4.1        rstudioapi_0.15.0  
[40] farver_2.1.1        jquerylib_0.1.4     generics_0.1.3     
[43] jsonlite_1.8.3      googlesheets4_1.0.1 magrittr_2.0.3     
[46] ncmeta_0.3.5        Rcpp_1.0.10         munsell_0.5.0      
[49] fansi_1.0.3         lifecycle_1.0.3     stringi_1.7.8      
[52] whisker_0.4         yaml_2.3.6          grid_4.2.2         
[55] parallel_4.2.2      promises_1.2.0.1    crayon_1.5.2       
[58] haven_2.5.1         seacarb_3.3.1       hms_1.1.2          
[61] knitr_1.41          ps_1.7.2            pillar_1.9.0       
[64] reprex_2.0.2        glue_1.6.2          evaluate_0.18      
[67] getPass_0.2-2       modelr_0.1.10       vctrs_0.6.4        
[70] tzdb_0.3.0          httpuv_1.6.6        cellranger_1.1.0   
[73] gtable_0.3.1        rematch2_2.1.2      assertthat_0.2.1   
[76] cachem_1.0.6        xfun_0.35           lwgeom_0.2-10      
[79] broom_1.0.5         e1071_1.7-12        later_1.3.0        
[82] class_7.3-20        googledrive_2.0.0   gargle_1.2.1       
[85] units_0.8-0         ellipsis_0.3.2