<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />


<meta name="author" content="Robert Schlegel" />

<meta name="date" content="2019-07-24" />

<title>SST preparation</title>

<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="site_libs/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<link href="site_libs/highlightjs-9.12.0/textmate.css" rel="stylesheet" />
<script src="site_libs/highlightjs-9.12.0/highlight.js"></script>
<link href="site_libs/font-awesome-5.0.13/css/fa-svg-with-js.css" rel="stylesheet" />
<script src="site_libs/font-awesome-5.0.13/js/fontawesome-all.min.js"></script>
<script src="site_libs/font-awesome-5.0.13/js/fa-v4-shims.min.js"></script>

<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
  pre:not([class]) {
    background-color: white;
  }
</style>
<script type="text/javascript">
if (window.hljs) {
  hljs.configure({languages: []});
  hljs.initHighlightingOnLoad();
  if (document.readyState && document.readyState === "complete") {
    window.setTimeout(function() { hljs.initHighlighting(); }, 0);
  }
}
</script>



<style type="text/css">
h1 {
  font-size: 34px;
}
h1.title {
  font-size: 38px;
}
h2 {
  font-size: 30px;
}
h3 {
  font-size: 24px;
}
h4 {
  font-size: 18px;
}
h5 {
  font-size: 16px;
}
h6 {
  font-size: 12px;
}
.table th:not([align]) {
  text-align: left;
}
</style>


</head>

<body>

<style type = "text/css">
.main-container {
  max-width: 940px;
  margin-left: auto;
  margin-right: auto;
}
code {
  color: inherit;
  background-color: rgba(0, 0, 0, 0.04);
}
img {
  max-width:100%;
  height: auto;
}
.tabbed-pane {
  padding-top: 12px;
}
.html-widget {
  margin-bottom: 20px;
}
button.code-folding-btn:focus {
  outline: none;
}
</style>


<style type="text/css">
/* padding for bootstrap navbar */
body {
  padding-top: 51px;
  padding-bottom: 40px;
}
/* offset scroll position for anchor links (for fixed navbar)  */
.section h1 {
  padding-top: 56px;
  margin-top: -56px;
}

.section h2 {
  padding-top: 56px;
  margin-top: -56px;
}
.section h3 {
  padding-top: 56px;
  margin-top: -56px;
}
.section h4 {
  padding-top: 56px;
  margin-top: -56px;
}
.section h5 {
  padding-top: 56px;
  margin-top: -56px;
}
.section h6 {
  padding-top: 56px;
  margin-top: -56px;
}
</style>

<script>
// manage active state of menu based on current page
$(document).ready(function () {
  // active menu anchor
  href = window.location.pathname
  href = href.substr(href.lastIndexOf('/') + 1)
  if (href === "")
    href = "index.html";
  var menuAnchor = $('a[href="' + href + '"]');

  // mark it active
  menuAnchor.parent().addClass('active');

  // if it's got a parent navbar menu mark it active as well
  menuAnchor.closest('li.dropdown').addClass('active');
});
</script>


<div class="container-fluid main-container">

<!-- tabsets -->
<script>
$(document).ready(function () {
  window.buildTabsets("TOC");
});
</script>

<!-- code folding -->




<script>
$(document).ready(function ()  {

    // move toc-ignore selectors from section div to header
    $('div.section.toc-ignore')
        .removeClass('toc-ignore')
        .children('h1,h2,h3,h4,h5').addClass('toc-ignore');

    // establish options
    var options = {
      selectors: "h1,h2,h3",
      theme: "bootstrap3",
      context: '.toc-content',
      hashGenerator: function (text) {
        return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase();
      },
      ignoreSelector: ".toc-ignore",
      scrollTo: 0
    };
    options.showAndHide = true;
    options.smoothScroll = true;

    // tocify
    var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>

<style type="text/css">

#TOC {
  margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
  position: relative;
  width: 100%;
}
}


.toc-content {
  padding-left: 30px;
  padding-right: 40px;
}

div.main-container {
  max-width: 1200px;
}

div.tocify {
  width: 20%;
  max-width: 260px;
  max-height: 85%;
}

@media (min-width: 768px) and (max-width: 991px) {
  div.tocify {
    width: 25%;
  }
}

@media (max-width: 767px) {
  div.tocify {
    width: 100%;
    max-width: none;
  }
}

.tocify ul, .tocify li {
  line-height: 20px;
}

.tocify-subheader .tocify-item {
  font-size: 0.90em;
  padding-left: 25px;
  text-indent: 0;
}

.tocify .list-group-item {
  border-radius: 0px;
}


</style>

<!-- setup 3col/9col grid for toc_float and main content  -->
<div class="row-fluid">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>

<div class="toc-content col-xs-12 col-sm-8 col-md-9">




<div class="navbar navbar-default  navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="index.html">MHW Northwest Atlantic</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li>
  <a href="index.html">Overview</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
    Analyses
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
    <li>
      <a href="polygon-prep.html">Polygon preparation</a>
    </li>
    <li>
      <a href="sst-prep.html">SST preparation</a>
    </li>
    <li>
      <a href="var-prep.html">Variable preparation</a>
    </li>
    <li>
      <a href="som.html">SOM analysis</a>
    </li>
    <li>
      <a href="figures.html">Figure creation</a>
    </li>
    <li>
      <a href="node-summary.html">Node summary</a>
    </li>
  </ul>
</li>
<li>
  <a href="license.html">License</a>
</li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li>
  <a href="https://github.com/robwschlegel/MHWNWA">
    <span class="fa fa-github"></span>
     
    Source code
  </a>
</li>
      </ul>
    </div><!--/.nav-collapse -->
  </div><!--/.container -->
</div><!--/.navbar -->

<!-- Add a small amount of space between sections. -->
<style type="text/css">
div.section {
  padding-top: 12px;
}
</style>

<div class="fluid-row" id="header">



<h1 class="title toc-ignore">SST preparation</h1>
<h4 class="author"><em>Robert Schlegel</em></h4>
<h4 class="date"><em>2019-07-24</em></h4>

</div>


<p><strong>Last updated:</strong> 2019-08-07</p>
<strong>workflowr checks:</strong> <small>(Click a bullet for more information)</small>
<ul>
<li>
<details>
<p><summary> <strong style="color:blue;">✔</strong> <strong>R Markdown file:</strong> up-to-date </summary></p>
<p>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.</p>
</details>
</li>
<li>
<details>
<p><summary> <strong style="color:blue;">✔</strong> <strong>Environment:</strong> empty </summary></p>
<p>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.</p>
</details>
</li>
<li>
<details>
<p><summary> <strong style="color:blue;">✔</strong> <strong>Seed:</strong> <code>set.seed(20190513)</code> </summary></p>
<p>The command <code>set.seed(20190513)</code> 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.</p>
</details>
</li>
<li>
<details>
<p><summary> <strong style="color:blue;">✔</strong> <strong>Session information:</strong> recorded </summary></p>
<p>Great job! Recording the operating system, R version, and package versions is critical for reproducibility.</p>
</details>
</li>
<li>
<details>
<p><summary> <strong style="color:blue;">✔</strong> <strong>Repository version:</strong> <a href="https://github.com/robwschlegel/MHWNWA/tree/9d817225c856d81f3581b7c8311c0e1fa2670e6b" target="_blank">9d81722</a> </summary></p>
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated. <br><br> 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 <code>wflow_publish</code> or <code>wflow_git_commit</code>). 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:
<pre><code>
Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/ALL_anom.Rda
    Ignored:    data/ALL_clim.Rda
    Ignored:    data/ERA5_lhf.Rda
    Ignored:    data/ERA5_lwr.Rda
    Ignored:    data/ERA5_qnet.Rda
    Ignored:    data/ERA5_qnet_anom.Rda
    Ignored:    data/ERA5_qnet_clim.Rda
    Ignored:    data/ERA5_shf.Rda
    Ignored:    data/ERA5_swr.Rda
    Ignored:    data/ERA5_t2m.Rda
    Ignored:    data/ERA5_t2m_anom.Rda
    Ignored:    data/ERA5_t2m_clim.Rda
    Ignored:    data/ERA5_u.Rda
    Ignored:    data/ERA5_u_anom.Rda
    Ignored:    data/ERA5_u_clim.Rda
    Ignored:    data/ERA5_v.Rda
    Ignored:    data/ERA5_v_anom.Rda
    Ignored:    data/ERA5_v_clim.Rda
    Ignored:    data/GLORYS_mld.Rda
    Ignored:    data/GLORYS_mld_anom.Rda
    Ignored:    data/GLORYS_mld_clim.Rda
    Ignored:    data/GLORYS_u.Rda
    Ignored:    data/GLORYS_u_anom.Rda
    Ignored:    data/GLORYS_u_clim.Rda
    Ignored:    data/GLORYS_v.Rda
    Ignored:    data/GLORYS_v_anom.Rda
    Ignored:    data/GLORYS_v_clim.Rda
    Ignored:    data/NAPA_clim_U.Rda
    Ignored:    data/NAPA_clim_V.Rda
    Ignored:    data/NAPA_clim_W.Rda
    Ignored:    data/NAPA_clim_emp_ice.Rda
    Ignored:    data/NAPA_clim_emp_oce.Rda
    Ignored:    data/NAPA_clim_fmmflx.Rda
    Ignored:    data/NAPA_clim_mldkz5.Rda
    Ignored:    data/NAPA_clim_mldr10_1.Rda
    Ignored:    data/NAPA_clim_qemp_oce.Rda
    Ignored:    data/NAPA_clim_qla_oce.Rda
    Ignored:    data/NAPA_clim_qns.Rda
    Ignored:    data/NAPA_clim_qsb_oce.Rda
    Ignored:    data/NAPA_clim_qt.Rda
    Ignored:    data/NAPA_clim_runoffs.Rda
    Ignored:    data/NAPA_clim_ssh.Rda
    Ignored:    data/NAPA_clim_sss.Rda
    Ignored:    data/NAPA_clim_sst.Rda
    Ignored:    data/NAPA_clim_taum.Rda
    Ignored:    data/NAPA_clim_vars.Rda
    Ignored:    data/NAPA_clim_vecs.Rda
    Ignored:    data/OAFlux.Rda
    Ignored:    data/OISST_sst.Rda
    Ignored:    data/OISST_sst_anom.Rda
    Ignored:    data/OISST_sst_clim.Rda
    Ignored:    data/node_mean_all_anom.Rda
    Ignored:    data/packet_all.Rda
    Ignored:    data/packet_all_anom.Rda
    Ignored:    data/packet_nolab.Rda
    Ignored:    data/packet_nolab14.Rda
    Ignored:    data/packet_nolabgsl.Rda
    Ignored:    data/packet_nolabmod.Rda
    Ignored:    data/som_all.Rda
    Ignored:    data/som_all_anom.Rda
    Ignored:    data/som_nolab.Rda
    Ignored:    data/som_nolab14.Rda
    Ignored:    data/som_nolab_16.Rda
    Ignored:    data/som_nolab_9.Rda
    Ignored:    data/som_nolabgsl.Rda
    Ignored:    data/som_nolabmod.Rda
    Ignored:    data/synoptic_states.Rda
    Ignored:    data/synoptic_vec_states.Rda

Unstaged changes:
    Modified:   code/workflow.R

</code></pre>
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.
</details>
</li>
</ul>
<details>
<summary> <small><strong>Expand here to see past versions:</strong></small> </summary>
<ul>
<table style="border-collapse:separate; border-spacing:5px;">
<thead>
<tr>
<th style="text-align:left;">
File
</th>
<th style="text-align:left;">
Version
</th>
<th style="text-align:left;">
Author
</th>
<th style="text-align:left;">
Date
</th>
<th style="text-align:left;">
Message
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/9a9fa7dcbb3784879c40ef4f5592c0401e0aba05/analysis/sst-prep.Rmd" target="_blank">9a9fa7d</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-08-01
</td>
<td style="text-align:left;">
A more in depth dive into the potential criteria to meet for the SOM model
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/aa82e6e565dc2e79a3152f77684953031971619b/docs/sst-prep.html" target="_blank">aa82e6e</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-31
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/51ed68129cb0c4bd1a7b96e371286abb5c5c5c9e/analysis/sst-prep.Rmd" target="_blank">51ed681</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-25
</td>
<td style="text-align:left;">
Completed anoms for OISST
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/0b6f065fff7bcf1f69b59f83ad7f5383649a54b0/analysis/sst-prep.Rmd" target="_blank">0b6f065</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-25
</td>
<td style="text-align:left;">
Push before beginning to write code for loading entire obs/reanalysis products into memory for clim calculations
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/7792f2489ae2ec1a2b8ab79e3bd63e280c67f3e6/docs/sst-prep.html" target="_blank">7792f24</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-24
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/bcee69836e357b19e2ef396a0de9b4964bd22f07/analysis/sst-prep.Rmd" target="_blank">bcee698</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-24
</td>
<td style="text-align:left;">
Edited the polygon and sst prep vignettes while redoing methodology.
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/7cc8ec3c2187c5f1b0efba9c358b1421156c6cb7/docs/sst-prep.html" target="_blank">7cc8ec3</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-24
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/463b89a0b52d3f50b13fee163488583e6fa4db5d/analysis/sst-prep.Rmd" target="_blank">463b89a</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-24
</td>
<td style="text-align:left;">
Edited the polygon and sst prep vignettes while redoing methodology.
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/81e961d9f37b51867dca7c4692d68aae1349e83b/docs/sst-prep.html" target="_blank">81e961d</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-09
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/7ff9b8b7f78e47e9d651799280c229fe6c5eccde/analysis/sst-prep.Rmd" target="_blank">7ff9b8b</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-06-17
</td>
<td style="text-align:left;">
More work on the talk
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/c23c50b1c93aba7ecdb843fad79a20ed847bfcf3/docs/sst-prep.html" target="_blank">c23c50b</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-06-10
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/028d3cc02abc1761fd51e624f1bec0ef6ed68dac/docs/sst-prep.html" target="_blank">028d3cc</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-06-10
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/c61a15f695d6d807427b5642f6e657830a527970/docs/sst-prep.html" target="_blank">c61a15f</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-06-06
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/6dd6da87ca5aa18617a30851b7f9cffe25ed7b10/docs/sst-prep.html" target="_blank">6dd6da8</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-06-06
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/25e7e9aa629a27698a15278713c14437a7717fed/analysis/sst-prep.Rmd" target="_blank">25e7e9a</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-06-05
</td>
<td style="text-align:left;">
SOM pipeline nearly finished
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/94ce8f67d95d2a30c7b904784e619457ee4907a7/analysis/sst-prep.Rmd" target="_blank">94ce8f6</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-06-04
</td>
<td style="text-align:left;">
Functions for creating data packets are up and running
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/65301edfa1c7e85df9bf0df7afc2bda432aef6b0/analysis/sst-prep.Rmd" target="_blank">65301ed</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-30
</td>
<td style="text-align:left;">
Push before getting rid of some testing structure
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/2c3f68c3bc971b684bc9f3dc03d707457de74f18/analysis/sst-prep.Rmd" target="_blank">2c3f68c</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-28
</td>
<td style="text-align:left;">
Working on the variable prep vignette
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/5cb8e8f594d0cc85039ef11473f926e876eecf2a/docs/sst-prep.html" target="_blank">5cb8e8f</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-28
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/c09b4f7548427da023cfaf19ba517cb49e9456df/docs/sst-prep.html" target="_blank">c09b4f7</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-24
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/5dc8bd9ce2b868ebaefcc3ff83f0289672d22430/analysis/sst-prep.Rmd" target="_blank">5dc8bd9</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-24
</td>
<td style="text-align:left;">
Finished initial creation of SST prep vignette.
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/e008b23e5766e16801244af3dc74a819d1658d73/analysis/sst-prep.Rmd" target="_blank">e008b23</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-24
</td>
<td style="text-align:left;">
Push before changing
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/5b6f2482dffead06ced0e7abdba38beb5df8f346/analysis/sst-prep.Rmd" target="_blank">5b6f248</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-23
</td>
<td style="text-align:left;">
More SST clomp work
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/5c2b40676c3e78154527e962a058b0e99745ed9c/analysis/sst-prep.Rmd" target="_blank">5c2b406</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-23
</td>
<td style="text-align:left;">
Commit before changes
</td>
</tr>
<tr>
<td style="text-align:left;">
html
</td>
<td style="text-align:left;">
<a href="https://cdn.rawgit.com/robwschlegel/MHWNWA/d544295f68d00b7b5691632221db5c0ad2e251e4/docs/sst-prep.html" target="_blank">d544295</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-23
</td>
<td style="text-align:left;">
Build site.
</td>
</tr>
<tr>
<td style="text-align:left;">
Rmd
</td>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/9cb3efa2e7631b2e3c86593c3af6e832d8c6ee7d/analysis/sst-prep.Rmd" target="_blank">9cb3efa</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-23
</td>
<td style="text-align:left;">
Updating work done on the polygon prep vignette.
</td>
</tr>
</tbody>
</table>
</ul>
</details>
<hr />
<div id="introduction" class="section level2">
<h2>Introduction</h2>
<p>Building on the work performed in the <a href="https://robwschlegel.github.io/MHWNWA/polygon-prep.html">Polygon preparation</a> vignette, we will now create grouped SST time series for the regions in our study area. We will do this by finding which NOAA OISST pixels fall within each of the region polygons. Also note that throughout this vignette (and this entire project) we will use the climatology period of 1993 – 2018 as this is the shortest time limiting us by the data products used for the various abiotic variables needed for the SOM.</p>
<pre class="r"><code># Packages used in this vignette
library(jsonlite, lib.loc = &quot;../R-packages/&quot;)
library(tidyverse) # Base suite of functions
library(heatwaveR, lib.loc = &quot;../R-packages/&quot;) # For detecting MHWs
# cat(paste0(&quot;heatwaveR version = &quot;, packageDescription(&quot;heatwaveR&quot;)$Version))
library(FNN) # For fastest nearest neighbour searches
# library(ncdf4) # For opening and working with NetCDF files
library(tidync, lib.loc = &quot;../R-packages/&quot;) # For a more tidy approach to managing NetCDF data
library(SDMTools) # For finding points within polygons
library(lubridate) # For convenient date manipulation

# Set number of cores
doMC::registerDoMC(cores = 50)

# Disable scientific notation for numeric values
  # I just find it annoying
options(scipen = 999)

# Corners of the study area
NWA_corners &lt;- readRDS(&quot;data/NWA_corners.Rda&quot;)

# Individual regions
NWA_coords &lt;- readRDS(&quot;data/NWA_coords_cabot.Rda&quot;)

# The base map
map_base &lt;- ggplot2::fortify(maps::map(fill = TRUE, col = &quot;grey80&quot;, plot = FALSE)) %&gt;%
  dplyr::rename(lon = long) %&gt;%
  mutate(group = ifelse(lon &gt; 180, group+9999, group),
         lon = ifelse(lon &gt; 180, lon-360, lon)) %&gt;% 
  select(-region, -subregion)</code></pre>
</div>
<div id="pixel-prep" class="section level2">
<h2>Pixel prep</h2>
<p>Up first we take the lon/lat grid from the 1/4 degree daily NOAA OISST product and find which points fall within each region. We will save this information to allow us to then easily pull out the desired pixels from the cube of OISST data.</p>
<pre class="r"><code># Load NAPA bathymetry
# NAPA_bathy &lt;- readRDS(&quot;data/NAPA_bathy.Rda&quot;)# %&gt;% 
  # mutate(index = paste0(lon, lat))
OISST_grid &lt;- data.frame(expand.grid(c(seq(0.125, 179.875, by = 0.25), seq(-179.875, -0.125, by = 0.25)),
                                        seq(-89.875, 89.875, by = 0.25)))
colnames(OISST_grid) &lt;- c(&quot;lon&quot;, &quot;lat&quot;)
# saveRDS(OISST_grid, &quot;data/OISST_grid.Rda&quot;)

# Trim down OISST grid for faster processing
OISST_grid_region &lt;- OISST_grid %&gt;% 
  filter(lon &gt;= min(NWA_coords$lon),
         lon &lt;= max(NWA_coords$lon),
         lat &gt;= min(NWA_coords$lat),
         lat &lt;= max(NWA_coords$lat))
# saveRDS(OISST_grid_region, &quot;data/OISST_grid_region.Rda&quot;)

# Function for finding and cleaning up points within a given region polygon
pnts_in_region &lt;- function(region_in){
  region_sub &lt;- NWA_coords %&gt;% 
    filter(region == region_in)
  coords_in &lt;- pnt.in.poly(pnts = OISST_grid_region[1:2], poly.pnts = region_sub[2:3]) %&gt;% 
    filter(pip == 1) %&gt;% 
    dplyr::select(-pip) %&gt;% 
    mutate(region = region_in)
  return(coords_in)
}

# Run the function
NWA_info &lt;- plyr::ldply(unique(NWA_coords$region), pnts_in_region)
# saveRDS(NWA_info, &quot;data/NWA_info.Rda&quot;)

# Visualise to ensure success
ggplot(NWA_coords, aes(x = lon, y = lat)) +
  geom_polygon(aes(fill = region), alpha = 0.2) +
  geom_point(data = NWA_info, aes(colour = region)) +
  geom_polygon(data = map_base, aes(group = group), show.legend = F) +
    coord_cartesian(xlim = NWA_corners[1:2],
                  ylim = NWA_corners[3:4]) +
  labs(x = NULL, y = NULL)</code></pre>
<p><img src="figure/sst-prep.Rmd/pixel-regions-1.png" width="768" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of pixel-regions-1.png:</em></summary>
<table style = "border-collapse:separate; border-spacing:5px;">
<thead>
<tr>
<th style="text-align:left;">
Version
</th>
<th style="text-align:left;">
Author
</th>
<th style="text-align:left;">
Date
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/aa82e6e565dc2e79a3152f77684953031971619b/docs/figure/sst-prep.Rmd/pixel-regions-1.png" target="_blank">aa82e6e</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-31
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/7792f2489ae2ec1a2b8ab79e3bd63e280c67f3e6/docs/figure/sst-prep.Rmd/pixel-regions-1.png" target="_blank">7792f24</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-24
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/7cc8ec3c2187c5f1b0efba9c358b1421156c6cb7/docs/figure/sst-prep.Rmd/pixel-regions-1.png" target="_blank">7cc8ec3</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-24
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/5cb8e8f594d0cc85039ef11473f926e876eecf2a/docs/figure/sst-prep.Rmd/pixel-regions-1.png" target="_blank">5cb8e8f</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-28
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/c09b4f7548427da023cfaf19ba517cb49e9456df/docs/figure/sst-prep.Rmd/pixel-regions-1.png" target="_blank">c09b4f7</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-24
</td>
</tr>
</tbody>
</table>
</details>
</div>
<div id="sst-prep" class="section level2">
<h2>SST prep</h2>
<p>With the OISST pixels successfully assigned to regions based on their thermal properties we now need to go about clumping these SST pixels into one mean time series per region.</p>
<pre class="r"><code># The OISST data location
OISST_files &lt;- dir(&quot;../../data/OISST&quot;, full.names = T)

# The files with data in the study area
OISST_files_sub &lt;- data.frame(files = OISST_files,
                              lon = c(seq(0.125, 179.875, by = 0.25), seq(-179.875, -0.125, by = 0.25))) %&gt;% 
  filter(lon &gt;= min(NWA_info$lon), lon &lt;= max(NWA_info$lon)) %&gt;% 
  mutate(files = as.character(files))

# Function for loading the individual OISST NetCDF files and subsetting SST accordingly
# file_name &lt;- OISST_files_sub$files[1]
load_OISST_sub &lt;- function(file_name, coords = NWA_info){
  res &lt;- tidync(file_name) %&gt;%
    hyper_filter(lat = dplyr::between(lat, min(coords$lat), max(coords$lat)),
                 time = dplyr::between(time, as.integer(as.Date(&quot;1993-01-01&quot;)),
                                       as.integer(as.Date(&quot;2018-12-31&quot;)))) %&gt;%
    hyper_tibble() %&gt;% 
    mutate(time = as.Date(time, origin = &quot;1970-01-01&quot;)) %&gt;% 
    dplyr::rename(temp = sst, t = time) %&gt;% 
    select(lon, lat, t, temp) %&gt;% 
    left_join(coords, by = c(&quot;lon&quot;, &quot;lat&quot;)) %&gt;% 
    filter(!is.na(region))
  # return(res)
}

# Clomp&#39;em 
system.time(
  OISST_region &lt;- plyr::ldply(OISST_files_sub$files,
                           .fun = load_OISST_sub,
                           .parallel = TRUE) %&gt;% 
    group_by(region, t) %&gt;% 
    summarise(temp = mean(temp, na.rm = T))
) # 18 seconds

# Save
# saveRDS(OISST_region, &quot;data/OISST_region.Rda&quot;)</code></pre>
</div>
<div id="mhw-detection" class="section level2">
<h2>MHW detection</h2>
<p>With our clumped SST time series ready the last step in this vignette is to detect the MHWs within each.</p>
<pre class="r"><code># Load the time series data
OISST_region &lt;- readRDS(&quot;data/OISST_region.Rda&quot;)

# Calculate base results
system.time(
OISST_region_MHW &lt;- OISST_region %&gt;%
  group_by(region) %&gt;%
  nest() %&gt;%
  mutate(clims = map(data, ts2clm,
                     climatologyPeriod = c(&quot;1993-01-01&quot;, &quot;2018-12-31&quot;)),
         events = map(clims, detect_event),
         cats = map(events, category, S = FALSE)) %&gt;%
  select(-data, -clims)
) # 2 seconds
# saveRDS(OISST_region_MHW, &quot;data/OISST_region_MHW.Rda&quot;)</code></pre>
<p>With the MHWs detected, let’s visualise the results to ensure everything worked as expected.</p>
<pre class="r"><code># Load MHW results
OISST_region_MHW &lt;- readRDS(&quot;data/OISST_region_MHW.Rda&quot;)

# Events
OISST_MHW_event &lt;- OISST_region_MHW %&gt;%
  select(-cats) %&gt;%
  unnest(events) %&gt;%
  filter(row_number() %% 2 == 0) %&gt;%
  unnest(events)

event_lolli_plot &lt;- ggplot(data = OISST_MHW_event , aes(x = date_peak, y = intensity_max)) + 
        geom_lolli(colour = &quot;salmon&quot;, colour_n = &quot;red&quot;, n = 3) + 
  labs(x = &quot;Peak Date&quot;, y = &quot;Max. Intensity (°C)&quot;) +
  # scale_y_continuous(expand = c(0, 0))+
  facet_wrap(~region)
# ggsave(plot = event_lolli_plot, filename = &quot;output/event_lolli_plot.pdf&quot;, height = 7, width = 13)

# Visualise
event_lolli_plot</code></pre>
<p><img src="figure/sst-prep.Rmd/MHW-vis-1.png" width="768" style="display: block; margin: auto;" /></p>
<details>
<summary><em>Expand here to see past versions of MHW-vis-1.png:</em></summary>
<table style = "border-collapse:separate; border-spacing:5px;">
<thead>
<tr>
<th style="text-align:left;">
Version
</th>
<th style="text-align:left;">
Author
</th>
<th style="text-align:left;">
Date
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/7cc8ec3c2187c5f1b0efba9c358b1421156c6cb7/docs/figure/sst-prep.Rmd/MHW-vis-1.png" target="_blank">7cc8ec3</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-24
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/81e961d9f37b51867dca7c4692d68aae1349e83b/docs/figure/sst-prep.Rmd/MHW-vis-1.png" target="_blank">81e961d</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-07-09
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/6dd6da87ca5aa18617a30851b7f9cffe25ed7b10/docs/figure/sst-prep.Rmd/MHW-vis-1.png" target="_blank">6dd6da8</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-06-06
</td>
</tr>
<tr>
<td style="text-align:left;">
<a href="https://github.com/robwschlegel/MHWNWA/blob/c09b4f7548427da023cfaf19ba517cb49e9456df/docs/figure/sst-prep.Rmd/MHW-vis-1.png" target="_blank">c09b4f7</a>
</td>
<td style="text-align:left;">
robwschlegel
</td>
<td style="text-align:left;">
2019-05-24
</td>
</tr>
</tbody>
</table>
</details>
<p>Everything appears to check out. Up next in the <a href="https://robwschlegel.github.io/MHWNWA/var-prep.html">Variable preparation</a> vignette we will go through the steps necessary to build the data that will be fed into our self-organising maps as seen in the <a href="https://robwschlegel.github.io/MHWNWA/som.html">Self-organising map (SOM) analysis</a> vignette.</p>
<!-- One last point however is that according to @Richaud2016 the different slopebreaks for the different regions occur at different depths, from 50 m to 400 m depending. They do however note that using a static definition of 200 m for the break does not produce significantly different results. Therefore, for the time being we will maintain the spatial breaks used above. -->
</div>
<div id="references" class="section level2">
<h2>References</h2>
<div id="refs">

</div>
</div>
<div id="session-information" class="section level2">
<h2>Session information</h2>
<pre class="r"><code>sessionInfo()</code></pre>
<pre><code>R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.18.so

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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] bindrcpp_0.2.2   lubridate_1.7.4  SDMTools_1.1-221 tidync_0.2.1    
 [5] FNN_1.1.2.1      heatwaveR_0.4.0  forcats_0.3.0    stringr_1.3.1   
 [9] dplyr_0.7.6      purrr_0.2.5      readr_1.1.1      tidyr_0.8.1     
[13] tibble_1.4.2     ggplot2_3.0.0    tidyverse_1.2.1  jsonlite_1.6    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18      lattice_0.20-35   assertthat_0.2.0 
 [4] rprojroot_1.3-2   digest_0.6.16     foreach_1.4.4    
 [7] R6_2.2.2          cellranger_1.1.0  plyr_1.8.4       
[10] backports_1.1.2   evaluate_0.11     httr_1.3.1       
[13] pillar_1.3.0      rlang_0.2.2       lazyeval_0.2.1   
[16] readxl_1.1.0      ncmeta_0.0.4      rstudioapi_0.7   
[19] data.table_1.12.2 whisker_0.3-2     R.utils_2.7.0    
[22] R.oo_1.22.0       rmarkdown_1.10    labeling_0.3     
[25] htmlwidgets_1.3   munsell_0.5.0     broom_0.5.0      
[28] compiler_3.6.1    modelr_0.1.2      pkgconfig_2.0.2  
[31] htmltools_0.3.6   tidyselect_0.2.4  workflowr_1.1.1  
[34] codetools_0.2-15  doMC_1.3.5        viridisLite_0.3.0
[37] crayon_1.3.4      withr_2.1.2       R.methodsS3_1.7.1
[40] grid_3.6.1        nlme_3.1-137      gtable_0.2.0     
[43] git2r_0.23.0      magrittr_1.5      scales_1.0.0     
[46] ncdf4_1.16.1      cli_1.0.0         stringi_1.2.4    
[49] xml2_1.2.0        iterators_1.0.10  tools_3.6.1      
[52] glue_1.3.0        RNetCDF_1.9-1     maps_3.3.0       
[55] hms_0.4.2         parallel_3.6.1    yaml_2.2.0       
[58] colorspace_1.3-2  rvest_0.3.2       plotly_4.9.0     
[61] knitr_1.20        bindr_0.1.1       haven_1.1.2      </code></pre>
</div>

<!-- Adjust MathJax settings so that all math formulae are shown using
TeX fonts only; see
http://docs.mathjax.org/en/latest/configuration.html.  This will make
the presentation more consistent at the cost of the webpage sometimes
taking slightly longer to load. Note that this only works because the
footer is added to webpages before the MathJax javascript. -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    "HTML-CSS": { availableFonts: ["TeX"] }
  });
</script>

<hr>
<p>
  This reproducible <a href="http://rmarkdown.rstudio.com">R Markdown</a>
  analysis was created with
  <a href="https://github.com/jdblischak/workflowr">workflowr</a> 1.1.1
</p>
<hr>


</div>
</div>

</div>

<script>

// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
  $('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
  bootstrapStylePandocTables();
});


</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>