Last updated: 2024-06-13

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 1f9b82a. 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:    .RData
    Ignored:    .Rproj.user/
    Ignored:    analysis/poster_profile_argo.png

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/_site.yml
    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 1f9b82a mlarriere 2024-06-13 cleaning code
html dd3575b mlarriere 2024-06-06 Build site.
Rmd af4f63d mlarriere 2024-06-06 cleaning code
html dab83a4 mlarriere 2024-05-24 Build site.
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

Heatwaves_RunA.nc - CESM outputs (run A) - variable of interest: thetao (seawater potential temperature [°C])

Outputs

CESM_temp2023.rds - seawater potential temperature in 2023, output of the CESM

CESM_temp_anomaly2023_clim2004-2019.rds - climatology of seawater potential temperature in the period 2004-2019, output of the CESM

#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

#base map
world_coordinates <- map_data("world") 

#year of interest
target_year<-2023
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==target_year)
gc()
#Write CESM outputs for 2023 to file
write_rds(CESM_temp_2023,
          file = paste0(path_argo_core_preprocessed,"/", "CESM_temp", target_year,".rds"))
CESM_temp_2023<- read_rds(file = paste0(path_argo_core_preprocessed,"/", "CESM_temp", target_year,".rds"))

# Visualization
CESM_temp_2023 %>%
  filter(depth == 5) %>%
  ggplot(aes(lon, lat, fill = temp)) +
  geom_raster() +
  geom_map(data = world_coordinates, map = world_coordinates, aes(long, lat, map_id = region), fill = "grey") +
  scale_fill_viridis_c(option = "plasma") +
  labs(title = "Monthly visualisation of CESM seawater potential temperature",
       subtitle = paste0("depth=5m, year: ", target_year))+
  coord_quickmap(expand = 0)+
  theme(legend.key.width = unit(0.5, "cm"),
        legend.key.height = unit(2, "cm"))+
  facet_wrap(~month, nrow = 3)

Version Author Date
dd3575b mlarriere 2024-06-06
dab83a4 mlarriere 2024-05-24
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)

#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_anomaly", target_year,"_clim2004-2019.rds"))

rm(CESM_anomaly_2023, CESM_temp_2004_2019)
gc()
# Read data
CESM_anomaly_2023<-read_rds(file =paste0(path_argo_core_preprocessed,"/", "CESM_temp_anomaly", target_year,"_clim2004-2019.rds"))

# Visualization
CESM_anomaly_2023 %>%
  filter(depth == 5) %>%
  ggplot(aes(lon, lat, fill = temp_anomaly)) +
  geom_raster() +
  geom_map(data = world_coordinates, map = world_coordinates, aes(long, lat, map_id = region), fill = "grey") +
  scale_fill_gradient2(name='T°C anomaly', low = "darkblue", high = "darkred")+  
  labs(title = "CESM temperature anomalies - 2023",
       subtitle = paste0("depth=5m, clim: 2004-2019, extent: ", name_extent))+
  coord_quickmap(expand = 0)+
  theme(legend.key.width = unit(0.5, "cm"),
        legend.key.height = unit(2, "cm"))+
  facet_wrap(~month, nrow = 3)

Version Author Date
dd3575b mlarriere 2024-06-06
b21e0e6 mlarriere 2024-05-20
7f729d4 mlarriere 2024-05-16
#Area of interest: eastern north atlantic
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 of the sea surface temperature anomalies in the chosen region
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") +
  lims(x = c(chosen_extent$lon_min, chosen_extent$lon_max), y=c(chosen_extent$lat_min, chosen_extent$lat_max)) + 
  scale_fill_gradient2(name='T°C anomaly', low = "darkblue", high = "darkred")+  
  labs(title = paste0("CESM temperature anomaly in ", target_year),
       subtitle = paste0("depth=5m, climatological period: 2004-2019"))+
  coord_quickmap(expand = 0)+
  facet_wrap(~month, nrow = 3)+
  theme(legend.key.width = unit(0.5, "cm"),
        legend.key.height = unit(2, "cm"))

Version Author Date
dd3575b mlarriere 2024-06-06
dab83a4 mlarriere 2024-05-24
b21e0e6 mlarriere 2024-05-20

Argo

Read data

Float location

#dataset with the CESM output with Argo extent, i.e. where Argo are present temporally and spatially
CESM_argo_extent <- 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_argo_extent, FUN = function(x) length(unique(x)))
cycle_count_per_platform_month <- CESM_argo_extent %>%
  group_by(month, platform_number) %>%
  summarise(cycle_count = n_distinct(cycle_number))

Float distribution

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

#Number of platform present in each lat/lon location per month 
float_monthly_count <- CESM_argo_extent %>%
  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") +
  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, annual average 2023",
       subtitle = "Resolution: 1°x1°",
       x='Longitude', y='Latitude',
       fill = "SST \nanomalies [°C]")+
  coord_quickmap(expand = 0)+
  theme(plot.title = element_text(size = 26), 
        plot.subtitle = element_text(size = 24),
        legend.text = element_text(size = 20), 
        legend.title = element_text(size = 20),
        axis.title.x = element_text(size = 20),
        axis.title.y = element_text(size = 20),
        axis.text.x = element_text(size = 18),   
        axis.text.y = element_text(size = 18),
        legend.key.width = unit(0.3, "cm"),
        legend.key.height = unit(2, "cm")
        )

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°",
       x='Longitude', y='Latitude',
       color = "Months \nwith float") +
  scale_color_scico(palette = "oslo", breaks = seq(1, 12, by = 1), limits = c(1, 12), direction=-1) +
  coord_quickmap(expand = 0) +
  theme(plot.title = element_text(size = 26), 
        plot.subtitle = element_text(size = 24),
        legend.text = element_text(size = 20), 
        legend.title = element_text(size = 20),
        axis.title.x = element_text(size = 20),
        axis.title.y = element_text(size = 20),
        axis.text.x = element_text(size = 18),   
        axis.text.y = element_text(size = 18),
        legend.key.width = unit(0.3, "cm"),
        legend.key.height = unit(2, "cm")
        )



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

Version Author Date
dd3575b mlarriere 2024-06-06
dab83a4 mlarriere 2024-05-24
b21e0e6 mlarriere 2024-05-20

Single Float

Floats located in the Eddies Corridor (Canary Islands)

#CESM output
unique_platform_CEM<-CESM_argo_extent %>%
  filter(platform_number==1902323)

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

#Plots
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 anomaly [°C]', y = 'Depth [m]', color = 'Months') +
    theme(plot.title = element_text(size = 18), 
        plot.subtitle = element_text(size = 16),
        axis.title.x = element_text(size = 14), 
        axis.title.y = element_text(size = 14),  
        axis.text.x = element_text(size = 12),   
        axis.text.y = element_text(size = 12),
        legend.text = element_text(size = 12),
        legend.title = element_text(size = 14, face = "bold"),
        legend.key.height = unit(1, "cm"))


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 anomaly [°C]', y = 'Depth [m]', color = 'Months') +
    theme(plot.title = element_text(size = 18), 
        plot.subtitle = element_text(size = 16),
        axis.title.x = element_text(size = 14), 
        axis.title.y = element_text(size = 14),  
        axis.text.x = element_text(size = 12),   
        axis.text.y = element_text(size = 12),
        legend.position = "none")


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 = 16)
      )
    )
combined_plot

Version Author Date
dd3575b mlarriere 2024-06-06
dab83a4 mlarriere 2024-05-24
b21e0e6 mlarriere 2024-05-20
7f729d4 mlarriere 2024-05-16

Coloring by lat/lon

Inspection of the potential spatial gradient captured by the CESM that may influence the SST anomalies penetration: longitude and latitude gradients.

#Calculating monthly mean anomaly for each platform cycle as function of lat/lon in the eastern North Atlantic
anomaly_lat_lon <- CESM_argo_extent %>%
  group_by(lat, lon, depth, month, platform_number, cycle_number) %>%
  summarise(temp_anomaly_mean = mean(temp_anomaly, na.rm = TRUE))

# Longitude - gradient west-east 
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(x = 'Temperature anomaly [°C]', y = 'Depth [m]', color = "Longitude") +
  scale_color_viridis_c()+
  theme(plot.title = element_text(size = 18),
        plot.subtitle = element_text(size = 15),
        axis.title.x = element_text(size = 15), 
        axis.title.y = element_text(size = 15),  
        axis.text.x = element_text(size = 15),   
        axis.text.y = element_text(size = 15),        
        legend.text = element_text(size = 15), 
        legend.title = element_text(size = 15, face = "bold"), 
        legend.key.width = unit(0.3, "cm"),
        legend.key.height = unit(1, "cm"))


# Latitude - gradient north-south
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(x = 'Temperature anomaly [°C]', y = 'Depth [m]', color = "Latitude") +
  scale_color_viridis_c()+
  theme(plot.title = element_text(size = 18),
        plot.subtitle = element_text(size = 15),
        axis.title.x = element_text(size = 15), 
        axis.title.y = element_text(size = 15),  
        axis.text.x = element_text(size = 15),   
        axis.text.y = element_text(size = 15),        
        legend.text = element_text(size = 15), 
        legend.title = element_text(size = 15, face = "bold"), 
        legend.key.width = unit(0.3, "cm"),
        legend.key.height = unit(1, "cm"))

combined_plot <- latitude + longitude + plot_layout(ncol = 1)+
  plot_annotation(title = 'Latitude and longitude gradients',
                  subtitle = "All floats and cycles included",
                  theme = theme(plot.title = element_text(size = 18),
                                plot.subtitle = element_text(size = 16)))
combined_plot

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

CESM model truth

We refer to model truth for the CESM full extent

# Calculating monthly mean anomaly over the east area by averaging the anomaly of each float present
#---Argo extent of the CESM
CESM_argo_extent_anomaly<-CESM_argo_extent %>% 
  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))

#---full extent of the CESM
CESM_full_extent_anomaly <- 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))

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


# difference between argo vs full extent of the CESM
difference_extent<- merge(CESM_full_extent_anomaly, CESM_argo_extent_anomaly, 
                          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  

Statistical distributions of the anomaly

#---ARGO
# annual average (mean + std dev)
yearly_mean_anomaly_argo <- mean(core_anomaly_2023_natlantic_subset$anomaly, na.rm = TRUE)
yearly_std_anomaly_argo <- sd(core_anomaly_2023_natlantic_subset$anomaly, na.rm = TRUE)

# Histogram
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=yearly_mean_anomaly_argo, 
                                     sd=yearly_std_anomaly_argo), aes(color="Gaussian"), size=1) +
  scale_fill_manual(values = "blue", name = 'Legend') +  
  scale_color_manual(values = "red", name = 'Legend') + 
  theme(plot.subtitle = element_text(size = 15))+
  labs(subtitle="Argo floats",
       x="Temperature Anomaly",
       y="Density")

#--- CESM - argo extent
# annual average (mean + std dev)
yearly_mean_anomaly_cesm_argo_extent <- mean(CESM_argo_extent$temp_anomaly, na.rm = TRUE)
yearly_sd_anomaly_cesm_argo_extent <- sd(CESM_argo_extent$temp_anomaly, na.rm = TRUE)

# Histogram
cesm_hist<- ggplot(CESM_argo_extent, aes(x=temp_anomaly)) +
  geom_histogram(aes(y=..density..), bins=30, fill="blue", alpha=0.5) +
  stat_function(fun=dnorm, args=list(mean=yearly_mean_anomaly_cesm_argo_extent,
                                     sd=yearly_sd_anomaly_cesm_argo_extent), aes(color="Gaussian"), size=1) +

  scale_fill_manual(values = "blue", name = 'Legend') +  
  scale_color_manual(values = "red", name = 'Legend') +
  labs(subtitle='CESM - Argo extent', 
       x="Temperature Anomaly",
       y="Density") +
 theme(plot.subtitle = element_text(size = 15),
       legend.position = "none"
       )
    
#--- CESM - model truth
# annual average (mean + std dev)
yearly_mean_anomaly_cesm_full <- mean(CESM_natlantic_2023_subset$temp_anomaly, na.rm = TRUE)
yearly_std_anomaly_cesm_full <- sd(CESM_natlantic_2023_subset$temp_anomaly, na.rm = TRUE)

# Histogram
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=yearly_mean_anomaly_cesm_full, 
                                     sd=yearly_std_anomaly_cesm_full), aes(color="Gaussian"), size=1) +
  scale_fill_manual(values = "blue", name = 'Legend') +  
  scale_color_manual(values = "red", name = 'Legend') +
  theme(plot.subtitle = element_text(size = 15),
         legend.text = element_text(size = 14),
        legend.title = element_text(size = 15))+
  labs(subtitle='CESM - full extent', 
    x="Temperature Anomaly",
       y="Density") 

#combining plots
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)))

combined_plot

Comparison CESM-ARGO

# Defining period of 2months and calculating monthly mean anomaly and sdt dev over the area of interest
#---Argo extent of the CESM
CESM_2month_avg_argo_extent<-CESM_argo_extent %>%
  mutate(period=(as.numeric(month)+1)%/%2)

CESM_2month_avg_argo_extent<-CESM_2month_avg_argo_extent %>% 
  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))

#---argo observations
argo_2month_avg <- core_anomaly_2023_natlantic_subset %>%
  mutate(period=(as.numeric(month)+1)%/%2)

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

#---full extent of the CESM
CESM_2month_avg_full_extent <- CESM_natlantic_2023_subset %>% 
    mutate(period=(as.numeric(month)+1)%/%2)

CESM_2month_avg_full_extent<-CESM_2month_avg_full_extent %>% 
  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))

#difference between the CESM extents
diff_2month_avg_CESM<-difference_extent %>% 
  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=CESM_2month_avg_argo_extent, aes(xmax = temp_anomaly_mean + temp_anomaly_sd,
                                                xmin = temp_anomaly_mean - temp_anomaly_sd,
                                                y = depth), fill = "#E9BA20", alpha = 0.2) +
  geom_ribbon(data=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=CESM_2month_avg_full_extent , aes(x = temp_anomaly_mean, y = depth, color = "3"), linetype="dashed", size=1)+ #diff_2month_avg_CESM
  geom_path(data=argo_2month_avg, aes(x = temp_anomaly_mean, y = depth, color = "1"), linetype="solid", size=1)+
  geom_path(data=CESM_2month_avg_argo_extent, aes(x = temp_anomaly_mean, y = depth, color = "2"), linetype="solid", size=1) +

  #---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 anomaly [°C]', y = 'Depth [m]') +
  theme(plot.title = element_text(size = 18), 
        plot.subtitle = element_text(size = 16),
         axis.title.x = element_text(size = 14), 
        axis.title.y = element_text(size = 14),  
        axis.text.x = element_text(size = 12),   
        axis.text.y = element_text(size = 12),
        strip.text = element_text(size = 14),
        legend.position = "bottom",
        legend.title = element_blank(), 
        legend.key.height = unit(8, "lines"), 
    legend.text = element_text(size = 12)) +
  scale_color_manual(values = c("1" = "#4CA97C", 
                                "2" = "#F3712B", #822E81
                                "3" = "#880D1E"), #black
                     labels = c( "ARGO", "CESM (Argo extent)","CESM (model truth)")) + #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=2)+
  
    guides(color = guide_legend(nrow = 1, override.aes = list(linetype = c("solid", "solid", "dashed"), size = 15)))

Version Author Date
dd3575b mlarriere 2024-06-06
dab83a4 mlarriere 2024-05-24
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