Last updated: 2024-05-24

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 61a27b0. 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/

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

Unstaged changes:
    Deleted:    analysis/MHWs_categorisation.Rmd
    Modified:   analysis/MHWs_vertical_anomaly.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_argo_core.Rmd
    Modified:   analysis/load_broullon_DIC_TA_clim.Rmd
    Modified:   analysis/temp_core_align_climatology.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 61a27b0 mlarriere 2024-05-24 Gaussian distribution
html b21e0e6 mlarriere 2024-05-20 Build site.
Rmd d483896 mlarriere 2024-05-20 final graph CESM- Argo comparison
html 7f729d4 mlarriere 2024-05-16 Build site.
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()

#Transformations
#--time
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()

#--longitude
CESM_temp <- CESM_temp %>% 
  mutate(lon = ifelse(lon > 180, lon - 360, lon))

#Select 2023
CESM_temp_2023 <- CESM_temp %>%
  filter(year==2023)
gc()
#Write CESM outputs for 2023 to file
write_rds(CESM_temp_2023,
          file = paste0(path_argo_core_preprocessed,"/", "CESM_temp2023.rds"))
CESM_temp_2023<- read_rds(file = paste0(path_argo_core_preprocessed,"/", "CESM_temp2023.rds"))

# Visualization
CESM_temp_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)

Version Author Date
7f729d4 mlarriere 2024-05-16
0a71d56 mlarriere 2024-05-15
# CESM_temp_2023 %>%
#   filter(lat == -50.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)
CESM_temp_2004_2019<- CESM_temp %>% 
  filter(year>=2004, year<=2019)

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

# Visualization
CESM_temp_2004_2019 %>%
  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)


# Temperature anomaly
CESM_anomaly_2023 <- inner_join(CESM_temp_2023, CESM_temp_2004_2019, by = c("month", "lat", "lon", "depth")) 

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

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

# rm(CESM_2004_2019_natlantic_east)
gc()
# Read data
CESM_anomaly_2023<-read_rds(file =paste0(path_argo_core_preprocessed,"/", "CESM_temp_anomaly2023_clim2004-2019.rds"))

# Visualization
CESM_anomaly_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)

Version Author Date
b21e0e6 mlarriere 2024-05-20
7f729d4 mlarriere 2024-05-16
#Area of interest: North Atlantic north west - lat:(60,30), lon:(-70,-30), North Atlantic east - lat:(0,40), lon:(-30,0)
chosen_extent <- list(
  lat_min = 0, #30
  lat_max = 40, #60
  lon_min = -30, #-70
  lon_max = 0 #-30
)  
name_extent<- "East" #Northwest

CESM_natlantic_2023_subset <- CESM_anomaly_2023 %>%
  filter(lat > chosen_extent$lat_min, lat < chosen_extent$lat_max, 
         lon > chosen_extent$lon_min, lon < chosen_extent$lon_max)
CESM_natlantic_2023_subset$month<- factor(format(CESM_natlantic_2023_subset$time, "%m"))

# Visualization
#--Base map
world_coordinates <- map_data("world") 
ggplot() +
  geom_raster(data= CESM_natlantic_2023_subset %>% filter(depth == 5),  aes(lon, lat, fill = temp_anomaly)) +
  geom_map(data = world_coordinates, map = world_coordinates, aes(long, lat, map_id = region), fill = "grey") +
  # geom_map(data = world_coordinates, map = world_coordinates, aes(long, lat, map_id = region), color = "black", fill = NA) +
  lims(x = c(chosen_extent$lon_min, chosen_extent$lon_max), y=c(chosen_extent$lat_min, chosen_extent$lat_max)) + 
  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)

Version Author Date
b21e0e6 mlarriere 2024-05-20

Argo

Read data

Float location

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

# Float coverage -- subset 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))

Float distribution

# topofile='ETOPO15_mean_bath.nc'
# topopath='/nfs/kryo/work/updata/bathymetry/ETOPO1/'
# bathymetry<-tidync(paste0(topopath,topofile)) 
# bathymetry<-bathymetry %>% 
#   hyper_tibble(select_var = c("latitude","longitude", "mean_bath"), 
#                        force = TRUE)
# 
# east_extent<-bathymetry %>% 
#   filter(latitude>0, latitude<40, longitude>-30, longitude<0, mean_bath>0)

CESM_SSTanomaly_mean2023<- CESM_natlantic_2023_subset %>%
  filter(depth == 5) %>%
  group_by(lat, lon) %>% 
  summarise(yearly_SSTanomaly= mean(temp_anomaly, na.rm = TRUE))

float_monthly_count <- CESM_with_float %>%
  group_by(lon, lat) %>%
  summarise(months_present = n_distinct(month)) %>%
  ungroup()


#--Plots
SST_2023_plot <- ggplot()+
  geom_raster(data=CESM_SSTanomaly_mean2023, aes(lon, lat, fill = yearly_SSTanomaly)) +
  geom_map(data = world_coordinates, map = world_coordinates, aes(long, lat, map_id = region), fill = "grey") +
  # geom_map(data = world_coordinates, map = world_coordinates, aes(long, lat, map_id = region), color = "black", fill = NA) +
  lims(x = c(chosen_extent$lon_min, chosen_extent$lon_max), y=c(chosen_extent$lat_min, chosen_extent$lat_max)) + 
  scale_fill_viridis_c(option = "magma") +
  labs(title = "SST anomaly, \nannual average 2023",
       subtitle = "Resolution: 1°x1°",
       fill = "SST \nanomalies [°C]")+
  coord_quickmap(expand = 0)+
   theme(plot.title = element_text(size = 18), 
        plot.subtitle = element_text(size = 12),
        legend.text = element_text(size = 12),  
    legend.title = element_text(size = 14) ,
          legend.key.width = unit(0.3, "cm"),
                legend.key.height = unit(1, "cm")
  )
library(scico)

float_distrib <- ggplot() +
  geom_point(data = float_monthly_count, aes(x = lon, y = lat, color = months_present)) +
  geom_map(data = world_coordinates, map = world_coordinates, aes(long, lat, map_id = region), fill = "grey") +
  lims(x = c(chosen_extent$lon_min, chosen_extent$lon_max), y=c(chosen_extent$lat_min, chosen_extent$lat_max)) + 
  labs(title = "Platform Locations",
       subtitle = "Resolution: 1°x1°",
       color = "Months \nwith float") +
    scale_color_scico(palette = "oslo", breaks = seq(1, 12, by = 1), limits = c(1, 12), direction=-1) +

  # scale_color_gradient(low = "blue", high = "red", breaks = seq(1, 12, by = 1), limits = c(1, 12)) +
  coord_quickmap(expand = 0) +
  theme(plot.title = element_text(size = 18), 
        plot.subtitle = element_text(size = 12),
        legend.text = element_text(size = 12),  
    legend.title = element_text(size = 14),
        legend.key.width = unit(0.3, "cm"),
                legend.key.height = unit(1, "cm"))


combined_plot <- SST_2023_plot + float_distrib + plot_layout(ncol = 2)
combined_plot

Version Author Date
b21e0e6 mlarriere 2024-05-20

1 Float

unique_platform_CEM<-CESM_with_float %>%
  filter(platform_number==1902323  )

unique_platform_ARGO<-core_anomaly_2023_natlantic_subset %>%
filter(platform_number==1902323  )

# ggplot(unique_platform, aes(x = 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)
# 
CEM_singlfloat<- ggplot() +
  geom_path(data=unique_platform_CEM, aes(x = temp_anomaly , y = depth, color = factor(month), group = cycle_number)) +
  geom_vline(xintercept = 0) +
  scale_y_reverse() +
  coord_cartesian(xlim = c(-6, 6), ylim = c(200, 0)) +
    scale_color_manual(values = colorRampPalette(c("#2796A5", "#F3712B", "#880D1E"))(12)) +
    labs(
         # subtitle = "CESM ocean model", 
       x = 'Temperature (°C)', y = 'Depth (m)', color = 'Months') +
    theme(plot.title = element_text(size = 18), 
        plot.subtitle = element_text(size = 14),
        legend.text = element_text(size = 12),  
        legend.title = element_text(size = 14, face = "bold"),
        legend.background = element_rect(fill = "transparent", color='transparent')
        # legend.position=c(.91,.28),
    )


ARGO_singlfloat<- ggplot() +
  geom_path(data=unique_platform_ARGO, aes(x = anomaly , y = depth, color = factor(month), group = cycle_number)) +
  geom_vline(xintercept = 0) +
  scale_y_reverse() +
  coord_cartesian(xlim = c(-6, 6), ylim = c(200, 0)) +
    scale_color_manual(values = colorRampPalette(c("#2796A5", "#F3712B", "#880D1E"))(12)) +
    labs(
         # subtitle = "Argo floats", 
       x = 'Temperature (°C)', y = 'Depth (m)', color = 'Months') +
   theme(plot.title = element_text(size = 18), 
        plot.subtitle = element_text(size = 14),
            legend.position = "none"

        # legend.text = element_text(size = 12),
        # legend.title = element_text(size = 14, face = "bold"),
        # legend.background = element_rect(fill = "transparent", color='transparent'),
        # legend.position=c(.91,.28),
    )




combined_plot <- ARGO_singlfloat + CEM_singlfloat + 
  plot_layout(ncol = 2) +
  plot_annotation(
    title = 'SST anomalies propagation of a single float',
    subtitle = 'Location: Canaries Islands (Eddies corridor)',
    theme = theme(
      plot.title = element_text(size = 18),
      plot.subtitle = element_text(size = 14)
    )
  )
combined_plot

Version Author Date
b21e0e6 mlarriere 2024-05-20
7f729d4 mlarriere 2024-05-16

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
longitude<- 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
latitude<- 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()
combined_plot <- latitude + longitude + plot_layout(ncol = 2)
combined_plot

Version Author Date
b21e0e6 mlarriere 2024-05-20
7f729d4 mlarriere 2024-05-16

Monthy average - ARGO exent

# 
# ggplot(anomaly_CESM, 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 Monthly anomaly profile'), 
#        subtitle = paste0("Extent: East and ARGO float locations"),
#        x = 'Temperature (°C)', y = 'Depth (m)') +
#   guides(color = FALSE)+
#   facet_wrap(~month)

Monthy average - entire extent

# Calculating monthly mean anomaly over the east area by averaging the anomaly of each float present
anomaly_CESM_entire_extent <- CESM_natlantic_2023_subset %>% 
  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))


anomaly_ARGO <- core_anomaly_2023_natlantic_subset %>% #ARGO
  group_by(depth, month) %>%
  summarise(temp_count = n(),
            temp_anomaly_mean = mean(anomaly , na.rm = TRUE),
            temp_anomaly_sd = sd(anomaly , na.rm = TRUE))

# Defining period of 2months and calculating monthly mean anomaly over the east area 
anomaly_CESM<-CESM_with_float %>% #CESM
  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))

# difference ARGO vs full extent
difference_extent<- merge(anomaly_CESM_entire_extent, anomaly_CESM, 
                          by = c("depth","month"), suffixes = c("_float", "_entire_extent")) %>%
  as_tibble()
difference_extent$diff_temp_anomaly_mean <- difference_extent$temp_anomaly_mean_entire_extent    - difference_extent$temp_anomaly_mean_float  

Distributions of the anomaly

#ARGO
mean_anomaly_argo <- mean(core_anomaly_2023_natlantic_subset$anomaly, na.rm = TRUE)
sd_anomaly_argo <- sd(core_anomaly_2023_natlantic_subset$anomaly, na.rm = TRUE)
argo_hist <-   ggplot(core_anomaly_2023_natlantic_subset, aes(x=anomaly)) +
  geom_histogram(aes(y=..density.., fill="Values"), bins=30, alpha=0.5) +
  stat_function(fun=dnorm, args=list(mean=mean_anomaly_argo, sd=sd_anomaly_argo), aes(color="Gaussian"), size=1) +
  scale_fill_manual(values = "blue", name = NULL) +  # Legend for histogram bars
  scale_color_manual(values = "red", name = NULL) +  # Legend for Gaussian curve
  labs(subtitle="Argo floats",
       x="Temperature Anomaly",
       y="Density")


#CESM
mean_anomaly_cesm_full <- mean(CESM_natlantic_2023_subset$temp_anomaly, na.rm = TRUE)
sd_anomaly_cesm_full <- sd(CESM_natlantic_2023_subset$temp_anomaly, na.rm = TRUE)

cesm_hist_full<- ggplot(CESM_natlantic_2023_subset, aes(x=temp_anomaly)) +
  geom_histogram(aes(y=..density..), bins=30, fill="blue", alpha=0.5) +
  stat_function(fun=dnorm, args=list(mean=mean_anomaly_cesm_full, sd=sd_anomaly_cesm_full), color="red", size=1) +
  labs(subtitle='CESM - full extent', 
    x="Temperature Anomaly",
       y="Density") 


mean_anomaly_cesm <- mean(CESM_with_float$temp_anomaly, na.rm = TRUE)
sd_anomaly_cesm <- sd(CESM_with_float$temp_anomaly, na.rm = TRUE)

cesm_hist<- ggplot(CESM_with_float, aes(x=temp_anomaly)) +
  geom_histogram(aes(y=..density..), bins=30, fill="blue", alpha=0.5) +
  stat_function(fun=dnorm, args=list(mean=mean_anomaly_cesm, sd=sd_anomaly_cesm), color="red", size=1) +
  labs(subtitle='CESM - Argo extent', 
    x="Temperature Anomaly",
       y="Density") 

combined_plot<-argo_hist+cesm_hist+  cesm_hist_full+
  plot_layout(ncol = 3, guides = 'collect') +
  plot_annotation(
    title = 'Temperature Anomaly Distribution with Gaussian Curve',
    theme = theme(
      plot.title = element_text(size = 18),
      plot.subtitle = element_text(size = 14))
    )

combined_plot

Comparison CESM- ARGO

# Defining period of 2months and calculating monthly mean anomaly over the east area 
anomaly_CESM_2month_avg<-CESM_with_float %>% #CESM
  mutate(period=(as.numeric(month)+1)%/%2)

anomaly_CESM_2month_avg<-anomaly_CESM_2month_avg %>% #CESM
  group_by(depth, period) %>% 
  summarise(temp_count = n(),
            temp_anomaly_mean = mean(temp_anomaly , na.rm = TRUE),
            temp_anomaly_sd = sd(temp_anomaly , na.rm = TRUE))

anomaly_ARGO_2month_avg <- core_anomaly_2023_natlantic_subset %>% #ARGO
  mutate(period=(as.numeric(month)+1)%/%2)

anomaly_ARGO_2month_avg<-anomaly_ARGO_2month_avg %>% #CESM
  group_by(depth, period) %>% 
  summarise(temp_count = n(),
            temp_anomaly_mean = mean(anomaly , na.rm = TRUE),
            temp_anomaly_sd = sd(anomaly , na.rm = TRUE))

anomaly_CESM_entire_extent <- CESM_natlantic_2023_subset %>% #entire extent
    mutate(period=(as.numeric(month)+1)%/%2)

anomaly_CESM_entire_extent<-anomaly_CESM_entire_extent %>% #CESM
  group_by(depth, period) %>% 
  summarise(temp_count = n(),
            temp_anomaly_mean = mean(temp_anomaly , na.rm = TRUE),
            temp_anomaly_sd = sd(temp_anomaly , na.rm = TRUE))

anomaly_extents_diff_2month_avg<-difference_extent %>% #different extents
  mutate(period=(as.numeric(month)+1)%/%2)%>% 
  group_by(depth, period) %>% 
  summarise(temp_count = n(),
            temp_anomaly_mean = mean(diff_temp_anomaly_mean , na.rm = TRUE),
            temp_anomaly_sd = sd(diff_temp_anomaly_mean , na.rm = TRUE))


#PLot
ggplot() +
  #---ribbons
   # geom_ribbon(data=anomaly_CESM_entire_extent, aes(xmax = temp_anomaly_mean + temp_anomaly_sd,
   #                                              xmin = temp_anomaly_mean - temp_anomaly_sd,
   #                                              y = depth), fill = "#880D1E", alpha = 0.3) +
  geom_ribbon(data=anomaly_CESM_2month_avg, aes(xmax = temp_anomaly_mean + temp_anomaly_sd,
                                                xmin = temp_anomaly_mean - temp_anomaly_sd,
                                                y = depth), fill = "#FFBE0B", alpha = 0.2) +
  geom_ribbon(data=anomaly_ARGO_2month_avg, aes(xmax = temp_anomaly_mean + temp_anomaly_sd,
                                                xmin = temp_anomaly_mean - temp_anomaly_sd,
                                                y = depth), fill = "#7FC6A4", alpha = 0.2) +
  
  #---paths
  geom_path(data=anomaly_CESM_entire_extent , aes(x = temp_anomaly_mean, y = depth, color = "3"), linetype="dashed")+ #anomaly_extents_diff_2month_avg
  geom_path(data=anomaly_ARGO_2month_avg, aes(x = temp_anomaly_mean, y = depth, color = "1"), linetype="solid")+
  geom_path(data=anomaly_CESM_2month_avg, aes(x = temp_anomaly_mean, y = depth, color = "2"), linetype="solid") +

  #---settings (legend, ticks...)
  geom_vline(xintercept = 0) +
  scale_y_reverse() +
  coord_cartesian(xlim = c(-4, 4), ylim = c(200, 0)) +
  labs(title = paste('Propagation of SST anomalies in the water column'), 
       subtitle = paste0("Extent: ", name_extent, " North Atlantic bassin in 2023"),
       x = 'Temperature (°C)', y = 'Depth (m)') +
  theme(plot.title = element_text(size = 20), 
        plot.subtitle = element_text(size = 14),
    legend.position = "bottom",
        legend.title = element_blank(), 
        legend.key.height = unit(5, "lines"), 
    legend.text = element_text(size = 12)) +
  scale_color_manual(values = c("1" = "#4CA97C", 
                                "2" = "#F3712B", 
                                "3" = "#880D1E"),
                     labels = c( "ARGO", "CESM (ARGO extent)","CESM (full extent)")) + #CESM extents difference (full -ARGO)
  facet_wrap(~period, labeller = labeller(period = c("1"="Jan-Feb", 
                                                     "2"="Mar-Apr", 
                                                     "3"="May-Jun", 
                                                     "4"="Jul-Aug", 
                                                     "5"="Sep-Oct", 
                                                     "6"="Nov-Dec")), nrow=1)+
    guides(color = guide_legend(nrow = 1, override.aes = list(linetype = c("solid", "solid", "dashed"))))

Version Author Date
b21e0e6 mlarriere 2024-05-20

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] scico_1.3.1        patchwork_1.1.2    collapse_2.0.13    tidync_0.3.0      
 [5] marelac_2.1.10     shape_1.4.6        RColorBrewer_1.1-3 stars_0.6-0       
 [9] sf_1.0-9           abind_1.4-5        paletteer_1.6.0    cluster_2.1.6     
[13] gridExtra_2.3      viridis_0.6.2      viridisLite_0.4.1  lubridate_1.9.0   
[17] timechange_0.1.1   forcats_0.5.2      stringr_1.5.0      dplyr_1.1.3       
[21] purrr_1.0.2        readr_2.1.3        tidyr_1.3.0        tibble_3.2.1      
[25] ggplot2_3.4.4      tidyverse_1.3.2    workflowr_1.7.0   

loaded via a namespace (and not attached):
 [1] googledrive_2.0.0   colorspace_2.0-3    ellipsis_0.3.2     
 [4] class_7.3-20        rprojroot_2.0.3     fs_1.5.2           
 [7] rstudioapi_0.15.0   proxy_0.4-27        farver_2.1.1       
[10] fansi_1.0.3         xml2_1.3.3          ncdf4_1.22         
[13] cachem_1.0.6        knitr_1.41          jsonlite_1.8.3     
[16] gsw_1.1-1           broom_1.0.5         dbplyr_2.2.1       
[19] compiler_4.2.2      httr_1.4.4          backports_1.4.1    
[22] assertthat_0.2.1    fastmap_1.1.0       gargle_1.2.1       
[25] cli_3.6.1           later_1.3.0         htmltools_0.5.8.1  
[28] tools_4.2.2         gtable_0.3.1        glue_1.6.2         
[31] maps_3.4.1          Rcpp_1.0.10         cellranger_1.1.0   
[34] jquerylib_0.1.4     RNetCDF_2.6-1       vctrs_0.6.4        
[37] lwgeom_0.2-10       xfun_0.35           ps_1.7.2           
[40] rvest_1.0.3         lifecycle_1.0.3     ncmeta_0.3.5       
[43] googlesheets4_1.0.1 oce_1.7-10          getPass_0.2-2      
[46] scales_1.2.1        hms_1.1.2           promises_1.2.0.1   
[49] parallel_4.2.2      rematch2_2.1.2      yaml_2.3.6         
[52] sass_0.4.4          stringi_1.7.8       highr_0.9          
[55] e1071_1.7-12        rlang_1.1.1         pkgconfig_2.0.3    
[58] evaluate_0.18       SolveSAPHE_2.1.0    labeling_0.4.2     
[61] processx_3.8.0      tidyselect_1.2.0    seacarb_3.3.1      
[64] magrittr_2.0.3      R6_2.5.1            generics_0.1.3     
[67] DBI_1.2.2           pillar_1.9.0        haven_2.5.1        
[70] whisker_0.4         withr_2.5.0         units_0.8-0        
[73] modelr_0.1.10       crayon_1.5.2        KernSmooth_2.23-20 
[76] utf8_1.2.2          tzdb_0.3.0          rmarkdown_2.18     
[79] grid_4.2.2          readxl_1.4.1        callr_3.7.3        
[82] git2r_0.30.1        reprex_2.0.2        digest_0.6.30      
[85] classInt_0.4-8      httpuv_1.6.6        munsell_0.5.0      
[88] bslib_0.4.1