Last updated: 2020-12-21

Checks: 7 0

Knit directory: MHWflux/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(666) 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 949244e. 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/ALL_anom.Rda
    Ignored:    data/ALL_other.Rda
    Ignored:    data/ALL_ts_anom.Rda
    Ignored:    data/ERA5_down.Rda
    Ignored:    data/ERA5_down_anom.Rda
    Ignored:    data/ERA5_evp_anom.Rda
    Ignored:    data/ERA5_lhf_anom.Rda
    Ignored:    data/ERA5_lwr_anom.Rda
    Ignored:    data/ERA5_mslp_anom.Rda
    Ignored:    data/ERA5_pcp_anom.Rda
    Ignored:    data/ERA5_qnet_anom.Rda
    Ignored:    data/ERA5_shf_anom.Rda
    Ignored:    data/ERA5_swr_MLD.Rda
    Ignored:    data/ERA5_swr_anom.Rda
    Ignored:    data/ERA5_t2m_anom.Rda
    Ignored:    data/ERA5_tcc_anom.Rda
    Ignored:    data/ERA5_u_anom.Rda
    Ignored:    data/ERA5_v_anom.Rda
    Ignored:    data/GLORYS_all_anom.Rda
    Ignored:    data/OISST_all_anom.Rda
    Ignored:    data/packet.Rda
    Ignored:    data/som.Rda
    Ignored:    data/synoptic_states.Rda
    Ignored:    data/synoptic_states_other.Rda

Unstaged changes:
    Modified:   code/functions.R
    Modified:   data/ALL_cor.Rda
    Modified:   data/ALL_ts_anom_cum.Rda
    Modified:   output/magnitude_schematic.pdf
    Modified:   shiny/ALL_cor.Rda
    Modified:   shiny/ALL_ts_anom_cum.Rda
    Modified:   shiny/app.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/som.Rmd) and HTML (docs/som.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 4a00400 robwschlegel 2020-12-21 Build site.
html 65f38bf robwschlegel 2020-12-21 Build site.
html 33f4595 robwschlegel 2020-11-10 Build site.
html a438235 robwschlegel 2020-11-10 Build site.
Rmd cbc5b74 robwschlegel 2020-11-10 Re-built site.
Rmd e513e01 robwschlegel 2020-10-09 Added Qsw* to the SOM data and removed the SOM correlation figure
Rmd 54144a7 robwschlegel 2020-09-28 Working on non-numeric node labels
Rmd 5bfa2a7 robwschlegel 2020-09-03 Push before beginning large structural additions to app
html 8d65758 robwschlegel 2020-09-03 Build site.
Rmd d1c9bad robwschlegel 2020-09-03 Re-built site.
Rmd 66f3736 robwschlegel 2020-08-26 More edits to the figures
Rmd 4b04d7a robwschlegel 2020-08-14 Renamed some files in preparation for the file runs on the SOM sized data
Rmd c0c599d robwschlegel 2020-08-12 Combining the MHWNWA and MHWflux code bases

Introduction

This vignette contains the code used to perform the self-organising map (SOM) analysis on the mean synoptic states created in the data preparation vignette. We’ll start by creating custom packets that meet certain experimental criteria before feeding them into a SOM.

# Load functions and objects to be used below
source("code/functions.R")

Data packet

In this step we will create a data packet that can be fed directly into the SOM algorithm. This means that it must be converted into a super-wide matrix format. In the first run of this analysis on the NAPA model data it was found that the inclusion of the Labrador Sea complicated the results quite a bit. It was also unclear whether or not the Gulf of St Lawrence (GSL) region should be included in the analysis. So in the second run of this analysis multiple different SOM variations were employed and it was decided that the GSL region should be included.

Prep synoptic state packets

Up first we must create the synoptic state packets.

# Set number of cores
  # NB: 50 cores uses too much RAM
registerDoParallel(cores = 20)

# Load needed data
ALL_anom <- readRDS("data/ALL_anom.Rda")
ALL_other <- readRDS("data/ALL_other.Rda")

# Create one big anomaly packet from OISST data
system.time(synoptic_states <- plyr::ddply(OISST_MHW_event, c("region", "event_no"),
                                           data_packet_func, .parallel = T, df = ALL_anom)) # 129 seconds
# Save
saveRDS(synoptic_states, "data/synoptic_states.Rda")

# Create other synoptic states per MHW per variable
doParallel::registerDoParallel(cores = 10) # NB: Be careful here...
system.time(synoptic_states_other <- plyr::ddply(OISST_MHW_event, c("region", "event_no"),
                                                 data_packet_func, .parallel = T, df = ALL_other)) # 212 seconds
# Save
saveRDS(synoptic_states_other, "data/synoptic_states_other.Rda")

Create SOM packet

With all of our data ready we may now prepare and save them for the SOM.

## Create wide data packet that is fed to SOM
system.time(packet <- synoptic_states %>%
              select(region, event_no, synoptic) %>%
              unnest(cols = "synoptic") %>%
              wide_packet_func()) # 79 seconds

# Save
saveRDS(packet, "data/packet.Rda")

Run SOM models

Now we feed the SOM with a function that ingests the data packet and produces results for us. The function below has been greatly expanded on from the previous version of this project and now performs all of the SOM related work in one go. This allowed me to remove a couple hundreds lines of code and text from this vignette.

# # OISST SOM analysis
packet <- readRDS("data/packet.Rda")
synoptic_states_other <- readRDS("data/synoptic_states_other.Rda")
system.time(som <- som_model_PCI(packet, synoptic_states_other)) # 176 seconds
saveRDS(som, file = "data/som.Rda")
# saveRDS(som, file = "shiny/som.Rda")

References


sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] doParallel_1.0.16    iterators_1.0.13     foreach_1.5.1       
 [4] Metrics_0.1.4        yasomi_0.3           proxy_0.4-24        
 [7] e1071_1.7-4          ggraph_2.0.3         correlation_0.4.0   
[10] tidync_0.2.4         heatwaveR_0.4.4.9004 lubridate_1.7.9.2   
[13] data.table_1.13.2    forcats_0.5.0        stringr_1.4.0       
[16] dplyr_1.0.2          purrr_0.3.4          readr_1.4.0         
[19] tidyr_1.1.2          tibble_3.0.4         ggplot2_3.3.2       
[22] tidyverse_1.3.0     

loaded via a namespace (and not attached):
 [1] fs_1.5.0           insight_0.10.0     httr_1.4.2         rprojroot_2.0.2   
 [5] tools_4.0.3        backports_1.2.0    R6_2.5.0           DBI_1.1.0         
 [9] lazyeval_0.2.2     colorspace_2.0-0   withr_2.3.0        gridExtra_2.3     
[13] tidyselect_1.1.0   compiler_4.0.3     git2r_0.27.1       cli_2.1.0         
[17] rvest_0.3.6        RNetCDF_2.4-2      xml2_1.3.2         plotly_4.9.2.1    
[21] bayestestR_0.7.5   scales_1.1.1       digest_0.6.27      rmarkdown_2.5     
[25] pkgconfig_2.0.3    htmltools_0.5.0    dbplyr_2.0.0       htmlwidgets_1.5.2 
[29] rlang_0.4.8        readxl_1.3.1       rstudioapi_0.13    generics_0.1.0    
[33] farver_2.0.3       jsonlite_1.7.1     magrittr_2.0.1     ncmeta_0.3.0      
[37] parameters_0.9.0   Rcpp_1.0.5         munsell_0.5.0      fansi_0.4.1       
[41] viridis_0.5.1      lifecycle_0.2.0    stringi_1.5.3      whisker_0.4       
[45] yaml_2.2.1         MASS_7.3-53        grid_4.0.3         promises_1.1.1    
[49] ggrepel_0.8.2      crayon_1.3.4       graphlayouts_0.7.1 haven_2.3.1       
[53] hms_0.5.3          knitr_1.30         pillar_1.4.6       igraph_1.2.6      
[57] effectsize_0.4.0   codetools_0.2-18   reprex_0.3.0       glue_1.4.2        
[61] evaluate_0.14      modelr_0.1.8       vctrs_0.3.5        tweenr_1.0.1      
[65] httpuv_1.5.4       cellranger_1.1.0   gtable_0.3.0       polyclip_1.10-0   
[69] assertthat_0.2.1   xfun_0.19          ggforce_0.3.2      broom_0.7.2       
[73] tidygraph_1.2.0    later_1.1.0.1      class_7.3-17       ncdf4_1.17        
[77] viridisLite_0.3.0  workflowr_1.6.2    ellipsis_0.3.1