<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Cullen Molitor</title>
<link>https://cullen-molitor.github.io/blog.html</link>
<atom:link href="https://cullen-molitor.github.io/blog.xml" rel="self" type="application/rss+xml"/>
<description>Data scientist working at the intersection of remote sensing, machine learning, climate, and human well-being.</description>
<generator>quarto-1.6.40</generator>
<lastBuildDate>Wed, 19 Aug 2026 07:00:00 GMT</lastBuildDate>
<item>
  <title>Climate change and childhood malaria in Africa</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2026-08-19-climate-change-childhood-malaria/</link>
  <description><![CDATA[ 





<p><a href="https://doi.org/10.1038/s41586-026-10840-w">The past and future impact of climate change on childhood malaria in Africa</a> is out in <em>Nature</em>. I’m a co-author with Colin Carlson, Tamma Carleton, Romaric Odoulami, and Christopher Trisos.</p>
<section id="the-question" class="level2">
<h2 class="anchored" data-anchor-id="the-question">The question</h2>
<p>Malaria was one of the first health effects people suspected climate change might cause, and the question has been debated for decades. Despite progress in climate attribution, many health effects of climate change still haven’t been measured. We used over a century of clinical data to test whether human-caused warming has actually changed the burden of childhood malaria across sub-Saharan Africa.</p>
</section>
<section id="what-we-found" class="level2">
<h2 class="anchored" data-anchor-id="what-we-found">What we found</h2>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://cullen-molitor.github.io/posts/2026-08-19-climate-change-childhood-malaria/malaria_climate_impacts.png" class="img-fluid figure-img" alt="Map of Africa colored by change in malaria prevalence attributable to climate change, with decreases in West Africa and increases in parts of East and southern Africa; scatter plots showing increases in cooler, higher-elevation areas and decreases in hotter, lowland areas; and line charts of projected prevalence change to 2100 for central, East, southern, and West Africa under three emissions scenarios."></p>
<figcaption>Estimated impact of climate change on childhood malaria prevalence: (a) by region across Africa, (b–c) by baseline temperature and elevation, and (d) projected through 2100 under three emissions scenarios. From Carlson et al.&nbsp;(2026), <em>Nature</em>.</figcaption>
</figure>
</div>
<ul>
<li><strong>Temperature and extreme precipitation</strong> have a robust effect on malaria prevalence. This matches earlier local studies and laboratory experiments.</li>
<li><strong>The past effect differs by region.</strong> Rising temperatures have probably increased malaria in East and southern Africa but averted a comparable number of cases in West Africa. Across the continent, the net effect is about <strong>1 excess case per 1,000 children</strong> (95% CI −4 to 6).</li>
<li><strong>The future could look different from what many expect.</strong> Over the coming century, climate change could slightly speed up malaria elimination in West and central Africa, where the burden is highest today. Across the continent, it could avert 1 (low emissions) to 20 (high emissions) cases per 1,000 children by 2100.</li>
<li><strong>Mitigation still matters a great deal locally.</strong> Holding warming under 2 °C instead of 3 °C could prevent an average of about <strong>5 excess cases per 1,000 children</strong> by 2100 in high-elevation East Africa (above 1 km) and in southern Africa.</li>
</ul>
</section>
<section id="why-it-matters" class="level2">
<h2 class="anchored" data-anchor-id="why-it-matters">Why it matters</h2>
<p>The results settle a long-running debate and give a template for measuring the true global health burden of climate change. The effects vary a lot from region to region, and a single continental number can hide large local risks.</p>
<p>The data behind the paper are openly available on <a href="https://doi.org/10.5281/zenodo.20399793">Zenodo</a>.</p>
<p><strong>Citation:</strong> Carlson, C.J., Carleton, T., Odoulami, R.C., Molitor, C., Trisos, C.H. (2026). The past and future impact of climate change on childhood malaria in Africa. <em>Nature</em>, 657(8131), 487–494. <a href="https://doi.org/10.1038/s41586-026-10840-w">doi:10.1038/s41586-026-10840-w</a></p>


</section>

 ]]></description>
  <category>Publication</category>
  <category>Climate</category>
  <category>Health</category>
  <category>Africa</category>
  <guid>https://cullen-molitor.github.io/posts/2026-08-19-climate-change-childhood-malaria/</guid>
  <pubDate>Wed, 19 Aug 2026 07:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2026-08-19-climate-change-childhood-malaria/malaria_climate_impacts.png" medium="image" type="image/png" height="115" width="144"/>
</item>
<item>
  <title>Mapping on a budget</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2026-04-04-mapping-on-a-budget/</link>
  <description><![CDATA[ 





<p><a href="https://doi.org/10.1609/aaai.v40i45.41162">Mapping on a Budget: Optimizing Spatial Data Collection for ML</a> was published in the <em>Proceedings of the AAAI Conference on Artificial Intelligence</em>. I worked on it with a great team, including collaborators in Togo; the full author list is in the citation below.</p>
<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>Satellite imagery covers the whole globe, but the labels used to train models on it usually don’t. They tend to be small, spatially clustered, and collected for some other purpose, such as administrative surveys or field plots. Most research responds with new model architectures built to cope with scarce data. That leaves a practical question unanswered: if you have money to collect more data, <strong>where should you collect it?</strong></p>
</section>
<section id="what-we-did" class="level2">
<h2 class="anchored" data-anchor-id="what-we-did">What we did</h2>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://cullen-molitor.github.io/posts/2026-04-04-mapping-on-a-budget/togo_sampling.png" class="img-fluid figure-img" alt="Three maps of Togo. Left: grey points showing an initial clustered survey sample. Middle: the same sample with purple points added by the optimization method. Right: a high-resolution map of cultivated land produced by a model trained on satellite imagery and the augmented labels."></p>
<figcaption>Our approach applied to Togo: an existing survey sample (left) is augmented with optimally placed new samples (purple), which train a satellite ML model to map cultivated land countrywide (right). From Betti et al.&nbsp;(2026), AAAI.</figcaption>
</figure>
</div>
<p>We wrote down the first formal version of this problem. It has two features that real fieldwork always has: collection costs that vary from place to place (some sites are harder to reach than others) and a fixed budget. We then developed new methods for choosing which locations to sample under those constraints.</p>
</section>
<section id="what-we-found" class="level2">
<h2 class="anchored" data-anchor-id="what-we-found">What we found</h2>
<p>We ran simulations across three continents and four prediction tasks. Optimizing where samples are collected produced substantial gains in model performance. Further experiments showed which settings benefit most from optimized sampling.</p>
</section>
<section id="why-it-matters" class="level2">
<h2 class="anchored" data-anchor-id="why-it-matters">Why it matters</h2>
<p>The methods are designed to carry over to any domain that uses satellite machine learning. We paid particular attention to one setting where our coauthors can use the results right away: adding to clustered agricultural surveys in <strong>Togo</strong> so they can support satellite-based monitoring. This links closely to my <a href="../2025-11-25-maize-yields-zambia/">maize yield work in Zambia</a>, where limited ground data is the main bottleneck.</p>
<p><strong>Citation:</strong> Betti, L., Sanni, F., Sogoyou, G.Z., Agbagla, T., Molitor, C., Carleton, T., Rolf, E. (2026). Mapping on a Budget: Optimizing Spatial Data Collection for ML. <em>Proceedings of the AAAI Conference on Artificial Intelligence</em>, 40(45), 38233–38241. <a href="https://doi.org/10.1609/aaai.v40i45.41162">doi:10.1609/aaai.v40i45.41162</a></p>


</section>

 ]]></description>
  <category>Publication</category>
  <category>Remote Sensing</category>
  <category>Machine Learning</category>
  <category>Sampling</category>
  <category>Africa</category>
  <guid>https://cullen-molitor.github.io/posts/2026-04-04-mapping-on-a-budget/</guid>
  <pubDate>Sat, 04 Apr 2026 07:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2026-04-04-mapping-on-a-budget/togo_sampling.png" medium="image" type="image/png" height="81" width="144"/>
</item>
<item>
  <title>Monitoring maize yields in Zambia from space</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2025-11-25-maize-yields-zambia/</link>
  <description><![CDATA[ 





<p>Our paper, <a href="https://doi.org/10.3390/rs17213641">Monitoring Maize Yield Variability over Space and Time with Unsupervised Satellite Imagery Features</a>, is now out in <em>Remote Sensing</em>. It started as our <a href="../2022-05-29-publicpresentation/">MEDS capstone project</a> and grew into a full paper with Juliet Cohen, Grace Lewin, Steven Cognac, Protensia Hadunka, Jonathan Proctor, and Tamma Carleton.</p>
<section id="the-question" class="level2">
<h2 class="anchored" data-anchor-id="the-question">The question</h2>
<p>Zambia is prone to severe droughts and crop failures, but ground data on yields is limited. During COVID-19, for example, district-level maize surveys stopped entirely. Methods like <a href="https://center-for-effective-global-action-cega.github.io/MOSAIKS-Training-Manual/en/index.html">MOSAIKS</a> make it cheap to turn satellite imagery into features for prediction. Until now, though, nobody had tested whether these simple pipelines can track change <strong>over time</strong> in a low-data, developing-country setting. Most evaluations only look at variation across space.</p>
</section>
<section id="what-we-did" class="level2">
<h2 class="anchored" data-anchor-id="what-we-did">What we did</h2>
<p>We computed random convolutional features from Landsat and Sentinel-2 imagery and paired them with district-level yield data. We then fit plain linear ridge regression models. There is no deep learning and no task-specific architecture.</p>
</section>
<section id="what-we-found" class="level2">
<h2 class="anchored" data-anchor-id="what-we-found">What we found</h2>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://cullen-molitor.github.io/posts/2025-11-25-maize-yields-zambia/yield_predictions.png" class="img-fluid figure-img" alt="Scatter plot of model-estimated versus observed log maize yields for Zambian districts from 2016 to 2021, colored by year, with marginal histograms. Points cluster along the 1:1 line; R squared is 0.83."></p>
<figcaption>Out-of-sample model estimates vs.&nbsp;observed district maize yields in Zambia, 2016–2021 (R² = 0.83). From Molitor et al.&nbsp;(2025), <em>Remote Sensing</em>.</figcaption>
</figure>
</div>
<ul>
<li>The model explains <strong>83%</strong> of out-of-sample maize yield variation from 2016 to 2021. That is slightly better than a model built on NDVI features, the standard approach practitioners use to monitor crop health.</li>
<li>The real difference shows up over <strong>time</strong>. When predicting year-to-year variation alone, our model keeps an R² of <strong>0.74</strong>, while the NDVI model drops to <strong>0.39</strong>.</li>
</ul>
</section>
<section id="why-it-matters" class="level2">
<h2 class="anchored" data-anchor-id="why-it-matters">Why it matters</h2>
<p>Monitoring droughts and food security depends on catching change from year to year. Our results show that task-agnostic featurization can capture that change even where ground truth is sparse and compute is limited. Imagery-based monitoring can work in exactly the places where expensive approaches are out of reach.</p>
<p><strong>Citation:</strong> Molitor, C., Cohen, J., Lewin, G., Cognac, S., Hadunka, P., Proctor, J., Carleton, T. (2025). Monitoring Maize Yield Variability over Space and Time with Unsupervised Satellite Imagery Features. <em>Remote Sensing</em>, 17(21), 3641. <a href="https://doi.org/10.3390/rs17213641">doi:10.3390/rs17213641</a></p>


</section>

 ]]></description>
  <category>Publication</category>
  <category>Remote Sensing</category>
  <category>Machine Learning</category>
  <category>Agriculture</category>
  <category>Africa</category>
  <category>MOSAIKS</category>
  <guid>https://cullen-molitor.github.io/posts/2025-11-25-maize-yields-zambia/</guid>
  <pubDate>Tue, 25 Nov 2025 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2025-11-25-maize-yields-zambia/yield_predictions.png" medium="image" type="image/png" height="143" width="144"/>
</item>
<item>
  <title>Wrangling tidal flat data with R</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2022-09-10-tidal-flats/</link>
  <description><![CDATA[ 





<section id="tidal-flat-data" class="level1">
<h1>Tidal flat Data</h1>
<p>While working with the Ocean Health Index (OHI) during my summer fellowship, I was tasked with exploring and summarizing data that we wanted to integrate into the program to update the <a href="https://oceanhealthindex.org/goals/biodiversity/habitats/">habitat</a> subgoal of <a href="https://oceanhealthindex.org/goals/biodiversity/">biodiversity</a>. This data was for tidal flat ecosystems to complement the existing habitat types. Tidal flat habitat is defined as sand, rock, or mud flats that undergo regular tidal inundation. This vital habitat is distributed globally, but up until this recently there was very limited data on the extent of these ecosystems, especially at the global scale.</p>
<p>The data come from a paper, <a href="https://www.nature.com/articles/s41586-018-0805-8">The global distribution and trajectory of tidal flats</a> (Murray et al.&nbsp;2019), which used satellite imagery and machine learning methods to classify tidal flat habitat from over 700,000 satellite images between 1984 and 2016.</p>
<p>This new dataset has given OHI the opportunity to further improve their methods and in turn, the ability to understand the health of the world’s oceans. For example, the paper found that:</p>
<blockquote class="blockquote">
<p>“Extensive degradation from coastal development, reduced sediment delivery from major rivers, sinking of riverine deltas, increased coastal erosion, and sea-level rise signal a continuing negative trajectory for tidal flat ecosystems around the world.”</p>
</blockquote>
<p><img src="https://cullen-molitor.github.io/posts/2022-09-10-tidal-flats/jitze_couperus_cargill_flats_flickr.jpg" class="img-fluid"></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; <em>The interface of coastal development with tidal flat habitat off Redwood City, California (Photo: <a href="https://www.flickr.com/photos/jitze1942/5244615529/in/photolist-8Zs2tF-2mcBSEz-2mbaQWz-2eGrCBb-2mcR9AJ-riuRXd-2m9pjVX-dfpp5f-2ni8fyW-2maeZuS-237cW2k-2mbDn5Z-2mbfbXK-ZRJNMp-2mbvHuj-2mbaigy-2m9okJm-2m9KhCq-2ma4UN8-2maC7zZ-2m9H5Uu-2mb6sxZ-5A7XK2-SCXCLN-mEucZb-2mcJVgv-SCXCuA-5Q9qm-5qWU36-SCXCHG-r4fDrf-2maKF6K-2mbKNm7-2maWHYx-SCXC9f-of2jqp-PagPZo-24aBQVg-aMC5Jz-oJMgpT-9gsEyT-VRTZsv-P5Aez8-xsSKEo-3Yz3Si-YT1xo3-24Z2DH7-xbXZ3Q-qDc4vo-2kSmqmB">Jitze Couperus</a>)</em>.</p>
<p>Tidal flats will affect the OHI global scores by adding additional layers to the habitat subgoal and carbon storage goal. The three new data layers created are tidal flat extent (measured in \(km^2\)), tidal flat trend (proportional change), and tidal flat condition (current status compared to historic status).</p>
<p>This post will give a brief explanation of tidal flat habitat, explore the new dataset, and demonstrate how to programmatically summarize the data in the R software environment. The goal of data summarization is to distill the large raster dataset into simple tabular data which can be integrated into the OHI annual analysis as new data layers for 2022 and beyond.</p>
<section id="data-exploration" class="level2">
<h2 class="anchored" data-anchor-id="data-exploration">Data exploration</h2>
<p>The published data product includes 11 sets (1 for each time step) of global tidal flat extent maps at 30 meter Ground Sample Distance (GSD; AKA resolution). This means that each pixel in each raster represents 30 m<sup>2</sup>, and contains either 0 for “not tidal flat”, or 1 for “tidal flat.” This is a massive amount of data, but thankfully, each of the 11 time steps were broken into 108 files with discrete spatial extents, making individual files easy to work with.</p>
<p>So where to begin? Well first, we needed to access the data. The authors provide several options for <a href="https://www.intertidal.app/download">data access</a> including through <a href="https://developers.google.com/earth-engine/datasets/tags/tidal-flats">Google Earth Engine</a>, <a href="https://data.unep-wcmc.org/datasets/47">UNEP-WCMC Ocean Data Viewer</a>, and finally through <a href="https://www.intertidal.app/download/direct-download">direct download</a>. We chose the direct download option and wrote a simple shell script that is executed in an R Markdown code chunk.</p>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">### Make the new directory and move into it</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mkdir</span> /<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>path<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>to<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>directory<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>of<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>choice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/tidal_flats <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">&amp;&amp;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$_</span></span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">### Declare an array of strings, one for each time step</span></span>
<span id="cb1-5"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">declare</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-a</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">StringArray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">(</span></span>
<span id="cb1-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1984-1986"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1987-1989"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1990-1992"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1993-1995"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1996-1998"</span> </span>
<span id="cb1-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1999-2001"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2002-2004"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2005-2007"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2008-2010"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2011-2013"</span> </span>
<span id="cb1-8">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2014-2016"</span></span>
<span id="cb1-9"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-10"></span>
<span id="cb1-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">### Iterate through the array using for loop</span></span>
<span id="cb1-12"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> val <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">${StringArray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[@]</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">}</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">;</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">do</span></span>
<span id="cb1-13">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$val</span></span>
<span id="cb1-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">wget</span> https://storage.googleapis.com/uq-intertidal/v1_1/global_intertidal/<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$val</span>.zip</span>
<span id="cb1-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unzip</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$val</span>.zip <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-d</span> ./<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$val</span></span>
<span id="cb1-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rm</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$val</span>.zip</span>
<span id="cb1-17"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">done</span></span></code></pre></div>
<p>With the data in hand, we first do some basic exploration and ensure it is what we expect, and that it makes sense. The <code>terra</code> package has some handy functions for doing this. After reading the first file of the first time step with <code>terra::rast()</code>, I used <code>terra::freq()</code> to check how many unique values there were, expecting only 0 or 1 based on the metadata.</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">image <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidal_flats"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1984-1986"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-100_-20.tif"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-2">  terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rast</span>() </span>
<span id="cb2-3">image <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print the raster metadata</span></span></code></pre></div>
<p>Output (raster metadata)</p>
<pre class="console"><code>class       : SpatRaster 
dimensions  : 74213, 74213, 1  (nrow, ncol, nlyr)
resolution  : 0.0002694946, 0.0002694946  (x, y)
extent      : -160, -140, -20, 0  (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326) 
source      : -160_0.tif 
name        : classification</code></pre>

<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">freq</span>(image)</span></code></pre></div>
<p>Output (frequency table)</p>
<pre class="console"><code>     layer value      count
[1,]     1     0 5507569369</code></pre>

<p>Dang! All 0’s. This is most likely due to the spatial tile not intersecting any intertidal region. There will be many tiles over nothing but ocean or land. While not a satisfying result for our first data exploration, it is important to anticipate what you are looking for and what you might find. Lets take a look at this files spatial extent in relation to the global coastline to make sure that our results match what we now expect of it.</p>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rnaturalearth)</span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rnaturalearthdata)</span>
<span id="cb6-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyterra)</span>
<span id="cb6-4"></span>
<span id="cb6-5">world <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ne_countries</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"medium"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">returnclass =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sf"</span>)</span>
<span id="cb6-6"></span>
<span id="cb6-7">extent <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ext</span>(image)</span>
<span id="cb6-8"></span>
<span id="cb6-9">extent_polygon <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.polygons</span>(extent)</span>
<span id="cb6-10"></span>
<span id="cb6-11">terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">crs</span>(extent_polygon) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"epsg:4326"</span></span>
<span id="cb6-12"></span>
<span id="cb6-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> world) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-15">  tidyterra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_spatvector</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> extent_polygon, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Red"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2022-09-10-tidal-flats/plot_1.png" class="img-fluid"></p>
<p>Looks like our intuition matches the result! This plot shows the extent only covers open ocean.</p>
<p>Now lets examine another raster to see what kind of unique value we get.</p>
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">image <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidal_flats"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1984-1986"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0_-20.tif"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-2">  terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rast</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-3">  terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">freq</span>()</span></code></pre></div>
<p>Output (frequency table)</p>
<pre class="console"><code>     layer value      count
[1,]     1     0 5506916280
[2,]     1     1     653089</code></pre>

<p>That is better! Now lets see where this file lands on the globe.</p>
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">extent_polygon <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ext</span>(image) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-2">  terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.polygons</span>()</span>
<span id="cb9-3"></span>
<span id="cb9-4">terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">crs</span>(extent_polygon) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"epsg:4326"</span></span>
<span id="cb9-5"></span>
<span id="cb9-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> world) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-8">  tidyterra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_spatvector</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> extent_polygon, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Red"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2022-09-10-tidal-flats/plot_2.png" class="img-fluid"></p>
<p>Now we can see that this tile falls along a section of coastline, and has both 0 and 1 values. Things look good so far.</p>
</section>
<section id="transforming-the-data" class="level2">
<h2 class="anchored" data-anchor-id="transforming-the-data">Transforming the data</h2>
<p>Now that we know our files contain what we expect, and have seen a few outputs, it is time to design a workflow that will allow us to extract the information we want from the files. For OHI, our goal is to summarize the extent of habitat in each region, for each time step. Our ideal final product will have an extent measured in \(km^2\), the region ID, the year, and the habitat type.</p>
<p>Even though each time step is broken into 108 files, the resolution still makes this data hard to work with. The <code>terra</code> package offers a solution to reduce resolution, often referred to as down-sampling. The function <code>terra::aggregate()</code> allows a user to specify how many pixels should be connected into one and what function to use on the pixels being aggregated. In our case we want to sum the pixels to retain all of the habitat information. We want to choose a resolution that will allow us to continue using the rasters for analysis without bogging down our computer. We chose to down-sample to ~1 \(km^2\) resolution by choosing 30 pixels as our aggregation factor. Our function then looks like:</p>
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">down_sampled_image <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aggregate</span>(</span>
<span id="cb10-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> image, </span>
<span id="cb10-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fact =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, </span>
<span id="cb10-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> sum, </span>
<span id="cb10-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> T</span>
<span id="cb10-6">)</span></code></pre></div>
<p>The true resolution in \(km^2\) can be found with a bit of simple math, 30 meters by 30 pixels is 900 meters to a side, and squaring that gives our new pixel dimensions of \(900 x 900\) meters. We then divide these new dimensions by by a pixel with an area of 1 \(km^2\): \[\frac{900 * 900}{1,000 * 1,000} = .81 \text{ }km^2\] Using 33 pixels would have brought us closer to 1 \(km^2\), but this brings the image to a reasonable size, and in general we would like to keep the resolution as high as possible.</p>
<p>Our next goal is to convert pixel counts into area. If the native raster cells are 30 x 30 meters, then a raster cell with a value of 1 would be equivalent to 0.0009 \(km^2\) habitat area. This can be found by multiplying the pixel dimensions together and dividing by a pixel with an area of 1 \(km^2\): \[\frac{30 * 30}{1,000 * 1,000} = 0.0009 \text{ }km^2\] The simplest way to convert to area in this scenario is to simply multiply our down-sampled raster by 0.0009.</p>
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">down_sampled_image <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> down_sampled_image <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0009</span></span></code></pre></div>
<p>This works because each pixel started out as a 0 or a 1, so the aggregated raster has values in multiples of 1. We can check this by again using <code>terra::freq()</code> to see that our new raster has values in multiples of 0.0009. We use the <code>digits</code> argument to make sure values are not rounded to 0 in the output table.</p>
<div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">freq</span>(</span>
<span id="cb12-2">  down_sampled_image, </span>
<span id="cb12-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span></span>
<span id="cb12-4">) </span></code></pre></div>
<p>Output (frequency table)</p>
<pre class="console"><code>     layer  value   count
[1,]     1 0.0000 6117245
[2,]     1 0.0009      61
[3,]     1 0.0018      59
(cropped for brevity)</code></pre>

<p>Results look good! Just as expected, we now have raster cells at ~1 \(km^2\) resolution, with cell values representing the area in \(km^2\) of tidal flat habitat. In this case there are 61 cells which contained a single cell of tidal flat, prior to aggregation, 59 which had two, and so on.</p>
<p>Now we need to extract the values that fall with each OHI region polygon. To do this we use another package new to OHI, <code>exactextractr</code>. As we saw in the previous post on soft bottom habitat analysis, this package allows us to extract values from polygons and return an estimate if a polygon goes through a raster cell. This is handy to implement after aggregation as it allows us to maintain a higher level of precision. The <code>raster::extract()</code> function will only include a cell if the center of the cell falls inside a polygon. Our shapefile has separate polygons for all regions’ EEZ’s and for their land area. We want to use both because our data primarily goes through the intersection of these two polygons.</p>
<p>The first thing we need to do is <a href="https://oceanhealthindex.org/global-scores/data-download/">download</a> the OHI region <a href="https://mazu.nceas.ucsb.edu/data/">polygon file</a>.</p>
<div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mkdir</span> /<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>path<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>to<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>directory<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>of<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>choice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/regions <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">&amp;&amp;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">cd</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$_</span></span>
<span id="cb14-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">wget</span> https://ohi.nceas.ucsb.edu/data/data/regions.zip</span>
<span id="cb14-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unzip</span> regions.zip </span>
<span id="cb14-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rm</span> regions.zip</span></code></pre></div>
<p>Next we read in the data and filter for what we want. We also create a dummy dataframe to use when reconstructing the extracted values into a usable data format.</p>
<div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">regions_eez_and_land <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'regions'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'regions.shp'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-2">  sf<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_sf</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb15-3">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(rgn_type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"eez"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'land'</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-4">  sf<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_transform</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4326</span>)</span>
<span id="cb15-5">  </span>
<span id="cb15-6">dummy_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> regions_eez_and_land <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-7">  tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-8">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(rgn_id, rgn_name) </span></code></pre></div>
<p>We use the sum of values in our extraction because our downsampled image has also been converted to area in each pixel. The sum will give us the total area inside each polygon. Our function to extract values then looks like:</p>
<div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1">exactextractr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exact_extract</span>(</span>
<span id="cb16-2"> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> down_sampled_image, </span>
<span id="cb16-3"> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> regions_eez_and_land, </span>
<span id="cb16-4"> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sum'</span></span>
<span id="cb16-5">)</span></code></pre></div>
</section>
<section id="putting-it-all-together" class="level2">
<h2 class="anchored" data-anchor-id="putting-it-all-together">Putting it all together</h2>
<p>Now that we have a workflow that has been tested on a single raster, all we have to do is design a loop that goes through each raster file and outputs a simple <code>.csv</code> file.</p>
<div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### Create an empty intermediate output folder</span></span>
<span id="cb17-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.create</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"int"</span>) </span>
<span id="cb17-3"></span>
<span id="cb17-4">tictoc<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># time this code </span></span>
<span id="cb17-5"></span>
<span id="cb17-6">folders <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidal_flats"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list.files</span>()</span>
<span id="cb17-8"></span>
<span id="cb17-9">j <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb17-10"></span>
<span id="cb17-11"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### To run this code in parallel, </span></span>
<span id="cb17-12"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### Uncomment next two lines and comment out one after</span></span>
<span id="cb17-13"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### You will loose the pretty output messages :(</span></span>
<span id="cb17-14"></span>
<span id="cb17-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># doParallel::registerDoParallel(11)</span></span>
<span id="cb17-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># foreach::foreach (dir = folders) %dopar% {</span></span>
<span id="cb17-17"></span>
<span id="cb17-18"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (dir <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> folders) { </span>
<span id="cb17-19">  </span>
<span id="cb17-20">  files <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidal_flats"</span>, dir) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list.files</span>()</span>
<span id="cb17-22">  </span>
<span id="cb17-23">  year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_split</span>(dir, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span>
<span id="cb17-24">  </span>
<span id="cb17-25">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (file <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> files){</span>
<span id="cb17-26">    </span>
<span id="cb17-27">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(j, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(files), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb17-28">    </span>
<span id="cb17-29">    j <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> j <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb17-30">    </span>
<span id="cb17-31">    fn <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> file <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-32">      stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace</span>(</span>
<span id="cb17-33">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern     =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".tif"</span>,</span>
<span id="cb17-34">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replacement =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>, year, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".csv"</span>))</span>
<span id="cb17-35">    </span>
<span id="cb17-36">    <span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### make a new int folder to hold the output</span></span>
<span id="cb17-37">    </span>
<span id="cb17-38">    file_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"int"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidal_flat"</span>, fn)</span>
<span id="cb17-39">    </span>
<span id="cb17-40">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.exists</span>(file_name)){</span>
<span id="cb17-41">      </span>
<span id="cb17-42">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(fn, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" is being created!</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb17-43">      </span>
<span id="cb17-44">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"    down sampling...</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb17-45">      </span>
<span id="cb17-46">      image <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidal_flats"</span>, dir, file) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-47">        terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rast</span>() </span>
<span id="cb17-48">       </span>
<span id="cb17-49">      down_sampled_image <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aggregate</span>(</span>
<span id="cb17-50">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> image, </span>
<span id="cb17-51">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fact =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, </span>
<span id="cb17-52">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> sum,</span>
<span id="cb17-53">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> T</span>
<span id="cb17-54">      )</span>
<span id="cb17-55"></span>
<span id="cb17-56">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"    converting to area (km2)...</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb17-57">      </span>
<span id="cb17-58">      down_sampled_image <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> down_sampled_image <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0009</span></span>
<span id="cb17-59">      </span>
<span id="cb17-60">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"    extracting...</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb17-61">      </span>
<span id="cb17-62">      extracted_values <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> exactextractr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exact_extract</span>(</span>
<span id="cb17-63">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> down_sampled_image, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> regions_eez_and_land, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sum'</span></span>
<span id="cb17-64">      )</span>
<span id="cb17-65">      </span>
<span id="cb17-66">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"km2"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> extracted_values, dummy_df) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-67">        dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(rgn_id, rgn_name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-68">        dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">km2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(km2)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-69">        dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year =</span> year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">habitat =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidal flat"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-70">        readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_csv</span>(file_name)</span>
<span id="cb17-71">      </span>
<span id="cb17-72">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(fn, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" already exists!</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>))}</span>
<span id="cb17-73">  }</span>
<span id="cb17-74">}</span>
<span id="cb17-75">tictoc<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div>
<p>There is a lot to take in there, but if you follow it line by line it isn’t too bad.</p>
<blockquote class="blockquote">
<p><strong>To recap:</strong><br>
List raw data folders<br>
Outer loop iterates through folders<br>
List files in the folder<br>
Find the year by splitting the folder name<br>
Inner loop iterates through files in folder<br>
Check if desired output already esists, if not, create it!<br>
Create the SpatRaster<br>
Down-sample resolution<br>
Convert cell values to area<br>
Extract area inside region polygons<br>
Assign values to dummy dataframe Summarize to the region level<br>
Write the results!</p>
</blockquote>
</section>
<section id="consolidate-results" class="level2">
<h2 class="anchored" data-anchor-id="consolidate-results">Consolidate results</h2>
<p>The end result of the above workflow produces a single <code>.csv</code> file for every raster in every time step with the extent of tidal wetland in every OHI region. We also know that each raster only covers a 1/108 chunk of the globe, which means there are a lot of 0 values in each of the files. These can be further condensed and summarized with a simple for loop.</p>
<div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### Create an empty output folder</span></span>
<span id="cb18-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.create</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"output"</span>)</span>
<span id="cb18-3"></span>
<span id="cb18-4"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### list csv files with extracted tidal flat values</span></span>
<span id="cb18-5">files <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> here<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"int"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidal_flat"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list.files</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">full.names =</span> T)</span>
<span id="cb18-7"></span>
<span id="cb18-8"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### make an empty tibble to fill through iteration</span></span>
<span id="cb18-9">output <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>()</span>
<span id="cb18-10"></span>
<span id="cb18-11"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### loop through files</span></span>
<span id="cb18-12"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (file <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> files) {</span>
<span id="cb18-13">  </span>
<span id="cb18-14">  <span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### read in files, suppress messages with col_types argument</span></span>
<span id="cb18-15">  tmp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(file, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_types =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cols</span>()) </span>
<span id="cb18-16">  </span>
<span id="cb18-17">  <span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### bind temporary output to complete output</span></span>
<span id="cb18-18">  output <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(output, tmp) </span>
<span id="cb18-19">}</span>
<span id="cb18-20"></span>
<span id="cb18-21"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">### summarize results and write final output</span></span>
<span id="cb18-22">final <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> output <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-23">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(rgn_id, year, habitat) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-24">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">km2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(km2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> T)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-25">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(rgn_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">213</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-26">  readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_csv</span>(here<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'output'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidal_flat_extent.csv"</span>))</span></code></pre></div>
<p>Now we have a single <code>.csv</code> file with every OHI region listed a single time for each time step, and a corresponding tidal flat extent for that region. This data is then used as a new layer when calculating the OHI scores.</p>
<p><strong><a href="https://github.com/OHI-Science/ohiprep_v2022/tree/gh-pages/globalprep/hab_tidal_flat/v2022">Check out the full data prep used in the 2022 OHI assessment here.</a></strong></p>
</section>
</section>
<section id="references" class="level1">
<h1>References</h1>
<ul>
<li><p>Daniel Baston (2022). <em>exactextractr: Fast Extraction from Raster Datasets using Polygons</em>. R package version 0.8.2, <a href="https://CRAN.R-project.org/package=exactextractr" class="uri">https://CRAN.R-project.org/package=exactextractr</a>.</p></li>
<li><p>Hijmans R (2022). <em>terra: Spatial Data Analysis</em>. R package version 1.6-3, <a href="https://CRAN.R-project.org/package=terra" class="uri">https://CRAN.R-project.org/package=terra</a>.</p></li>
<li><p>Murray, N.J., Phinn, S.R., DeWitt, M. et al.&nbsp;The global distribution and trajectory of tidal flats. Nature 565, 222–225 (2019). <a href="https://doi.org/10.1038/s41586-018-0805-8" class="uri">https://doi.org/10.1038/s41586-018-0805-8</a></p></li>
<li><p>R Core Team (2022). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL <a href="https://www.R-project.org/" class="uri">https://www.R-project.org/</a>.</p></li>
<li><p>Wickham H, Averick M, Bryan J, Chang W, McGowan LD, François R, Grolemund G, Hayes A, Henry L, Hester J, Kuhn M, Pedersen TL, Miller E, Bache SM, Müller K, Ooms J, Robinson D, Seidel DP, Spinu V, Takahashi K, Vaughan D, Wilke C, Woo K, Yutani H (2019). “Welcome to the tidyverse.” <em>Journal of Open Source Software</em>, <em>4</em>(43), 1686. <a href="https://doi.org/10.21105/joss.01686" class="uri">https://doi.org/10.21105/joss.01686</a>.</p></li>
</ul>
<div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>

 ]]></description>
  <category>R</category>
  <category>Remote Sensing</category>
  <category>Spatial Analysis</category>
  <category>Ocean Data</category>
  <guid>https://cullen-molitor.github.io/posts/2022-09-10-tidal-flats/</guid>
  <pubDate>Sat, 10 Sep 2022 07:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2022-09-10-tidal-flats/terra_hex.png" medium="image" type="image/png" height="162" width="144"/>
</item>
<item>
  <title>2022 MEDS Public Presentations</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <dc:creator>Juliet Cohen</dc:creator>
  <dc:creator>Steven Cognac</dc:creator>
  <dc:creator>Grace Lewin</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2022-05-29-publicpresentation/</link>
  <description><![CDATA[ 





<section id="an-open-source-pipeline-for-remote-sensing-of-crop-yields-a-zambia-case-study" class="level3">
<h3 class="anchored" data-anchor-id="an-open-source-pipeline-for-remote-sensing-of-crop-yields-a-zambia-case-study">An open-source pipeline for remote sensing of crop yields: a Zambia case study</h3>
<p>Our group capstone project has come to a close with our public presentation at Bren Hall, UCSB on May 26, 2022. More information on presenters and the schedule can be found <a href="https://bren.ucsb.edu/events/2022-meds-capstone-project-presentations">here</a>.</p>
<section id="presntation-youtube-link" class="level4">
<h4 class="anchored" data-anchor-id="presntation-youtube-link"><a href="https://youtu.be/iXdETegKbSs?t=4372"><strong>Presntation YouTube Link</strong></a></h4>
</section>
<section id="abstract" class="level4">
<h4 class="anchored" data-anchor-id="abstract">Abstract</h4>
<p>High-quality, long-term environmental data sets are the foundation of long-range risk and climate modeling. However, producing such datasets is costly, logistically challenging, and resource-intensive. Due to limited agricultural data across sub-Saharan Africa, policy-makers, farmers, and researchers are currently unable to accurately forecast short-run food security risks posed by weather anomalies and long-run climate change projections. Recent machine learning approaches applied to high-resolution satellite imagery have successfully modeled various social and environmental variables. Here, we expand upon a recently developed machine learning approach to build a model that predicts maize yields over time using public satellite imagery. We developed a generalizable pipeline from survey data through a use case for predicting maize yields in Zambia. In 2020 and 2021, the Zambia Statistics Agency could not survey maize growers due to the COVID-19 pandemic. We use our model to fill in this data gap of maize yield predictions during these years. Through parameter optimization, we selected the model with the best ability to predict over space and time. Our model performed better overall relative to its predictive performance over time. The processed satellite imagery, predictions, and pipeline serve as a tool for the research community and users interested in analyzing Zambia’s current and future food security risks. This pipeline further enables users to explore global and region-specific questions at scale.</p>
</section>
<section id="acknowledgemnts" class="level4">
<h4 class="anchored" data-anchor-id="acknowledgemnts">Acknowledgemnts</h4>
<p>Bren School: Tamma Carleton, Assistant Professor; Brad Hill, IT Director; Allison Horst, Assistant Teaching Professor; Kat Le, Technical Applications Manager</p>
<p>Jonathan Proctor, postdoctoral fellow at the Harvard Data Science Initiative and the Center for the Environment</p>
<p>Baylis Lab, University of California, Santa Barbara</p>
<p>Zambia Statistics Agency</p>
<p>Microsoft Planetary Computer: Caleb Robinson, Tom Augsburger</p>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>
</section>

 ]]></description>
  <category>Python</category>
  <category>Remote Sensing</category>
  <category>Spatial Analysis</category>
  <category>Africa</category>
  <category>Agriculture</category>
  <category>MOSAIKS</category>
  <guid>https://cullen-molitor.github.io/posts/2022-05-29-publicpresentation/</guid>
  <pubDate>Sun, 29 May 2022 07:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2022-05-29-publicpresentation/public_presentations.png" medium="image" type="image/png" height="81" width="144"/>
</item>
<item>
  <title>New Horizons in Conservation Conference Poster Submission</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <dc:creator>Juliet Cohen</dc:creator>
  <dc:creator>Steven Cognac</dc:creator>
  <dc:creator>Grace Lewin</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2022-04-23-new-horizons/</link>
  <description><![CDATA[ 





<p><img src="https://cullen-molitor.github.io/posts/2022-04-23-new-horizons/NHC.png" style="width:99.0%"></p>
<section id="an-open-source-pipleline-for-remote-sensing-of-crop-yields-under-environmental-change-in-sub-saharan-africa" class="level3">
<h3 class="anchored" data-anchor-id="an-open-source-pipleline-for-remote-sensing-of-crop-yields-under-environmental-change-in-sub-saharan-africa">An open-source pipleline for remote sensing of crop yields under environmental change in sub-Saharan Africa</h3>
<section id="abstract" class="level4">
<h4 class="anchored" data-anchor-id="abstract">ABSTRACT:</h4>
<p>The environmental and social impacts of climate change are disproportionately distributed worldwide. Many highly impacted regions lack the assets to monitor and generate resource predictions, and therefore lack high-quality environmental and social data. As a result, it is difficult to make predictions about the impacts of climate change for these regions using conventional modeling. Recently, machine learning approaches applied to high-resolution satellite imagery have been successful in making predictions of a wide range of social and environmental variables. However, generating these predictions comes with significant barriers, including high computational, data storage, expertise, and financial resource costs. Reducing the financial and computational burden of machine learning approaches is essential to increasing the equity of environmental monitoring processes and outputs. Sub-Saharan Africa is one of these data-limited regions and is likely to suffer some of the largest impacts from climate change globally. To enable increased monitoring and data access across the sub-continent, we apply the novel machine learning approach, MOSAIKS, to create tabular features for sub-Saharan Africa using satellite imagery. These features, paired with ground-truth crop data from three countries, will be used to build a model that predicts crop yields over time in regions without crop data. This model will provide new insights into the historical crop yields of the region. Furthermore, these tabular features of satellite imagery, and the methodology developed to create them, will enable more people around the globe to build models and generate predictions of other social and environmental variables in this region.</p>
</section>
<section id="video-submission" class="level4">
<h4 class="anchored" data-anchor-id="video-submission">Video submission</h4>
<div class="quarto-video"><video id="video_shortcode_videojs_video1" class="video-js vjs-default-skin vjs-fluid" controls="" preload="auto" data-setup="{}" title=""><source src="New_Horizons_Video_CropMOSAIKS.mp4"></video></div>
</section>
<section id="poster-submission" class="level4">
<h4 class="anchored" data-anchor-id="poster-submission">Poster submission</h4>
<p><img src="https://cullen-molitor.github.io/posts/2022-04-23-new-horizons/New_Horizons_Conference_Poster_Final_1.png" style="width:99.0%"></p>
<p>Please feel free to contact my team at <strong>cp-cropmosaiks.bren.ucsb.edu</strong> or inspect our code in our github organization, <a href="https://github.com/cropmosaiks">cropMOSAIKS</a>. Thanks!</p>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>
</section>

 ]]></description>
  <category>Python</category>
  <category>Remote Sensing</category>
  <category>Spatial Analysis</category>
  <category>Africa</category>
  <category>Agriculture</category>
  <category>MOSAIKS</category>
  <guid>https://cullen-molitor.github.io/posts/2022-04-23-new-horizons/</guid>
  <pubDate>Sat, 23 Apr 2022 07:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2022-04-23-new-horizons/NHC.png" medium="image" type="image/png" height="83" width="144"/>
</item>
<item>
  <title>CropMOSAIKS Animated NDVI</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2022-01-23-cropmosaiks-animated-ndvi/</link>
  <description><![CDATA[ 





<section id="ndvi-animated-images" class="level1">
<h1>NDVI Animated Images</h1>
<p>The following code is adapted from a Google Earth Engine <a href="https://developers.google.com/earth-engine/tutorials/community/modis-ndvi-time-series-animation">JavaScript tutorial</a>. The code was translated into python and reproduced with several color palettes. The python code is found on the <a href="https://github.com/cropmosaiks/NDVI_Images">CropMOSAIKS GitHub</a>.</p>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> ee</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> geemap</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb1-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> glob</span>
<span id="cb1-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> PIL <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> Image</span></code></pre></div>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Initialize google earth engine</span></span>
<span id="cb2-2">ee.Initialize()</span>
<span id="cb2-3"></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fetch a MODIS NDVI collection and select NDVI.</span></span>
<span id="cb2-5">img_collection <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.ImageCollection(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'MODIS/006/MOD13A2'</span>).select(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'NDVI'</span>)</span>
<span id="cb2-6"></span>
<span id="cb2-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define a mask to clip the NDVI data by.</span></span>
<span id="cb2-8">mask <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.FeatureCollection(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'USDOS/LSIB_SIMPLE/2017'</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">filter</span>(ee.Filter.eq(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'wld_rgn'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Africa'</span>))</span>
<span id="cb2-9"></span>
<span id="cb2-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define the regional bounds of animation frames.</span></span>
<span id="cb2-11">region <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.Geometry.Polygon(</span>
<span id="cb2-12">  [[[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">18.698368046353494</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">38.1446395611524</span>],</span>
<span id="cb2-13">    [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">18.698368046353494</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">36.16300755581617</span>],</span>
<span id="cb2-14">    [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">52.229366328646506</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">36.16300755581617</span>],</span>
<span id="cb2-15">    [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">52.229366328646506</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">38.1446395611524</span>]]], <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>, <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span></span>
<span id="cb2-16">)</span></code></pre></div>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add day-of-year (DOY) property to each image.</span></span>
<span id="cb3-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> clip_and_get_day_of_year(img):</span>
<span id="cb3-3">    img <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> img.clip(mask)</span>
<span id="cb3-4">    doy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.Date(img.get(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'system:time_start'</span>)).getRelative(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'day'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>)</span>
<span id="cb3-5">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> img.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'doy'</span>, doy)</span></code></pre></div>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Apply median reduction among matching DOY collections.</span></span>
<span id="cb4-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> match_day_of_year_and_reduce(img):</span>
<span id="cb4-3">    doyCol <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.ImageCollection.fromImages(img.get(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'doy_matches'</span>))</span>
<span id="cb4-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> doyCol.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">reduce</span>(ee.Reducer.median())</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1">natural <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb5-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'FFFFFF'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CE7E45'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'DF923D'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'F1B555'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'FCD163'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'99B718'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'74A901'</span>,</span>
<span id="cb5-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'66A000'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'529400'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'3E8601'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'207401'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'056201'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'004C00'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'023B01'</span>,</span>
<span id="cb5-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'012E01'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'011D01'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'011301'</span></span>
<span id="cb5-5">]</span>
<span id="cb5-6">viridis <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb5-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#440154FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#48186AFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#472D7BFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#424086FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3B528BFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#33638DFF"</span>, </span>
<span id="cb5-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2C728EFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#26828EFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#21908CFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1F9F88FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#27AD81FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3EBC74FF"</span>,</span>
<span id="cb5-9">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#5DC863FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#82D34DFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#AADC32FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#D5E21AFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FDE725FF"</span></span>
<span id="cb5-10">]</span>
<span id="cb5-11">magma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb5-12">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#000004FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#0B0724FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#210C4AFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3D0965FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#56106EFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#71196EFF"</span>, </span>
<span id="cb5-13">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#89226AFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#A32C61FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#BB3754FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#D14545FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#E35932FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F1721EFF"</span>,</span>
<span id="cb5-14">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F98C0AFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FCAA0FFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F9C932FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F2E865FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FCFFA4FF"</span></span>
<span id="cb5-15">]</span>
<span id="cb5-16">cividis <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb5-17">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#00204DFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#002C69FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#05366EFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2D426CFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#414D6BFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#52596CFF"</span>, </span>
<span id="cb5-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#61646FFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#6F7073FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#7C7B78FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#8B8779FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#9B9477FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ACA174FF"</span>,</span>
<span id="cb5-19">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#BCAF6FFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#CEBC68FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#E0CB5EFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F2DA50FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FFEA46FF"</span></span>
<span id="cb5-20">]</span></code></pre></div>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define visualization parameters.</span></span>
<span id="cb6-2">vis_params <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb6-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'region'</span>: region,</span>
<span id="cb6-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimensions'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>,</span>
<span id="cb6-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'crs'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'EPSG:3857'</span>,</span>
<span id="cb6-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'framesPerSecond'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb6-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'min'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>,</span>
<span id="cb6-8">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'max'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">9000.0</span>,</span>
<span id="cb6-9">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'palette'</span>: magma</span>
<span id="cb6-10">}</span></code></pre></div>
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1">img_collection <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> img_collection.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">map</span>(clip_and_get_day_of_year)</span>
<span id="cb7-2">img_dates <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> img_collection.aggregate_array(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'system:index'</span>).getInfo()</span></code></pre></div>
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1">start_yr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(img_dates[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>][:<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])</span>
<span id="cb8-2">end_yr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(img_dates[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>][:<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])</span>
<span id="cb8-3">years <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(start_yr, end_yr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb8-4">index_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span></code></pre></div>
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> year <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> years:</span>
<span id="cb9-2">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Downloading: '</span>, year)</span>
<span id="cb9-3">    date_start <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>(year)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">-01-01'</span></span>
<span id="cb9-4">    date_end <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>(year)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">-12-31'</span></span>
<span id="cb9-5">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Get a collection of distinct images by 'doy'.</span></span>
<span id="cb9-6">    distinct_doy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> img_collection.filterDate(date_start, date_end)</span>
<span id="cb9-7"></span>
<span id="cb9-8">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define a filter that identifies which images from the complete</span></span>
<span id="cb9-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># collection match the DOY from the distinct DOY collection.</span></span>
<span id="cb9-10">    filtered <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.Filter.equals(leftField <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'doy'</span>, rightField <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'doy'</span>)</span>
<span id="cb9-11"></span>
<span id="cb9-12">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define a join.</span></span>
<span id="cb9-13">    joined <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.Join.saveAll(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'doy_matches'</span>)</span>
<span id="cb9-14"></span>
<span id="cb9-15">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Apply the join and convert the resulting FeatureCollection to an ImageCollection.</span></span>
<span id="cb9-16">    join_img_collection <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.ImageCollection(joined.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">apply</span>(distinct_doy, img_collection, filtered))</span>
<span id="cb9-17"></span>
<span id="cb9-18">    img_composite <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> join_img_collection.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">map</span>(match_day_of_year_and_reduce)</span>
<span id="cb9-19">    index_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> index_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> img_composite.aggregate_array(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'system:index'</span>).getInfo()</span>
<span id="cb9-20">    </span>
<span id="cb9-21">    temp_file_name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"animations/temp_ndvi_</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>(year)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">.gif"</span></span>
<span id="cb9-22">    </span>
<span id="cb9-23">    geemap.download_ee_video(img_composite, vis_params, temp_file_name)</span></code></pre></div>
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># filepaths</span></span>
<span id="cb10-2">fp_in <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"animations/temp_*.gif"</span></span>
<span id="cb10-3">fp_out <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"animations/ndvi.gif"</span></span>
<span id="cb10-4"></span>
<span id="cb10-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#gif</span></span>
<span id="cb10-6">img, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>imgs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [Image.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">open</span>(f) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sorted</span>(glob.glob(fp_in))]</span>
<span id="cb10-7">img.save(fp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> fp_out, </span>
<span id="cb10-8">         <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">format</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'GIF'</span>,</span>
<span id="cb10-9">         append_images <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> imgs,</span>
<span id="cb10-10">         save_all <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, </span>
<span id="cb10-11">         duration <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, </span>
<span id="cb10-12">         loop <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div>
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1">geemap.add_text_to_gif(</span>
<span id="cb11-2">    in_gif <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> fp_out, </span>
<span id="cb11-3">    out_gif <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> fp_out,</span>
<span id="cb11-4">    xy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'75%'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'1%'</span>),</span>
<span id="cb11-5">    text_sequence <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> index_array,</span>
<span id="cb11-6">    font_type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'arial.ttf'</span>,</span>
<span id="cb11-7">    font_size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>,</span>
<span id="cb11-8">    font_color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>,</span>
<span id="cb11-9">    add_progress_bar <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb11-10">    progress_bar_color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>,</span>
<span id="cb11-11">    progress_bar_height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb11-12">    duration <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># milliseconds per frame so 200 is 5 fps, 100 is 10 fps etc</span></span>
<span id="cb11-13">    loop <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb11-14">)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2022-01-23-cropmosaiks-animated-ndvi/ndvi.gif" class="img-fluid"></p>
<div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>

 ]]></description>
  <category>Python</category>
  <category>Spatial Analysis</category>
  <category>Remote Sensing</category>
  <category>Google Earth Engine</category>
  <category>Africa</category>
  <category>MOSAIKS</category>
  <guid>https://cullen-molitor.github.io/posts/2022-01-23-cropmosaiks-animated-ndvi/</guid>
  <pubDate>Sun, 23 Jan 2022 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2022-01-23-cropmosaiks-animated-ndvi/ndvi.gif" medium="image" type="image/gif"/>
</item>
<item>
  <title>Creating Team Graphics</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2022-01-22-cropmosaiks-team-graphics/</link>
  <description><![CDATA[ 





<section id="ndvi-static-images" class="level1">
<h1>NDVI Static Images</h1>
<p>The following code is adapted from a Google Earth Engine <a href="https://developers.google.com/earth-engine/tutorials/community/modis-ndvi-time-series-animation">JavaScript tutorial</a>. The code was translated into python, made static, and reproduced with several color palettes. The python code is found on the <a href="https://github.com/cropmosaiks/NDVI_Images">CropMOSAIKS GitHub</a>.</p>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> ee</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> IPython.display <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> Image</span></code></pre></div>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">ee.Initialize()</span></code></pre></div>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1">ndvi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.ImageCollection(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'MODIS/006/MOD13A2'</span>).select(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'NDVI'</span>)</span></code></pre></div>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">mask <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.FeatureCollection(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'USDOS/LSIB_SIMPLE/2017'</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">filter</span>(ee.Filter.eq(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'wld_rgn'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Africa'</span>))</span></code></pre></div>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1">region <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.Geometry.Polygon(</span>
<span id="cb5-2">  [</span>
<span id="cb5-3">      [</span>
<span id="cb5-4">          [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">19.698368046353494</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">38.1446395611524</span>],</span>
<span id="cb5-5">          [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">19.698368046353494</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">36.16300755581617</span>],</span>
<span id="cb5-6">          [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">53.229366328646506</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">36.16300755581617</span>],</span>
<span id="cb5-7">          [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">53.229366328646506</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">38.1446395611524</span>]</span>
<span id="cb5-8">      ]</span>
<span id="cb5-9">  ]</span>
<span id="cb5-10">)</span></code></pre></div>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1">ndvi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ndvi.filterDate(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2013-01-01'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2014-01-01'</span>)</span></code></pre></div>
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1">ndvi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ndvi.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">reduce</span>(ee.Reducer.median())</span></code></pre></div>
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1">ndvi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ndvi.clip(mask)</span></code></pre></div>
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1">natural <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb9-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'FFFFFF'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CE7E45'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'DF923D'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'F1B555'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'FCD163'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'99B718'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'74A901'</span>,</span>
<span id="cb9-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'66A000'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'529400'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'3E8601'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'207401'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'056201'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'004C00'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'023B01'</span>,</span>
<span id="cb9-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'012E01'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'011D01'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'011301'</span></span>
<span id="cb9-5">]</span>
<span id="cb9-6">viridis <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb9-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#440154FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#48186AFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#472D7BFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#424086FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3B528BFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#33638DFF"</span>, </span>
<span id="cb9-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2C728EFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#26828EFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#21908CFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1F9F88FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#27AD81FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3EBC74FF"</span>,</span>
<span id="cb9-9">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#5DC863FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#82D34DFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#AADC32FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#D5E21AFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FDE725FF"</span></span>
<span id="cb9-10">]</span>
<span id="cb9-11">magma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb9-12">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#000004FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#0B0724FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#210C4AFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3D0965FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#56106EFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#71196EFF"</span>, </span>
<span id="cb9-13">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#89226AFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#A32C61FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#BB3754FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#D14545FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#E35932FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F1721EFF"</span>,</span>
<span id="cb9-14">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F98C0AFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FCAA0FFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F9C932FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F2E865FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FCFFA4FF"</span></span>
<span id="cb9-15">]</span>
<span id="cb9-16">cividis <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb9-17">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#00204DFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#002C69FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#05366EFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2D426CFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#414D6BFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#52596CFF"</span>, </span>
<span id="cb9-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#61646FFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#6F7073FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#7C7B78FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#8B8779FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#9B9477FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ACA174FF"</span>,</span>
<span id="cb9-19">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#BCAF6FFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#CEBC68FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#E0CB5EFF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#F2DA50FF"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FFEA46FF"</span></span>
<span id="cb9-20">  ]</span></code></pre></div>
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#  # Closer to True color</span></span>
<span id="cb10-2">visParams <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb10-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'min'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>,</span>
<span id="cb10-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'max'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">9000.0</span>,</span>
<span id="cb10-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimensions'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">512</span>,</span>
<span id="cb10-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'region'</span>: region, </span>
<span id="cb10-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'opacity'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb10-8">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'palette'</span>: natural</span>
<span id="cb10-9">}</span></code></pre></div>
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1">url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ndvi.getThumbUrl(visParams)</span>
<span id="cb11-2">Image(url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>url, embed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">format</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'png'</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2022-01-22-cropmosaiks-team-graphics/output_11_0.png" class="img-fluid"></p>
<div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># # Viridis</span></span>
<span id="cb12-2">visParams <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb12-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'min'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>,</span>
<span id="cb12-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'max'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">9000.0</span>,</span>
<span id="cb12-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimensions'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">512</span>,</span>
<span id="cb12-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'region'</span>: region, </span>
<span id="cb12-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'opacity'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb12-8">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'palette'</span>: viridis</span>
<span id="cb12-9">}</span></code></pre></div>
<div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1">url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ndvi.getThumbUrl(visParams)</span>
<span id="cb13-2">Image(url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>url, embed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">format</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'png'</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2022-01-22-cropmosaiks-team-graphics/output_13_0.png" class="img-fluid"></p>
<div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb14-1">visParams <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb14-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'min'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>,</span>
<span id="cb14-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'max'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">9000.0</span>,</span>
<span id="cb14-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimensions'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">512</span>,</span>
<span id="cb14-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'region'</span>: region, </span>
<span id="cb14-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'opacity'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb14-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'palette'</span>: magma</span>
<span id="cb14-8">}</span></code></pre></div>
<div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1">url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ndvi.getThumbUrl(visParams)</span>
<span id="cb15-2">Image(url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>url, embed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">format</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'png'</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2022-01-22-cropmosaiks-team-graphics/output_15_0.png" class="img-fluid"></p>
<div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1">visParams <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb16-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'min'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>,</span>
<span id="cb16-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'max'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">9000.0</span>,</span>
<span id="cb16-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimensions'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">512</span>,</span>
<span id="cb16-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'region'</span>: region, </span>
<span id="cb16-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'opacity'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb16-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'palette'</span>: cividis</span>
<span id="cb16-8">}</span></code></pre></div>
<div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1">url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ndvi.getThumbUrl(visParams)</span>
<span id="cb17-2">Image(url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>url, embed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">format</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'png'</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2022-01-22-cropmosaiks-team-graphics/output_17_0.png" class="img-fluid"></p>
<div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>

 ]]></description>
  <category>Python</category>
  <category>Spatial Analysis</category>
  <category>Remote Sensing</category>
  <category>Google Earth Engine</category>
  <category>Africa</category>
  <category>MOSAIKS</category>
  <guid>https://cullen-molitor.github.io/posts/2022-01-22-cropmosaiks-team-graphics/</guid>
  <pubDate>Sat, 22 Jan 2022 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2022-01-22-cropmosaiks-team-graphics/output_13_0.png" medium="image" type="image/png" height="171" width="144"/>
</item>
<item>
  <title>Channel Islands SST</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2022-01-22-channel-islands-sst/</link>
  <description><![CDATA[ 





<section id="libraries" class="level2">
<h2 class="anchored" data-anchor-id="libraries">Libraries</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(lubridate)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(sf)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rerddap)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(marmap)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(raster)</span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cowplot)</span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggspatial)</span>
<span id="cb1-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gganimate)</span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gifski)</span></code></pre></div>
</details>
</section>
<section id="geographic-data" class="level2">
<h2 class="anchored" data-anchor-id="geographic-data">Geographic Data</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">ca <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_sf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CA.gpkg"</span>)</span>
<span id="cb2-2">Site_Info <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Site_Info.csv"</span>)</span></code></pre></div>
</details>
</section>
<section id="griddap-query" class="level2">
<h2 class="anchored" data-anchor-id="griddap-query">Griddap Query</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">lat_min <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">33.35</span></span>
<span id="cb3-2">lat_max <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">34.5</span></span>
<span id="cb3-3">lon_min <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">120.75</span></span>
<span id="cb3-4">lon_max <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">118.95</span></span>
<span id="cb3-5"></span>
<span id="cb3-6">lat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(lat_min, lat_max)</span>
<span id="cb3-7">lon <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(lon_min, lon_max)</span>
<span id="cb3-8"></span>
<span id="cb3-9">tm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb3-10">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2009-01-02T12:00:00Z"</span>,</span>
<span id="cb3-11">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2009-12-30T12:00:00Z'</span></span>
<span id="cb3-12">)</span>
<span id="cb3-13"></span>
<span id="cb3-14">SST <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'jplMURSST41'</span></span>
<span id="cb3-15">field <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'analysed_sst'</span></span>
<span id="cb3-16">murSST_west <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">griddap</span>(</span>
<span id="cb3-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> SST,</span>
<span id="cb3-18">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">latitude =</span> lat,</span>
<span id="cb3-19">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">longitude =</span> lon,</span>
<span id="cb3-20">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> tm,</span>
<span id="cb3-21">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fields =</span> field</span>
<span id="cb3-22">)</span>
<span id="cb3-23">sst <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(murSST_west<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(lat, lon) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sst =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(analysed_sst))</span></code></pre></div>
</details>
</section>
<section id="bathymetry-querry" class="level2">
<h2 class="anchored" data-anchor-id="bathymetry-querry">Bathymetry Querry</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">ca_bath <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> marmap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getNOAA.bathy</span>(</span>
<span id="cb4-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lon1 =</span> lon_min <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb4-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lon2 =</span> lon_max <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb4-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lat1 =</span> lat_min <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb4-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lat2 =</span> lat_max <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb4-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">resolution =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb4-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-8">  marmap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.raster</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-9">  raster<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rasterToPoints</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-10">  base<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>() </span></code></pre></div>
</details>
</section>
<section id="make-california-map-for-inset" class="level2">
<h2 class="anchored" data-anchor-id="make-california-map-for-inset">Make California Map for Inset</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">box <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sf<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_polygon</span>(</span>
<span id="cb5-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb5-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(</span>
<span id="cb5-4">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(lon_min, lat_max), </span>
<span id="cb5-5">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(lon_max, lat_max), </span>
<span id="cb5-6">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(lon_max, lat_min), </span>
<span id="cb5-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(lon_min, lat_min),</span>
<span id="cb5-8">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(lon_min, lat_max)</span>
<span id="cb5-9">    )</span>
<span id="cb5-10">  )</span>
<span id="cb5-11">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_sfc</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4326</span>)</span>
<span id="cb5-12"></span>
<span id="cb5-13">C <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> ca, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> box, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_void</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.border =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),</span>
<span id="cb5-18">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)))</span></code></pre></div>
</details>
</section>
<section id="plot-static-map" class="level2">
<h2 class="anchored" data-anchor-id="plot-static-map">Plot Static Map</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">main.plot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_raster</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> sst, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> lon, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> lat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> sst), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interpolate =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis_c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">option =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_colorbar</span>(</span>
<span id="cb6-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"horizontal"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">frame.colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,</span>
<span id="cb6-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">barheight =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'cm'</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> ca, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey70"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey40"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_contour</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> ca_bath, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">z =</span> layer),</span>
<span id="cb6-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(ca_bath<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>layer), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(ca_bath<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>layer), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>),</span>
<span id="cb6-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> lon, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">119.5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> lat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">33.75</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">34.25</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Site_Info, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> Longitude, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Latitude),</span>
<span id="cb6-13">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#d55b23'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> F, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">inherit.aes =</span> F) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_viridis_d</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">option =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'magma'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">begin =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> force) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SST (\u00B0C)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotation_scale</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">location =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bl"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotation_north_arrow</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">which_north =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">location =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tr"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pad_x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.75</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>),</span>
<span id="cb6-18">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.125</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.12</span>),</span>
<span id="cb6-21">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bold'</span>),</span>
<span id="cb6-22">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bold'</span>),</span>
<span id="cb6-23">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'black'</span>),</span>
<span id="cb6-24">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>),</span>
<span id="cb6-25">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb6-26">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unit =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'cm'</span>),</span>
<span id="cb6-27">                                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bold'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">270</span>),</span>
<span id="cb6-28">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unit =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'cm'</span>),</span>
<span id="cb6-29">                                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bold'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>),</span>
<span id="cb6-30">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.border =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)</span>
<span id="cb6-31">  )</span>
<span id="cb6-32"></span>
<span id="cb6-33"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggdraw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw_plot</span>(main.plot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draw_plot</span>(C, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.72</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">77</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2022-01-22-channel-islands-sst/figures/unnamed-chunk-6-1.png" width="720"></p>
</section>
<section id="plot-animated-map" class="level2">
<h2 class="anchored" data-anchor-id="plot-animated-map">Plot Animated Map</h2>
<p>Showing 2014-2016 to highlight the 2015-2016 El Nino.</p>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">redo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb7-2"></span>
<span id="cb7-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.exists</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sst.gif"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> redo){</span>
<span id="cb7-4">  tm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb7-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2014-01-01T12:00:00Z"</span>,</span>
<span id="cb7-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2016-12-30T12:00:00Z'</span></span>
<span id="cb7-7">  )</span>
<span id="cb7-8">  </span>
<span id="cb7-9">  murSST_west <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">griddap</span>(</span>
<span id="cb7-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> SST, </span>
<span id="cb7-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">latitude =</span> lat, </span>
<span id="cb7-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">longitude =</span> lon,</span>
<span id="cb7-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">time =</span> tm, </span>
<span id="cb7-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fields =</span> field</span>
<span id="cb7-15">  )<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-16">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_time =</span> lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_datetime</span>(time),</span>
<span id="cb7-17">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date =</span> lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">date</span>(date_time)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(date, lon, lat) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sst =</span> analysed_sst)</span>
<span id="cb7-20">  </span>
<span id="cb7-21">  p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_raster</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> murSST_west, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> lon, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> lat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> sst), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interpolate =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-23">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis_c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">option =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'viridis'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_colorbar</span>(</span>
<span id="cb7-24">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"horizontal"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">frame.colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,</span>
<span id="cb7-25">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">barheight =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'cm'</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> ca, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey70"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey40"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-27">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_contour</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> ca_bath, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">z =</span> layer), </span>
<span id="cb7-28">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(ca_bath<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>layer), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(ca_bath<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>layer), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>), </span>
<span id="cb7-29">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> lon, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">119.5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-31">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> lat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">33.75</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">34.25</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-32">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_viridis_d</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">option =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'magma'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">begin =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> force) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-33">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SST (\u00B0C)"</span>, </span>
<span id="cb7-34">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{frame_time}"</span>,</span>
<span id="cb7-35">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-36">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotation_scale</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">location =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bl"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-37">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotation_north_arrow</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">which_north =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">location =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tr"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#pad_x = unit(2.75, "cm"),</span></span>
<span id="cb7-38">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-39">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-40">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.125</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.12</span>),</span>
<span id="cb7-41">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bold'</span>),</span>
<span id="cb7-42">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bold'</span>),</span>
<span id="cb7-43">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.background =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'black'</span>),</span>
<span id="cb7-44">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>),</span>
<span id="cb7-45">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb7-46">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unit =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'cm'</span>),</span>
<span id="cb7-47">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bold'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">270</span>),</span>
<span id="cb7-48">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unit =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'cm'</span>),</span>
<span id="cb7-49">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bold'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>),</span>
<span id="cb7-50">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.border =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-51">    gganimate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transition_time</span>(date)</span>
<span id="cb7-52">  </span>
<span id="cb7-53">  gganimate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">animate</span>(p1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">720</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">480</span>,</span>
<span id="cb7-54">                     <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># renderer = av_renderer(),</span></span>
<span id="cb7-55">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nframes =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb7-56">  </span>
<span id="cb7-57">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anim_save</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">filename =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sst.gif"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">animation =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last_animation</span>())</span>
<span id="cb7-58">}</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2022-01-22-channel-islands-sst/sst.gif" class="img-fluid"></p>
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>

 ]]></description>
  <category>R</category>
  <category>Ocean Data</category>
  <category>Remote Sensing</category>
  <category>Spatial Analysis</category>
  <category>ENSO</category>
  <guid>https://cullen-molitor.github.io/posts/2022-01-22-channel-islands-sst/</guid>
  <pubDate>Fri, 21 Jan 2022 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2022-01-22-channel-islands-sst/sst.gif" medium="image" type="image/gif"/>
</item>
<item>
  <title>Effect of ENSO on Kelp Forest Species</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2021-12-05-species-density-sst-lagsst/</link>
  <description><![CDATA[ 





<section id="motivation" class="level1">
<h1>Motivation</h1>
<p>California’s Northern Channel Islands sit at the transition between two biogeographic provinces, the cold-water North Pacific and the warm-water Gulf of California. San Miguel and Santa Rosa Islands have species representative of the North Pacific province while Anacapa and Santa Barbara Islands sit firmly in the Gulf of California province. Santa Cruz Island lies in the transition zone with the western end of the island favoring North Pacific species and the eastern end favoring Gulf of California species. This makes the Northern Channel Islands a unique place to study how species distribution and recruitment respond to ocean temperatures.</p>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-05-species-density-sst-lagsst/sst.png" class="img-fluid"></p>
<div class="line-block">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Figure 1. The Southern California Bight (SCB) shown with a composite sea<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;surface temperatures (SST) color gradient for 2009. This SST is typical of<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the region and illustrates the transition between the North Pacific and Gulf<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;of California biogegeographic provinces (<a href="https://cullen-molitor.github.io/posts/2022-01-22-channel-islands-sst/">source</a>).</div>
<p><br>
</p>
<p>The El Niño Southern Oscillation (<a href="https://www.climate.gov/news-features/blogs/enso/what-el-ni%C3%B1o%E2%80%93southern-oscillation-enso-nutshell">ENSO</a>) is measured primarily by the Oceanic Niño Index which calculates a SST <a href="https://origin.cpc.ncep.noaa.gov/products/analysis_monitoring/ensostuff/ONI_change.shtml">anomaly value</a> value each month going back to 1950. These values are derived from SST in the equatorial pacific (\(\pm5^{\circ}\) latitude, \(120^{\circ}-170^{\circ}W\) longitude). The patterns of SST in this region are responsible for driving certain global weather and climate patterns. Despite the distance from this region, ENSO has a large effect on the oceanographic conditions of the SCB and the Channel Islands. This effect includes an influence on local SST as well as the strength and direction of ocean currents. These effects are known to influence the distribution and abundance of certain marine species (<a href="https://www.frontiersin.org/articles/10.3389/fmars.2019.00497">Day 2018</a>, <a href="https://www.nature.com/articles/s41598-020-77885-3">Freedman 2020</a>).</p>
<p>This analysis takes a shotgun approach to investigate which species are sensitive to either warm-water or cold-water events by using a series of species-level dynamic linear models with lag SST anomalies as predictor variables. These models will provide a broad overview of which species are affected, how they are affected, and whether or not the affect is statistically significant. This will inform our understanding of how species distribution and population ranges might be affected by changing oceanographic conditions due to climate change.</p>
</section>
<section id="data" class="level1">
<h1>Data</h1>
<p>The Kelp Forest Monitoring (KFM) program at Channel Islands National Park has been collecting abundance and size distribution data of more than 170 species since 1982 (sampled annually). The park currently samples 33 sites at the five islands in the National Park. This data is publicly available and was requested and issued under a <a href="https://irma.nps.gov/RPRS/">scientific research and collecting permit</a> (permit #: CHIS-2020-SCI-0006). These data are collected using scuba surveys where the biologists attempt to minimize their impact on the reef by using non-invasive sampling methods. This means that animals are counted in situ and no rocks are overturned or species removed. This inevitably biases the data towards adult populations of certain invertebrates that utilize crevice habitat during development as they will be hidden from direct observation.</p>
<p>The fish data is collected in (#\(/m^3\)). In order to assure that all data are in the same units, only measurements of invertebrate and algae density (#\(/m^2\)) are retained. This takes the total number of species with density data from 151 down to 35. Using species density, we can identify trends in abundance observed over multiple El Niño (warm-water) and La Niña (cold-water) events. Using a dynamic linear model with lag independent variables we can see the effect of sea surface temperature anomalies during and in the years following these events on species density.</p>
<p>Below we read in ENSO data and calculate yearly mean anomalies before making 5 new columns with corresponding lag values. We then load in the species density data and filter out fish and 2 species which are exceedingly rare and do not have enough data to model. This leaves us with 33 species to model, all with the same units.</p>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Load libraries</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(here)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(lubridate)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(broom)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(arrow)</span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(plotly)</span>
<span id="cb1-8"></span>
<span id="cb1-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Load and Tidy Data</span></span>
<span id="cb1-10">oni_yearly <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Read in Oceanic Nino Index region 3.4 data</span></span>
<span id="cb1-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.table</span>(</span>
<span id="cb1-12">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://origin.cpc.ncep.noaa.gov/products/analysis_monitoring/ensostuff/detrend.nino34.ascii.txt"</span>,</span>
<span id="cb1-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">header =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-14">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># rename YR for joining tables</span></span>
<span id="cb1-15">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SurveyYear =</span> YR) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-16">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(SurveyYear) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-17">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Calculate yearly SST Anom</span></span>
<span id="cb1-18">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SST_Anom =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(ANOM)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-19">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create lagged SST</span></span>
<span id="cb1-20">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SST_Anom_1 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lag</span>(SST_Anom, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb1-21">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SST_Anom_2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lag</span>(SST_Anom, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-22">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SST_Anom_3 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lag</span>(SST_Anom, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb1-23">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SST_Anom_4 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lag</span>(SST_Anom, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>),</span>
<span id="cb1-24">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SST_Anom_5 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lag</span>(SST_Anom, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb1-25"></span>
<span id="cb1-26"></span>
<span id="cb1-27">density <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Read in Density data</span></span>
<span id="cb1-28">  arrow<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_feather</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density.feather"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-29">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Classification <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fish"</span>,</span>
<span id="cb1-30">                <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>CommonName <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wakame, adult"</span>, </span>
<span id="cb1-31">                                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wakame, juvenile"</span>, </span>
<span id="cb1-32">                                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white abalone"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-33">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(oni_yearly)</span></code></pre></div>
</details>
</section>
<section id="analysis" class="level1">
<h1>Analysis</h1>
<p>This analysis will use a general model formula of lm(Mean_Density ~ SST_Anom + SST_Anom_1 + SST_Anom_2 + SST_Anom_3 + SST_Anom_4 + SST_Anom_5) applied to density data grouped by each species scientific name. These five lag periods will show how a species is affected within the same year, and for the next five years following anomalous warm or cold water. We expect recruitment of certain species will either increases or decreases following warmer than usual or colder than usual ocean temperatures. Given what we know about the life cycle of many marine species, it is reasonable to assume these effects would not be detected by non-invasive sampling techniques for 1-5 years following anomalous temperatures.</p>
<p>This analysis is simplified to detect trends in a large number of species and does not take into account the effect of biogeography. This also does not consider the impact of marine protected areas (MPAs) which potentially buffer the ecological community from the effects of abiotic factors such as SST. MPAs could also have an effect from increased predation to some of these species, potentially limiting their abundance.</p>
<p>The cumulative effect on all species will be plotted. Then the results will be filtered to only include significant affects and sorted by the estimated slope of their relationship. The two species with the most positive slope and the two with the most negative slope will have their coefficients plotted over the lag periods.</p>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">Results_lag <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> density <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-2">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(ScientificName) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-3">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb2-4">    generics<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tidy</span>(</span>
<span id="cb2-5">      stats<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(</span>
<span id="cb2-6">        Mean_Density <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> SST_Anom <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> SST_Anom_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> SST_Anom_2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> SST_Anom_3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> SST_Anom_4 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> SST_Anom_5</span>
<span id="cb2-7">        ))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-8">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(term <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Intercept)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-9">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">significant =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(p.value <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"yes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"no"</span>))</span></code></pre></div>
</details>
</section>
<section id="results" class="level1">
<h1>Results</h1>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">Results_filtered <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Results_lag <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-2">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(p.value <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-3">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(estimate) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-4">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistic =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(statistic, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb3-5">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p.value =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(p.value, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb3-6">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p.value =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(p.value <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt; 0.001"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(p.value))) </span>
<span id="cb3-7">cold_sp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Results_filtered <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(estimate) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distinct</span>(ScientificName) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>()</span>
<span id="cb3-12"></span>
<span id="cb3-13">warm_sp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Results_filtered <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(estimate)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distinct</span>(ScientificName) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>()</span>
<span id="cb3-18"></span>
<span id="cb3-19">cold <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Results_lag <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(ScientificName) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cum_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cumsum</span>(estimate)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(ScientificName <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> cold_sp)</span>
<span id="cb3-23"></span>
<span id="cb3-24">warm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Results_lag <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(ScientificName) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cum_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cumsum</span>(estimate)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(ScientificName <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> warm_sp)</span>
<span id="cb3-28"></span>
<span id="cb3-29">plt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.data =</span> cold) {</span>
<span id="cb3-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> .data, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> term, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> cum_est)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-31">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> ScientificName, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> ScientificName), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-32">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape =</span> significant), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-33">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-34">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Current Year"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+2"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+3"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+4"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+5"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-35">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_viridis_d</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">option =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-36">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Years relative to SST anomaly exposure"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cumulative effect (sum of coefficients)"</span>,</span>
<span id="cb3-37">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P-Val &lt; .05?"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Species"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-38">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>() </span>
<span id="cb3-39">}</span></code></pre></div>
</details>
<section id="cold-water-species" class="level2">
<h2 class="anchored" data-anchor-id="cold-water-species">Cold-water species</h2>
<p>The two species with the largest negative cumulative effect were identified as <em>Strongylocentrotus purpuratus</em> (purple sea urchin) and <em>Strongylocentrotus franciscanus</em> (red sea urchin). Purple sea urchin seem to have the most extreme negative coefficients, suggesting that this species thrives under cold-water conditions. Red sea urchins have a similar though less extreme response to cold-water conditions. In both urchin species, the effect is significant in the same year, as well as the year following cold-water conditions. This makes sense, because despite non-invasive sampling, juvenile sea urchins as small as 1 mm have been recorded by KFM observers.</p>
<p><em>Patiria miniata</em> (bat star) had the third most negative cumulative effect. This species is particularly affected by warm water, which tends to cause a form of sea star wasting disease (SSWD). Bat star populations take years to rebound following SSWD events. This slow recovery is seen in the cumulative effect which is statistically significant for the current period and for the following four years.</p>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plt</span>()</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-05-species-density-sst-lagsst/figures/unnamed-chunk-4-1.png" width="960"></p>
<div class="line-block">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Figure 2. The cumulative effect that SST anomalies have on the three species<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;which have the largest negative slope estimates of all statistically significant<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results. The effect accumulates from the current year to the following 5 years.</div>
<p><br>
</p>
</section>
<section id="warm-water-species" class="level2">
<h2 class="anchored" data-anchor-id="warm-water-species">Warm-water species</h2>
<p><em>Sargassum horneri</em> (devil weed) had the single most positive cumulative effect of any species. This is an invasive algae that has spread rapidly at the Channel Islands since its introduction to Catalina island in 2006 (Miller 2007). Predicting what factors contribute to the spread of <em>S. horneri</em> will help scientist understand where to expect it next and what impacts it might have on the ecologic communities it settles in. Only the current year is seen to be positive, suggesting that <em>S. horneri</em> juveniles are largely responsible for the effect.</p>
<p><em>Megastaea undosa</em> (wavy turban snail) is an important grazing snail that is known to spawn in warm-water conditions which means that ENSO may be helpful in setting harvest quotas (Zacharias 2006). The effect is only significant 2, 3, and 4 years following a warm water event. I would argue that these snails spawn late in the year when the water is warmest and the sampling season is coming to a close. The following year, the juvenile snails are most likely missed as they are too cryptic. Then during the 2nd, 3rd, and 4th year, these animals are largest enough to be observed reliably.</p>
<p><em>Lytechinus anamesus</em> likely follow the same pattern as <em>M. undosa</em>. I would be interested to investigate MPA effects on these lobster and sheephead snack-sized sea urchin (&lt;40 mm typically).</p>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plt</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.data =</span> warm)</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-05-species-density-sst-lagsst/figures/unnamed-chunk-5-1.png" width="960"></p>
<div class="line-block">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Figure 3. The cumulative effect that SST anomalies have on the three species<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;which have the largest positive slope estimates of all statistically significant<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results. The effect accumulates from the current year to the following 5 years.</div>
<p><br>
</p>
</section>
</section>
<section id="future-work" class="level1">
<h1>Future Work</h1>
<section id="better-models" class="level2">
<h2 class="anchored" data-anchor-id="better-models">Better Models</h2>
<p>Include biogeogrphic regions to see how species abundance is affected by region. I would also like to include MPA status to identify if there are any buffer effects provided by the MPA, or impacts to prey species from increased preddation.</p>
</section>
<section id="more-protocolsspecies" class="level2">
<h2 class="anchored" data-anchor-id="more-protocolsspecies">More Protocols/Species</h2>
<p>This analysis only uses 2 out of 13 sampling protocols of the KFM program. The analysis could be expanded to include data from the two fish surveys, as well as percent cover data from random point contacts survey.</p>
</section>
<section id="integrate-program-data" class="level2">
<h2 class="anchored" data-anchor-id="integrate-program-data">Integrate Program Data</h2>
<p>This analysis could be made more robust by including data from the Partnership for Interdisciplinary Study of Coastal Oceans (PISCO), which conducts similar monitoring efforts around the Channel Islands.</p>
</section>
</section>
<section id="code-availability" class="level1">
<h1>Code Availability</h1>
<p><a href="https://github.com/cullen-molitor/cullen-molitor.github.io/tree/main/_posts/2021-12-01-eds-222-final-project-species-density-sst">GitHub Repository with all code and data available at this link.</a></p>
</section>
<section id="literature-cited" class="level1">
<h1>Literature Cited</h1>
<p>Costello, M.J., Tsai, P., Wong, P.S. et al.&nbsp;Marine biogeographic realms and species endemicity. Nat Commun 8, 1057 (2017). <a href="https://doi.org/10.1038/s41467-017-01121-2" class="uri">https://doi.org/10.1038/s41467-017-01121-2</a></p>
<p>Day, P. B., Stuart-Smith, R. D., Edgar, G. J. &amp; Bates, A. E. Species’ thermal ranges predict changes in reef fish community structure during 8 years of extreme temperature variation. Divers. Distrib. 24, 1036–1046 (2018).</p>
<p>Freedman, R.M., Brown, J.A., Caldow, C. et al.&nbsp;Marine protected areas do not prevent marine heatwave-induced fish community structure changes in a temperate transition zone. Sci Rep 10, 21081 (2020). <a href="https://doi.org/10.1038/s41598-020-77885-3" class="uri">https://doi.org/10.1038/s41598-020-77885-3</a></p>
<p>Horta e Costa, B. Tropicalization of fish assemblages in temperate biogeographic transition zones. Mar.&nbsp;Ecol. Prog. Ser. 504, 241–252 (2014).</p>
<p>Miller, K. A., Engle, J. M., Uwai, S., &amp; Kawai, H. (2007). First report of the asian seaweed sargassum filicinum harvey (fucales) in california, usa. Biological Invasions, (9), 609-613.</p>
<p>Wernberg, T. S. et al.&nbsp;Climate-driven regime shift of a temperate marine ecosystem. Science 353, 169–172 (2016).</p>
<p>Zacharias, Mark, and David J. Kushner. 2006. “Sea temperature and wave height as predictors of population size structure and density of Megastraea (Lithopoma) undosa: Implications for fishery management.” Bulletin of Marine Science 79.1: 71-82.</p>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>

 ]]></description>
  <category>R</category>
  <category>Ecology</category>
  <category>Ocean Data</category>
  <category>ENSO</category>
  <guid>https://cullen-molitor.github.io/posts/2021-12-05-species-density-sst-lagsst/</guid>
  <pubDate>Sun, 05 Dec 2021 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2021-12-05-species-density-sst-lagsst/figures/unnamed-chunk-4-1.png" medium="image" type="image/png" height="72" width="144"/>
</item>
<item>
  <title>Modeling ENSO and Wave Height</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/</link>
  <description><![CDATA[ 





<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="https://mybinder.org/v2/gh/mk-waves/mk-waves-tutorial/main"><img src="https://mybinder.org/badge_logo.svg" class="img-fluid figure-img" alt="Binder"></a></p>
<figcaption>Binder</figcaption>
</figure>
</div>
<p>↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑<br>
Click the binder icon above to begin a code along tutorial. A remote python session will launch in your browser with the tutorial Be patient, sometimes it takes a while for the session to initialize the first few times.</p>
<section id="hw3-making-waves-cdip-dataset-tutorial-and-use-case-examples" class="level1">
<h1>HW3 Making Waves: CDIP Dataset Tutorial and Use Case Examples</h1>
<section id="view-and-evaluating-wave-height-and-temperature-from-the-coastal-data-information-program" class="level3">
<h3 class="anchored" data-anchor-id="view-and-evaluating-wave-height-and-temperature-from-the-coastal-data-information-program">View and evaluating wave height and temperature from the Coastal Data Information Program</h3>
</section>
<section id="eds-220-fall-2021" class="level2">
<h2 class="anchored" data-anchor-id="eds-220-fall-2021">EDS 220, Fall 2021</h2>
<section id="authors" class="level4">
<h4 class="anchored" data-anchor-id="authors">Authors</h4>
<p>Cullen Molitor, UC Santa Barbara (<a href="mailto:cullen_molitor@bren.ucsb.edu" class="email">cullen_molitor@bren.ucsb.edu</a>) <a href="https://cullen-molitor.github.io/" class="uri">https://cullen-molitor.github.io/</a><br>
Jake Eisaguirre, UC Santa Barbara (<a href="mailto:eisaguirre@bren.ucsb.edu" class="email">eisaguirre@bren.ucsb.edu</a>) <a href="https://jake-eisaguirre.github.io/" class="uri">https://jake-eisaguirre.github.io/</a><br>
Marie Rivers, UC Santa Barbara (<a href="mailto:mrivers@bren.ucsb.edu" class="email">mrivers@bren.ucsb.edu</a>) <a href="https://marierivers.github.io/" class="uri">https://marierivers.github.io/</a></p>
</section>
</section>
<section id="table-of-contents" class="level2">
<h2 class="anchored" data-anchor-id="table-of-contents">Table of Contents</h2>
<p>1. Purpose</p>
<p>2. Dataset Description</p>
<p>3. Dataset Input/Output</p>
<p>4. Metadata</p>
<p>5. Visualize Data</p>
<p>6. Use Case Examples</p>
<p>7. References</p>
<section id="notebook-purpose" class="level3">
<h3 class="anchored" data-anchor-id="notebook-purpose">Notebook Purpose</h3>
<p>This notebook was created to provide an introduction to NetCDF4 files and data from the <a href="https://cdip.ucsd.edu/">Coastal Data Information Program (CDIP)</a> at the <a href="https://scripps.ucsd.edu/">Scripps Institute of Oceanography (SIO)</a>. This tutorial is based on a <a href="https://cdip.ucsd.edu/m/documents/data_access.html">python API</a> which loads netCDF files. We also provide methods for using sea surface temperature and swell height to compare correlations with El Nino/Southern Oscillation (ENSO) behavior at a specific location.</p>
<p>While these methods are applicable to other <a href="https://cdip.ucsd.edu/m/deployment/station_view/">CDIP wave buoy stations</a>, we chose the <a href="http://cdip.ucsd.edu/themes/?d2=p9:s:71:st:1:m:mobile">Harvest Buoy (CDIP site)</a> to get information close to our local Santa Barbara, CA coast. The metadata is documented on the <a href="https://cdip.ucsd.edu/m/documents/intro.html#">CDIP informational site</a>.</p>
<p>We are also interested to see how the El Niño Southern Oscillation (<a href="https://www.climate.gov/news-features/blogs/enso/what-el-ni%C3%B1o%E2%80%93southern-oscillation-enso-nutshell">ENSO</a>) effects our local waters in Santa Barbara California. To do this, we use the primary measurement of the strength of ENSO, the Oceanic Niño Index, which calculates a <a href="https://origin.cpc.ncep.noaa.gov/products/analysis_monitoring/ensostuff/ONI_change.shtml">monthly anomaly value</a> for <a href="https://www.ncdc.noaa.gov/teleconnections/enso/sst">region 3.4</a> in the equatorial pacific. Region 3.4 was chosen as it is the first zone to indicate ENSO and commonly used in ENSO research.</p>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/harvest.png" width="300"> <img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/buoy.png" width="300"></p>
</section>
<section id="buoy-dataset-description" class="level3">
<h3 class="anchored" data-anchor-id="buoy-dataset-description">Buoy Dataset Description</h3>
<p><strong>File format:</strong> NetCDF<br>
<strong>Data retrieval source:</strong> CDIP portal and CDIP Python API</p>
<p><strong>Operator:</strong> CDIP<br>
<strong>Collaborators:</strong> CleanSeas<br>
<strong>Funding:</strong> California Division of Boating and Waterways (CDBW) &amp; US Army Corps of Engineer (USACE)</p>
<p><strong>Data Availability:</strong> CDIP data and products are free available for public use<br>
<strong>License:</strong> These data may be redistributed and used without restriction</p>
<p><strong>Global coverage of stations:</strong><br>
<img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/all_stations.png" class="img-fluid"></p>
<p><strong>Harvest buoy period of record:</strong> October 1991 - present</p>
<section id="measured-wave-parameters" class="level4">
<h4 class="anchored" data-anchor-id="measured-wave-parameters">Measured wave parameters</h4>
<p>Wave height is measured as the distance between the trough and the crest of a wave. Wave period measurements represent the time between two consecutive crests. Wave direction is the compass angle (0-360 degrees clockwise from true North) that the waves are coming from. Ocean waves never have just a single direction or period. Therefore, measurements of peak period (Tp) and peak direction (Dp) are reported. The peak period is the most common period between consecutive waves, and peak direction is the most common direction.</p>
<ul>
<li>Hs = wave height, 30-minute average of the ⅓ highest waves at a sensor</li>
<li>Tp = peak period (most common period between consecutive waves)</li>
<li>Dp = peak direction (most common direction)</li>
</ul>
<p>CDIP documentation notes that statistical estimates of wave parameters have been developed by analyzing time-series measurements of a natural sea state. For example, significant wave height was designed to correspond to wave height estimates from experienced observer and is reported as the mean of the largest 1/3 (33%) of waves recorded during a sampling period. Ocean conditions constantly change and significant wave heights are statistical measures rather than measures corresponding to any specific wave. A given sampling period will have many waves smaller than Hs and some larger than Hs. Statistically, the largest wave in a 1,000 wave sample is likely to be ~1.8 times the reported significant wave height.</p>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/wave_measurements.png" width="500"></p>
</section>
<section id="equipment" class="level4">
<h4 class="anchored" data-anchor-id="equipment">Equipment</h4>
<p>CDIP uses Waverider (Mark III) directional buoys manufactured by Datawell that are equipped with accelerometers that measure wave height by recording the vertical acceleration of the buoy as it rises and falls with passing waves. Wave direction is recorded by horizontal accelerometers that measure north/south and east/west displacements. These buoys effectively measures waves with periods ranging from 1.6 to 30 seconds, with an error less than 3%. Temperature is measured by these buoys with a sensor is located approximately 18 inches below the watersurface. These buoys have a diameter of 0.9 meters. Available equipment documentation did not provide frequency of measurements.</p>
</section>
<section id="temporal-notes" class="level4">
<h4 class="anchored" data-anchor-id="temporal-notes">Temporal notes</h4>
<ul>
<li>Wave calcs use ~30 minute data samples</li>
<li>Time assigned to the data is start time</li>
<li>All data collected is archived by UTC time</li>
</ul>
</section>
<section id="data-quality" class="level4">
<h4 class="anchored" data-anchor-id="data-quality">Data Quality</h4>
<ul>
<li>high quality publicly released data excludes all records flagged by quality control procedures</li>
<li>activity log documents deployments, transmission problems, maintenance issues, and battery/power failures</li>
</ul>
</section>
</section>
<section id="buoy-dataset-inputoutput" class="level3">
<h3 class="anchored" data-anchor-id="buoy-dataset-inputoutput">Buoy Dataset Input/Output</h3>
<section id="import-required-packages" class="level4">
<h4 class="anchored" data-anchor-id="import-required-packages">Import required packages</h4>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> netCDF4</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb1-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> datetime</span>
<span id="cb1-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> time</span>
<span id="cb1-6"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> calendar</span>
<span id="cb1-7"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb1-8"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> matplotlib <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> gridspec</span>
<span id="cb1-9"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> matplotlib <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> cm</span>
<span id="cb1-10"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> mpl</span></code></pre></div>
</section>
<section id="set-parameters" class="level4">
<h4 class="anchored" data-anchor-id="set-parameters">Set parameters</h4>
<ul>
<li>names of any directories where data are stored</li>
<li>ranges of years over which data are valid</li>
<li>any thresholds or latitude/longitude ranges to be used later (e.g.&nbsp;dimensions of NINO3.4 region, threshold SSTA values for El Nino, etc.)</li>
</ul>
<p>The harvest buoy, CDIP station number of 071, was selected for our regional analysis of the Santa Barbara Coast.</p>
<p><a href="https://cdip.ucsd.edu/m/deployment/station_view/">Link to other buoy stations</a></p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Type</span></span>
<span id="cb2-2">stn <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'071'</span></span></code></pre></div>
</section>
<section id="read-in-the-data" class="level4">
<h4 class="anchored" data-anchor-id="read-in-the-data">Read in the data</h4>
<p>we use the <code>netCDF4</code> module to read in the archived buoy data.</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># CDIP Archived Dataset URL</span></span>
<span id="cb3-2">data_url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'http://thredds.cdip.ucsd.edu/thredds/dodsC/cdip/archive/'</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> stn <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'p1/'</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> stn <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'p1_historic.nc'</span></span></code></pre></div>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> netCDF4.Dataset(data_url)</span></code></pre></div>
</section>
</section>
<section id="metadata" class="level3">
<h3 class="anchored" data-anchor-id="metadata">Metadata</h3>
<p>The CDIP metadata includes general information about the Harvest buoy such as current status, location, instrument description and most recent measurement values. The metadata also includes the availability of parameters for each month that the station has been in operation. The code below further explores metadata associated with this dataset</p>
<p>The <code>type</code> function in Python was used to display the file type of the data</p>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># return the file type</span></span>
<span id="cb5-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">type</span>(data)</span></code></pre></div>
<pre><code>netCDF4._netCDF4.Dataset</code></pre>
<p>The <code>summary</code> Python function was used to display summary text of the data</p>
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># return a summary of the dataset</span></span>
<span id="cb7-2">data.summary</span></code></pre></div>
<pre><code>'Directional wave and sea surface temperature measurements collected in situ by Datawell Waverider buoys located near HARVEST, CA from 1991/10/22 to 2019/06/17. This dataset includes publicly-released data only, excluding all records flagged bad by quality control procedures. A total of 372110 wave samples were analyzed for this area, where the water depth is approximately 183 to 549 meters.'</code></pre>
<p>The command <code>.variables.keys()</code> was used to return all variables included in the dataset.</p>
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># return all variables included in the dataset</span></span>
<span id="cb9-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(data.variables.keys())</span></code></pre></div>
<pre><code>dict_keys(['sourceFilename', 'waveTime', 'waveTimeBounds', 'waveFlagPrimary', 'waveFlagSecondary', 'waveHs', 'waveTp', 'waveTa', 'waveDp', 'wavePeakPSD', 'waveTz', 'waveSourceIndex', 'waveFrequency', 'waveFrequencyBounds', 'waveFrequencyFlagPrimary', 'waveFrequencyFlagSecondary', 'waveBandwidth', 'sstTime', 'sstTimeBounds', 'sstFlagPrimary', 'sstFlagSecondary', 'sstSeaSurfaceTemperature', 'sstSourceIndex', 'sstReferenceTemp', 'gpsTime', 'gpsTimeBounds', 'gpsStatusFlags', 'gpsLatitude', 'gpsLongitude', 'gpsSourceIndex', 'dwrTime', 'dwrTimeBounds', 'dwrSourceIndex', 'dwrBatteryLevel', 'dwrZAccelerometerOffset', 'dwrXAccelerometerOffset', 'dwrYAccelerometerOffset', 'dwrOrientation', 'dwrInclination', 'dwrBatteryWeeksOfLife', 'metaDeployLatitude', 'metaDeployLongitude', 'metaWaterDepth', 'metaDeclination', 'metaStationName', 'metaStationLatitude', 'metaStationLongitude', 'metaPlatform', 'metaInstrumentation', 'metaGridMapping', 'waveEnergyDensity', 'waveMeanDirection', 'waveA1Value', 'waveB1Value', 'waveA2Value', 'waveB2Value', 'waveCheckFactor', 'waveSpread', 'waveM2Value', 'waveN2Value'])</code></pre>
<p>The Harvest buoy collects data in the following categories:</p>
<ul>
<li>Significant Wave Height<br>
</li>
<li>Swell Height</li>
<li>Swell Period</li>
<li>Swell Direction</li>
<li>Wind Wave Height</li>
<li>Wind Wave Period</li>
<li>Wind Wave Direction</li>
<li>Wave Steepness</li>
<li>Average Wave Period</li>
<li>Water Temperature</li>
</ul>
<p>For this tutorial we are interested in:</p>
<ul>
<li>Significant Wave Height (<code>waveHs</code>)</li>
<li>Sea Surface Temperature (<code>sstSeaSurfaceTemperature</code>)</li>
</ul>
<p>By using a print statement with the dataframe name and variable in brackets, you can view the long name, units, minimum values, and maximum values of a variable</p>
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># learn more about a variable including long name, units, valid min/max values</span></span>
<span id="cb11-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(data[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sstSeaSurfaceTemperature'</span>])</span></code></pre></div>
<pre><code>&lt;class 'netCDF4._netCDF4.Variable'&gt;
float32 sstSeaSurfaceTemperature(sstTime)
    long_name: sea surface temperature
    units: Celsius
    _FillValue: -999.99
    standard_name: sea_surface_temperature
    coordinates: metaStationLatitude metaStationLongitude
    grid_mapping: metaGridMapping
    valid_min: -5.0
    valid_max: 46.15
    ancillary_variables: sstFlagPrimary sstFlagSecondary
    ncei_name: SEA SURFACE TEMPERATURE
    cell_methods: sstTime: point
unlimited dimensions: 
current shape = (372015,)
filling off</code></pre>
<div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Other Variables</span></span>
<span id="cb13-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># data.variables</span></span>
<span id="cb13-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Hs = data.variables['waveHs']</span></span>
<span id="cb13-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Tp = data.variables['waveTp']</span></span>
<span id="cb13-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Dp = data.variables['waveDp'] </span></span></code></pre></div>
<section id="clean-data" class="level4">
<h4 class="anchored" data-anchor-id="clean-data">Clean data</h4>
<p>Thanks to the data processing methods used by CDIP, the downloaded datafiles did not require much actual cleaning. Since the sea surface temperature and wave height variables had different timestamps associated with each measurements we pulled out these variables for use in creating new dataframes that were used as an intermediate step in our overall analysis</p>
<p><a href="http://cdip.ucsd.edu/themes/?zoom=auto&amp;tz=UTC&amp;ll_fmt=dm&amp;numcolorbands=100&amp;palette=cdip_classic&amp;high=4.572&amp;r=7&amp;un=1&amp;pb=1&amp;d2=p70&amp;u2=s:071:st:1:v:product_descriptions">Example code found here</a></p>
<div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb14-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Get SST timestamp variable </span></span>
<span id="cb14-2">sst_time_var <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> data.variables[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sstTime'</span>]</span>
<span id="cb14-3"></span>
<span id="cb14-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Get SST variable </span></span>
<span id="cb14-5">sst <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> data.variables[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sstSeaSurfaceTemperature'</span>][:]</span>
<span id="cb14-6"></span>
<span id="cb14-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Get wave height timestamp variable</span></span>
<span id="cb14-8">wave_time_var <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> data.variables[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'waveTime'</span>]</span>
<span id="cb14-9"></span>
<span id="cb14-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Get wave height variable </span></span>
<span id="cb14-11">wave <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> data.variables[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'waveHs'</span>][:]</span></code></pre></div>
<p>We used the cftime Python library for decoding time units and variable values in a netCDF file conforming to the Climate and Forecasting (CF) netCDF conventions.</p>
<p><a href="https://unidata.github.io/cftime/">cftime documentation</a></p>
<p>First we created dataframes for the sea surface temperature <code>sst_df</code> and wave height <code>wave_df</code> data. We then aggregated this data by month and joined the dataframes to create one dataframe of buoy variables.</p>
<div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Use num2date on sst_time_var</span></span>
<span id="cb15-2">sst_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> netCDF4.num2date(sst_time_var[:], sst_time_var.units, only_use_cftime_datetimes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span></code></pre></div>
<div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Make an empty pandas dataframe</span></span>
<span id="cb16-2">sst_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame()</span>
<span id="cb16-3"></span>
<span id="cb16-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fill it with SST and the date time it was collected</span></span>
<span id="cb16-5">sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sst'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sst</span>
<span id="cb16-6">sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sst_time</span></code></pre></div>
<p>The code below creates columns for the date, month, and year of each observation timestamp. These values will later be used to calculate monthly means.</p>
<div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Make date_time column a pandas date_time</span></span>
<span id="cb17-2">sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_datetime(sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>]) </span>
<span id="cb17-3"></span>
<span id="cb17-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pull out date from datetime</span></span>
<span id="cb17-5">sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>].dt.date</span>
<span id="cb17-6"></span>
<span id="cb17-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pull out month from datetime</span></span>
<span id="cb17-8">sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'month'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>].dt.month</span>
<span id="cb17-9"></span>
<span id="cb17-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pull out year from datetime</span></span>
<span id="cb17-11">sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>].dt.year</span></code></pre></div>
<div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb18-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Use num2date on wave_time_var</span></span>
<span id="cb18-2">wave_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> netCDF4.num2date(wave_time_var[:], wave_time_var.units, only_use_cftime_datetimes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span></code></pre></div>
<div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Make an empty pandas dataframe</span></span>
<span id="cb19-2">wave_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame()</span>
<span id="cb19-3"></span>
<span id="cb19-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fill it with SST and the date time it was collected</span></span>
<span id="cb19-5">wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'wave'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> wave</span>
<span id="cb19-6">wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> wave_time</span></code></pre></div>
<div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb20-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Make date_time column a pandas date_time</span></span>
<span id="cb20-2">wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_datetime(wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>]) </span>
<span id="cb20-3"></span>
<span id="cb20-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pull out date from datetime</span></span>
<span id="cb20-5">wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>].dt.date</span>
<span id="cb20-6"></span>
<span id="cb20-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pull out month from datetime</span></span>
<span id="cb20-8">wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'month'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>].dt.month</span>
<span id="cb20-9"></span>
<span id="cb20-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pull out year from datetime</span></span>
<span id="cb20-11">wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date_time'</span>].dt.year</span></code></pre></div>
<p>The next two code chunks let you view the newly created sea surface temperature and wave height dataframes</p>
<div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb21-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect data</span></span>
<span id="cb21-2">sst_df.head()</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">sst</th>
<th style="text-align: left;">date_time</th>
<th style="text-align: left;">date</th>
<th style="text-align: left;">month</th>
<th style="text-align: left;">year</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">16.00</td>
<td style="text-align: left;">1991-10-22 08:21:00</td>
<td style="text-align: left;">1991-10-22</td>
<td style="text-align: left;">10</td>
<td style="text-align: left;">1991</td>
</tr>
<tr class="even">
<td>1</td>
<td style="text-align: left;">16.00</td>
<td style="text-align: left;">1991-10-22 08:51:00</td>
<td style="text-align: left;">1991-10-22</td>
<td style="text-align: left;">10</td>
<td style="text-align: left;">1991</td>
</tr>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">15.90</td>
<td style="text-align: left;">1991-10-22 09:21:00</td>
<td style="text-align: left;">1991-10-22</td>
<td style="text-align: left;">10</td>
<td style="text-align: left;">1991</td>
</tr>
<tr class="even">
<td>3</td>
<td style="text-align: left;">15.90</td>
<td style="text-align: left;">1991-10-22 09:51:00</td>
<td style="text-align: left;">1991-10-22</td>
<td style="text-align: left;">10</td>
<td style="text-align: left;">1991</td>
</tr>
<tr class="odd">
<td>4</td>
<td style="text-align: left;">15.85</td>
<td style="text-align: left;">1991-10-22 10:21:00</td>
<td style="text-align: left;">1991-10-22</td>
<td style="text-align: left;">10</td>
<td style="text-align: left;">1991</td>
</tr>
</tbody>
</table>
<div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb22-1">wave_df.head()</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">wave</th>
<th style="text-align: left;">date_time</th>
<th style="text-align: left;">date</th>
<th style="text-align: left;">month</th>
<th style="text-align: left;">year</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">1.50</td>
<td style="text-align: left;">1991-10-22 07:52:00</td>
<td style="text-align: left;">1991-10-22</td>
<td style="text-align: left;">10</td>
<td style="text-align: left;">1991</td>
</tr>
<tr class="even">
<td>1</td>
<td style="text-align: left;">1.48</td>
<td style="text-align: left;">1991-10-22 08:22:00</td>
<td style="text-align: left;">1991-10-22</td>
<td style="text-align: left;">10</td>
<td style="text-align: left;">1991</td>
</tr>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">1.54</td>
<td style="text-align: left;">1991-10-22 08:52:00</td>
<td style="text-align: left;">1991-10-22</td>
<td style="text-align: left;">10</td>
<td style="text-align: left;">1991</td>
</tr>
<tr class="even">
<td>3</td>
<td style="text-align: left;">1.56</td>
<td style="text-align: left;">1991-10-22 09:22:00</td>
<td style="text-align: left;">1991-10-22</td>
<td style="text-align: left;">10</td>
<td style="text-align: left;">1991</td>
</tr>
<tr class="odd">
<td>4</td>
<td style="text-align: left;">1.59</td>
<td style="text-align: left;">1991-10-22 09:52:00</td>
<td style="text-align: left;">1991-10-22</td>
<td style="text-align: left;">10</td>
<td style="text-align: left;">1991</td>
</tr>
</tbody>
</table>
</section>
</section>
<section id="enso-dataset" class="level3">
<h3 class="anchored" data-anchor-id="enso-dataset">ENSO Dataset</h3>
<p>El Nino/Southern Oscillation (ENSO) data was obtained from the National Oceanic and Atmospheric Administration (NOAA) Climate Prediction Center. The code below goes through the steps to download and visualize this data then manipulate it to use in conjunction with the buoy dataset. We used Nino Region 3.4 for our analysis.</p>
<section id="read-in-enso-data" class="level4">
<h4 class="anchored" data-anchor-id="read-in-enso-data">Read in <a href="https://www.cpc.ncep.noaa.gov/data/indices/ersst5.nino.mth.91-20.ascii">ENSO</a> data</h4>
<p><a href="https://psl.noaa.gov/data/gridded/data.noaa.ersst.v5.html">ERSST5</a> Extended Reconstructed Sea Surface Temperature (SST) V5<br>
<a href="https://www.ncdc.noaa.gov/teleconnections/enso/sst">Nino Regions</a></p>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/nino-regions.gif" width="500"></p>
<p>We use <code>sep = '\s{2,}'</code> because the data linked above is seperated by two or more spaces, not a comma or other typical delimiter.</p>
<div class="sourceCode" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb23-1">path <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.cpc.ncep.noaa.gov/data/indices/ersst5.nino.mth.91-20.ascii"</span></span>
<span id="cb23-2">enso <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.read_csv(path, sep <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'\s{2,}'</span>, engine <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'python'</span>)</span>
<span id="cb23-3">enso.head()</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">YR</th>
<th style="text-align: left;">MON</th>
<th style="text-align: left;">NINO1+2</th>
<th style="text-align: left;">ANOM</th>
<th style="text-align: left;">NINO3</th>
<th style="text-align: left;">ANOM.1</th>
<th style="text-align: left;">NINO4</th>
<th style="text-align: left;">ANOM.2</th>
<th style="text-align: left;">NINO3.4</th>
<th style="text-align: left;">ANOM.3</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">1950</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">23.01</td>
<td style="text-align: left;">-1.55</td>
<td style="text-align: left;">23.56</td>
<td style="text-align: left;">-2.10</td>
<td style="text-align: left;">26.94</td>
<td style="text-align: left;">-1.38</td>
<td style="text-align: left;">24.55</td>
<td style="text-align: left;">-1.99</td>
</tr>
<tr class="even">
<td>1</td>
<td style="text-align: left;">1950</td>
<td style="text-align: left;">2</td>
<td style="text-align: left;">24.32</td>
<td style="text-align: left;">-1.78</td>
<td style="text-align: left;">24.89</td>
<td style="text-align: left;">-1.52</td>
<td style="text-align: left;">26.67</td>
<td style="text-align: left;">-1.53</td>
<td style="text-align: left;">25.06</td>
<td style="text-align: left;">-1.69</td>
</tr>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">1950</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">25.11</td>
<td style="text-align: left;">-1.38</td>
<td style="text-align: left;">26.36</td>
<td style="text-align: left;">-0.84</td>
<td style="text-align: left;">26.52</td>
<td style="text-align: left;">-1.80</td>
<td style="text-align: left;">25.87</td>
<td style="text-align: left;">-1.42</td>
</tr>
<tr class="even">
<td>3</td>
<td style="text-align: left;">1950</td>
<td style="text-align: left;">4</td>
<td style="text-align: left;">23.63</td>
<td style="text-align: left;">-1.90</td>
<td style="text-align: left;">26.44</td>
<td style="text-align: left;">-1.14</td>
<td style="text-align: left;">26.90</td>
<td style="text-align: left;">-1.73</td>
<td style="text-align: left;">26.28</td>
<td style="text-align: left;">-1.54</td>
</tr>
<tr class="odd">
<td>4</td>
<td style="text-align: left;">1950</td>
<td style="text-align: left;">5</td>
<td style="text-align: left;">22.68</td>
<td style="text-align: left;">-1.74</td>
<td style="text-align: left;">25.69</td>
<td style="text-align: left;">-1.57</td>
<td style="text-align: left;">27.73</td>
<td style="text-align: left;">-1.18</td>
<td style="text-align: left;">26.18</td>
<td style="text-align: left;">-1.75</td>
</tr>
</tbody>
</table>
<div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb24-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># drop unused columns from ENSO data</span></span>
<span id="cb24-2">enso <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> enso.drop(enso.columns[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>]], axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb24-3"></span>
<span id="cb24-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># rename columns</span></span>
<span id="cb24-5">enso <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> enso.rename(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"YR"</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MON"</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"month"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ANOM.3"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"enso_anom"</span>})</span>
<span id="cb24-6">enso.head()</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">year</th>
<th style="text-align: left;">month</th>
<th style="text-align: left;">enso_anom</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">1950</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">-1.99</td>
</tr>
<tr class="even">
<td>1</td>
<td style="text-align: left;">1950</td>
<td style="text-align: left;">2</td>
<td style="text-align: left;">-1.69</td>
</tr>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">1950</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">-1.42</td>
</tr>
<tr class="even">
<td>3</td>
<td style="text-align: left;">1950</td>
<td style="text-align: left;">4</td>
<td style="text-align: left;">-1.54</td>
</tr>
<tr class="odd">
<td>4</td>
<td style="text-align: left;">1950</td>
<td style="text-align: left;">5</td>
<td style="text-align: left;">-1.75</td>
</tr>
</tbody>
</table>
</section>
</section>
<section id="visualize-data" class="level3">
<h3 class="anchored" data-anchor-id="visualize-data">Visualize data</h3>
<section id="harvet-buoy-visualization" class="level4">
<h4 class="anchored" data-anchor-id="harvet-buoy-visualization">Harvet buoy visualization</h4>
<p>We started by visualizing the full dataset to inform our further analysis. Based on the data gaps shown in the plot, we decided to begin our analysis at 1997.</p>
<div class="sourceCode" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb25-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot here to see what the data looks like</span></span>
<span id="cb25-2">f, (pHs, pSst) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, sharex<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) </span>
<span id="cb25-3">pSst.plot(sst_df.date, sst_df.sst, linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>)</span>
<span id="cb25-4">pHs.plot(wave_df.date, wave_df.wave, linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>)</span>
<span id="cb25-5">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Harvest Buoy"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.3</span>)</span>
<span id="cb25-6">pHs.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Wave Height, m'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>)</span>
<span id="cb25-7">pSst.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'SST, C'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>)</span></code></pre></div>
<pre><code>Text(0, 0.5, 'SST, C')</code></pre>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/output_47_1.png" class="img-fluid figure-img"></p>
<figcaption>png</figcaption>
</figure>
</div>
</section>
<section id="enso-anomaly-visualization" class="level4">
<h4 class="anchored" data-anchor-id="enso-anomaly-visualization">ENSO anomaly visualization</h4>
<p>The below plot shows the Oceanic Nino Index anaomaly vvalues from 1950 to the most current available data. The area under/over the curve to the x-axis is colored by the intensity of the anomaly. Anomaly values over 0.5°C for 5 consecutive 3 month seasonal averages are considered to be El Niño. Anomaly values under -0.5°C for 5 consecutive 3 month seasonal averages are considered to be La Niña.</p>
<p>Next we <code>assign()</code> an arbitrary day value of 1 in order to make a date with <code>pd.to_datetime()</code> function</p>
<div class="sourceCode" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb27-1">enso <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> enso.assign(day <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb27-2">enso[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_datetime(enso[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'month'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'day'</span>]])</span></code></pre></div>
<div class="sourceCode" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb28-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Choose color gradient here: https://matplotlib.org/stable/tutorials/colors/colormaps.html </span></span>
<span id="cb28-2"></span>
<span id="cb28-3">colourmap <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> cm.get_cmap(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'magma'</span>)</span>
<span id="cb28-4"></span>
<span id="cb28-5">xx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> enso.date</span>
<span id="cb28-6">yy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  enso.enso_anom</span>
<span id="cb28-7"></span>
<span id="cb28-8">plt.figure(figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb28-9">plt.plot(xx,yy, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>)</span>
<span id="cb28-10"></span>
<span id="cb28-11">normalize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mpl.colors.Normalize(vmin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yy.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>(), vmax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>yy.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>())</span>
<span id="cb28-12">npts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(enso)</span>
<span id="cb28-13"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(npts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>):</span>
<span id="cb28-14">    plt.fill_between([xx[i], xx[i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]],</span>
<span id="cb28-15">                     [yy[i], yy[i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]],</span>
<span id="cb28-16">                     color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>colourmap(normalize(yy[i]))</span>
<span id="cb28-17">                     ,alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>)</span>
<span id="cb28-18">plt.show()</span></code></pre></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/output_51_0.png" class="img-fluid figure-img"></p>
<figcaption>png</figcaption>
</figure>
</div>
</section>
</section>
<section id="use-cases-examples" class="level3">
<h3 class="anchored" data-anchor-id="use-cases-examples">Use Cases Examples</h3>
<p><strong>Observational Data vs Modeled Data</strong></p>
<p>The CDIP buoy network is a valuable resource for marine scientists, coastal managers, and mariners. The <strong>historic data</strong> (observational) is archived and is of great use for understanding past patterns and provides context for understanding the oceanographic conditions of our local ocean. <strong>Real time data</strong> (observational) gives an better idea of what to expect as wave energy moves past the buoy and towards our shoreline. It is also incredibly useful for mariners navigating these sometimes harsh and volatile waters. Forecasted data (modeled) is perhaps the most practical use case for mariners, as they not only need to know the current conditions but they need to know how those conditions are changing in order to navigate safely.</p>
<p>CDIP provide what they call <a href="https://cdip.ucsd.edu/m/documents/models.html#about-the-cdip-wave-forecast-model">‘nowcasted’ data and ‘forecasted’ data</a>. - Nowcasted provides insight at a higher resolution for the upcoming 6-hour period. These predictions tend to be more accurate and are generally fairly trustworthy. - Forecasted data provide a look further into the future, but with a greater amount of uncertainty</p>
<p><strong>Our interest</strong></p>
<p>We are interested in investigating the effect of El Niño on our local oceanographic conditions. We used linear regression models to plot and compare equatorial sea surface temperature anomalies with local Santa Barbara temperature and wave height. Typically temperature anomalies are calculated from a 30 year base period. Since we only had ~20 years of consistent data, we calculated monthly means since 1997 and used these as base values from which to compare monthly means for each year. The results of this analysis are useful to scientist, marine managers, marine conservation groups and coastal communities.</p>
<p><strong>Other General Use Cases</strong></p>
<ul>
<li>Modeling coastal erosion</li>
<li>Investigating storm frequency and intensity over time</li>
<li>Investigating changes in SST over time</li>
<li>Detecting upwelling events</li>
</ul>
<p>The code chunks below take the sea surface temperature and wave height dataframes created from the buoy data and group values by month and year so that monthly averages can be calculated. The two datasets are then grouped into a single buoy dataframe, <code>buoy_df</code>.</p>
<div class="sourceCode" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb29-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Filter data to be greater than 1997 due to missing values before that time</span></span>
<span id="cb29-2">sst_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sst_df[sst_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1997</span>]</span>
<span id="cb29-3"></span>
<span id="cb29-4">wave_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> wave_df[wave_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1997</span>]</span></code></pre></div>
<div class="sourceCode" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb30-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Group by date and summarise with mean SST and Wave Height</span></span>
<span id="cb30-2">sst_monthly <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sst_df.groupby([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'month'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>]).agg({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sst'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mean'</span>})</span>
<span id="cb30-3"></span>
<span id="cb30-4">wave_monthly <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> wave_df.groupby([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'month'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>]).agg({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'wave'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mean'</span>})</span></code></pre></div>
<div class="sourceCode" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb31-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect Data</span></span>
<span id="cb31-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(sst_monthly.head())</span>
<span id="cb31-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(wave_monthly.head())</span></code></pre></div>
<pre><code>                  sst
month year           
1     1999  13.194914
      2000  13.023686
      2001  13.454234
      2002  12.896236
      2003  14.313378
                wave
month year          
1     1999  2.467315
      2000  2.126410
      2001  2.971848
      2002  2.609128
      2003  2.432630</code></pre>
<div class="sourceCode" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb33-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># join monthly sst and wave data into a buoy dataframe</span></span>
<span id="cb33-2">buoy_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sst_monthly.join(wave_monthly)</span>
<span id="cb33-3">buoy_df.head()</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th></th>
<th style="text-align: left;">sst</th>
<th style="text-align: left;">wave</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>month</td>
<td>year</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<td>1</td>
<td>1999</td>
<td style="text-align: left;">13.194914</td>
<td style="text-align: left;">2.467315</td>
</tr>
<tr class="odd">
<td></td>
<td>2000</td>
<td style="text-align: left;">13.023686</td>
<td style="text-align: left;">2.126410</td>
</tr>
<tr class="even">
<td></td>
<td>2001</td>
<td style="text-align: left;">13.454234</td>
<td style="text-align: left;">2.971848</td>
</tr>
<tr class="odd">
<td></td>
<td>2002</td>
<td style="text-align: left;">12.896236</td>
<td style="text-align: left;">2.609128</td>
</tr>
<tr class="even">
<td></td>
<td>2003</td>
<td style="text-align: left;">14.313378</td>
<td style="text-align: left;">2.432630</td>
</tr>
</tbody>
</table>
<p>Next we used <code>reset_index</code> to ungroup the buoy data</p>
<div class="sourceCode" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb34-1">buoy_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> buoy_df.reset_index()</span>
<span id="cb34-2">buoy_df.head()</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">month</th>
<th style="text-align: left;">year</th>
<th style="text-align: left;">sst</th>
<th style="text-align: left;">wave</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">1999</td>
<td style="text-align: left;">13.194914</td>
<td style="text-align: left;">2.467315</td>
</tr>
<tr class="even">
<td>1</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">2000</td>
<td style="text-align: left;">13.023686</td>
<td style="text-align: left;">2.126410</td>
</tr>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">2001</td>
<td style="text-align: left;">13.454234</td>
<td style="text-align: left;">2.971848</td>
</tr>
<tr class="even">
<td>3</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">2002</td>
<td style="text-align: left;">12.896236</td>
<td style="text-align: left;">2.609128</td>
</tr>
<tr class="odd">
<td>4</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">2003</td>
<td style="text-align: left;">14.313378</td>
<td style="text-align: left;">2.432630</td>
</tr>
</tbody>
</table>
<p>Here we calculate anomalies for buoy sea surface temperature and wave height values.</p>
<div class="sourceCode" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb35-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># calculate the anomalies</span></span>
<span id="cb35-2">buoy_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> buoy_df.groupby([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'month'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>]).agg({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sst'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mean'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'wave'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mean'</span>}) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb35-3">    buoy_df.groupby([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'month'</span>]).agg({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sst'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mean'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'wave'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mean'</span>}) </span>
<span id="cb35-4">buoy_df.head()</span>
<span id="cb35-5"></span>
<span id="cb35-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># since this line of code was so long, use used a `\` to break up the line. You can also split up lines at commas</span></span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th></th>
<th style="text-align: left;">sst</th>
<th style="text-align: left;">wave</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>month</td>
<td>year</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<td>1</td>
<td>1999</td>
<td style="text-align: left;">-0.458099</td>
<td style="text-align: left;">-0.088380</td>
</tr>
<tr class="odd">
<td></td>
<td>2000</td>
<td style="text-align: left;">-0.629327</td>
<td style="text-align: left;">-0.429286</td>
</tr>
<tr class="even">
<td></td>
<td>2001</td>
<td style="text-align: left;">-0.198779</td>
<td style="text-align: left;">0.416153</td>
</tr>
<tr class="odd">
<td></td>
<td>2002</td>
<td style="text-align: left;">-0.756777</td>
<td style="text-align: left;">0.053433</td>
</tr>
<tr class="even">
<td></td>
<td>2003</td>
<td style="text-align: left;">0.660365</td>
<td style="text-align: left;">-0.123065</td>
</tr>
</tbody>
</table>
<p>Note: You need to reset the index each time you group the data</p>
<div class="sourceCode" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb36-1">buoy_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> buoy_df.reset_index()</span>
<span id="cb36-2">buoy_df.head()</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">month</th>
<th style="text-align: left;">year</th>
<th style="text-align: left;">sst</th>
<th style="text-align: left;">wave</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">1999</td>
<td style="text-align: left;">-0.458099</td>
<td style="text-align: left;">-0.088380</td>
</tr>
<tr class="even">
<td>1</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">2000</td>
<td style="text-align: left;">-0.629327</td>
<td style="text-align: left;">-0.429286</td>
</tr>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">2001</td>
<td style="text-align: left;">-0.198779</td>
<td style="text-align: left;">0.416153</td>
</tr>
<tr class="even">
<td>3</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">2002</td>
<td style="text-align: left;">-0.756777</td>
<td style="text-align: left;">0.053433</td>
</tr>
<tr class="odd">
<td>4</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">2003</td>
<td style="text-align: left;">0.660365</td>
<td style="text-align: left;">-0.123065</td>
</tr>
</tbody>
</table>
<div class="sourceCode" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb37-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># rename columns</span></span>
<span id="cb37-2">buoy_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> buoy_df.rename(columns <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'sst'</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'buoy_sst_anom'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'wave'</span>:<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'buoy_wave_anom'</span>})</span>
<span id="cb37-3"></span>
<span id="cb37-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Assign arbitrary day value</span></span>
<span id="cb37-5">buoy_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> buoy_df.assign(day <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) </span>
<span id="cb37-6"></span>
<span id="cb37-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># set datetime </span></span>
<span id="cb37-8">buoy_df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_datetime(buoy_df[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'year'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'month'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'day'</span>]])</span>
<span id="cb37-9"></span>
<span id="cb37-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># sort values</span></span>
<span id="cb37-11">buoy_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> buoy_df.sort_values(by<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>])</span>
<span id="cb37-12"></span>
<span id="cb37-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># set the index for plotting</span></span>
<span id="cb37-14">buoy_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> buoy_df.set_index(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>)</span></code></pre></div>
<div class="sourceCode" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb38-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect</span></span>
<span id="cb38-2">buoy_df.head()</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">month</th>
<th style="text-align: left;">year</th>
<th style="text-align: left;">buoy_sst_anom</th>
<th style="text-align: left;">buoy_wave_anom</th>
<th style="text-align: left;">day</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>date</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<td>1998-03-01</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">1998</td>
<td style="text-align: left;">1.834283</td>
<td style="text-align: left;">0.105816</td>
<td style="text-align: left;">1</td>
</tr>
<tr class="odd">
<td>1998-04-01</td>
<td style="text-align: left;">4</td>
<td style="text-align: left;">1998</td>
<td style="text-align: left;">0.914924</td>
<td style="text-align: left;">-0.130027</td>
<td style="text-align: left;">1</td>
</tr>
<tr class="even">
<td>1998-05-01</td>
<td style="text-align: left;">5</td>
<td style="text-align: left;">1998</td>
<td style="text-align: left;">0.674051</td>
<td style="text-align: left;">-0.090042</td>
<td style="text-align: left;">1</td>
</tr>
<tr class="odd">
<td>1998-06-01</td>
<td style="text-align: left;">6</td>
<td style="text-align: left;">1998</td>
<td style="text-align: left;">0.614153</td>
<td style="text-align: left;">-0.300137</td>
<td style="text-align: left;">1</td>
</tr>
<tr class="even">
<td>1998-07-01</td>
<td style="text-align: left;">7</td>
<td style="text-align: left;">1998</td>
<td style="text-align: left;">1.214789</td>
<td style="text-align: left;">0.132242</td>
<td style="text-align: left;">1</td>
</tr>
</tbody>
</table>
<p><strong>Joining enso and buoy data:</strong> Here we join the buoy dataframe and ENSO dataframe by <code>date</code> and create a basic plot of each anomaly.</p>
<div class="sourceCode" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb39-1">buoy_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> buoy_df.drop([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"month"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"day"</span>], axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>).reset_index()</span>
<span id="cb39-2">enso <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> enso.drop([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"month"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"day"</span>], axis <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div>
<div class="sourceCode" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb40-1">anom_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> buoy_df.set_index(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>).join(enso.set_index(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'date'</span>)).reset_index()</span></code></pre></div>
<div class="sourceCode" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb41-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot sst and wave height anomaly from buoy along with ENSO sst anomaly</span></span>
<span id="cb41-2">f, (bwa, bsa, esa ) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, sharex<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb41-3"></span>
<span id="cb41-4">bwa.plot(anom_df.date, anom_df.buoy_wave_anom)</span>
<span id="cb41-5">bwa.fill_between(anom_df.date, anom_df.buoy_wave_anom, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.30</span>)</span>
<span id="cb41-6">bwa.axhline(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb41-7">bwa.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Buoy Wave Height Anomaly'</span>)</span>
<span id="cb41-8"></span>
<span id="cb41-9">bsa.plot(anom_df.date, anom_df.buoy_sst_anom)</span>
<span id="cb41-10">bsa.fill_between(anom_df.date, anom_df.buoy_sst_anom,  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.30</span>)</span>
<span id="cb41-11">bsa.axhline(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb41-12">bsa.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Buoy SST Anomaly'</span>)</span>
<span id="cb41-13"></span>
<span id="cb41-14">esa.plot(anom_df.date, anom_df.enso_anom)</span>
<span id="cb41-15">esa.fill_between(anom_df.date, anom_df.enso_anom,  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.30</span>)</span>
<span id="cb41-16">esa.axhline(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb41-17">esa.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ENSO Anomaly'</span>)</span></code></pre></div>
<pre><code>Text(0, 0.5, 'ENSO Anomaly')</code></pre>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/output_70_1.png" class="img-fluid figure-img"></p>
<figcaption>png</figcaption>
</figure>
</div>
<section id="model" class="level4">
<h4 class="anchored" data-anchor-id="model">Model</h4>
<p>We used the <code>statsmodels</code> package to develop linear regression models of the anomaly dataframes created in the sections above. We modeled anomalies for buoy sea surface temperature vs.&nbsp;ENSO sea surface temperature, buoy wave height vs.&nbsp;ENSO sea surface temperature, and buoy wave height vs.&nbsp;buoy sea surface temperature.</p>
<div class="sourceCode" id="cb43" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb43-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> statsmodels.api <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> sm</span></code></pre></div>
<p><strong>Buoy sea surface tempurature anomaly vs.&nbsp;ENSO sea surface temperature anomaly</strong></p>
<div class="sourceCode" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb44-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simple linear model: buoy sst anomaly vs enso sst anomaly</span></span>
<span id="cb44-2">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.OLS(anom_df.buoy_sst_anom, anom_df.enso_anom)</span>
<span id="cb44-3"></span>
<span id="cb44-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Model results</span></span>
<span id="cb44-5">results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.fit()</span>
<span id="cb44-6"></span>
<span id="cb44-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Model summary</span></span>
<span id="cb44-8"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(results.summary())</span></code></pre></div>
<pre><code>                                 OLS Regression Results                                
=======================================================================================
Dep. Variable:          buoy_sst_anom   R-squared (uncentered):                   0.282
Model:                            OLS   Adj. R-squared (uncentered):              0.279
Method:                 Least Squares   F-statistic:                              98.58
Date:                Tue, 07 Dec 2021   Prob (F-statistic):                    8.24e-20
Time:                        18:09:44   Log-Likelihood:                         -312.83
No. Observations:                 252   AIC:                                      627.7
Df Residuals:                     251   BIC:                                      631.2
Df Model:                           1                                                  
Covariance Type:            nonrobust                                                  
==============================================================================
                 coef    std err          t      P&gt;|t|      [0.025      0.975]
------------------------------------------------------------------------------
enso_anom      0.5964      0.060      9.929      0.000       0.478       0.715
==============================================================================
Omnibus:                       11.182   Durbin-Watson:                   0.808
Prob(Omnibus):                  0.004   Jarque-Bera (JB):               12.718
Skew:                           0.402   Prob(JB):                      0.00173
Kurtosis:                       3.751   Cond. No.                         1.00
==============================================================================

Notes:
[1] R² is computed without centering (uncentered) since the model does not contain a constant.
[2] Standard Errors assume that the covariance matrix of the errors is correctly specified.</code></pre>
<p><strong>Buoy wave height anomaly vs.&nbsp;ENSO sea surface temperature anomaly</strong></p>
<div class="sourceCode" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb46-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simple linear model: buoy wave anomaly vs enso sst anomaly</span></span>
<span id="cb46-2">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.OLS(anom_df.buoy_wave_anom, anom_df.enso_anom)</span>
<span id="cb46-3"></span>
<span id="cb46-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Model results</span></span>
<span id="cb46-5">results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.fit()</span>
<span id="cb46-6"></span>
<span id="cb46-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Model summary</span></span>
<span id="cb46-8"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(results.summary())</span></code></pre></div>
<pre><code>                                 OLS Regression Results                                
=======================================================================================
Dep. Variable:         buoy_wave_anom   R-squared (uncentered):                   0.000
Model:                            OLS   Adj. R-squared (uncentered):             -0.004
Method:                 Least Squares   F-statistic:                           0.006389
Date:                Tue, 07 Dec 2021   Prob (F-statistic):                       0.936
Time:                        18:09:44   Log-Likelihood:                         -11.128
No. Observations:                 252   AIC:                                      24.26
Df Residuals:                     251   BIC:                                      27.79
Df Model:                           1                                                  
Covariance Type:            nonrobust                                                  
==============================================================================
                 coef    std err          t      P&gt;|t|      [0.025      0.975]
------------------------------------------------------------------------------
enso_anom      0.0015      0.018      0.080      0.936      -0.034       0.037
==============================================================================
Omnibus:                        1.416   Durbin-Watson:                   1.619
Prob(Omnibus):                  0.493   Jarque-Bera (JB):                1.162
Skew:                           0.011   Prob(JB):                        0.559
Kurtosis:                       3.332   Cond. No.                         1.00
==============================================================================

Notes:
[1] R² is computed without centering (uncentered) since the model does not contain a constant.
[2] Standard Errors assume that the covariance matrix of the errors is correctly specified.</code></pre>
<p><strong>Buoy wave height anomaly vs.&nbsp;buoy sea surface temperature anomaly</strong></p>
<div class="sourceCode" id="cb48" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb48-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simple linear model: buoy wave anomaly vs buoy sst anomaly</span></span>
<span id="cb48-2">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.OLS(anom_df.buoy_wave_anom, anom_df.buoy_sst_anom)</span>
<span id="cb48-3"></span>
<span id="cb48-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Model results</span></span>
<span id="cb48-5">results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.fit()</span>
<span id="cb48-6"></span>
<span id="cb48-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Model summary</span></span>
<span id="cb48-8"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(results.summary())</span></code></pre></div>
<pre><code>                                 OLS Regression Results                                
=======================================================================================
Dep. Variable:         buoy_wave_anom   R-squared (uncentered):                   0.035
Model:                            OLS   Adj. R-squared (uncentered):              0.031
Method:                 Least Squares   F-statistic:                              9.167
Date:                Tue, 07 Dec 2021   Prob (F-statistic):                     0.00272
Time:                        18:09:44   Log-Likelihood:                         -6.6118
No. Observations:                 252   AIC:                                      15.22
Df Residuals:                     251   BIC:                                      18.75
Df Model:                           1                                                  
Covariance Type:            nonrobust                                                  
=================================================================================
                    coef    std err          t      P&gt;|t|      [0.025      0.975]
---------------------------------------------------------------------------------
buoy_sst_anom    -0.0480      0.016     -3.028      0.003      -0.079      -0.017
==============================================================================
Omnibus:                        2.296   Durbin-Watson:                   1.645
Prob(Omnibus):                  0.317   Jarque-Bera (JB):                2.133
Skew:                           0.093   Prob(JB):                        0.344
Kurtosis:                       3.410   Cond. No.                         1.00
==============================================================================

Notes:
[1] R² is computed without centering (uncentered) since the model does not contain a constant.
[2] Standard Errors assume that the covariance matrix of the errors is correctly specified.</code></pre>
<p><strong>Visualize model results</strong></p>
<div class="sourceCode" id="cb50" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb50-1">m, b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.polyfit(anom_df.enso_anom, anom_df.buoy_sst_anom, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb50-2">plt.figure(figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb50-3">plt.scatter(anom_df.enso_anom, anom_df.buoy_sst_anom)</span>
<span id="cb50-4">plt.plot(anom_df.enso_anom, m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> anom_df.enso_anom <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> b, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb50-5">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Buoy SST Anomaly ~ ENSO SST Anomaly'</span>)</span>
<span id="cb50-6">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Buoy SST Anomaly'</span>)</span>
<span id="cb50-7">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ENSO SST Anomaly'</span>)</span></code></pre></div>
<pre><code>Text(0.5, 0, 'ENSO SST Anomaly')</code></pre>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/output_81_1.png" class="img-fluid figure-img"></p>
<figcaption>png</figcaption>
</figure>
</div>
<div class="sourceCode" id="cb52" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb52-1">m, b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.polyfit(anom_df.enso_anom, anom_df.buoy_wave_anom, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb52-2">plt.figure(figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb52-3">plt.scatter(anom_df.enso_anom, anom_df.buoy_wave_anom)</span>
<span id="cb52-4">plt.plot(anom_df.enso_anom, m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> anom_df.enso_anom <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> b, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb52-5">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Buoy Wave Anomaly ~ ENSO SST Anomaly'</span>)</span>
<span id="cb52-6">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Buoy Wave Anomaly'</span>)</span>
<span id="cb52-7">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ENSO SST Anomaly'</span>)</span></code></pre></div>
<pre><code>Text(0.5, 0, 'ENSO SST Anomaly')</code></pre>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/output_82_1.png" class="img-fluid figure-img"></p>
<figcaption>png</figcaption>
</figure>
</div>
<div class="sourceCode" id="cb54" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb54-1">m, b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.polyfit(anom_df.buoy_sst_anom, anom_df.buoy_wave_anom, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb54-2">plt.figure(figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb54-3">plt.scatter(anom_df.buoy_sst_anom, anom_df.buoy_wave_anom)</span>
<span id="cb54-4">plt.plot(anom_df.buoy_sst_anom, m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> anom_df.buoy_sst_anom <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> b, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb54-5">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Buoy Wave Anomaly ~ Buoy SST Anomaly'</span>)</span>
<span id="cb54-6">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Buoy Wave Anomaly'</span>)</span>
<span id="cb54-7">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Buoy SST Anomaly'</span>)</span></code></pre></div>
<pre><code>Text(0.5, 0, 'Buoy SST Anomaly')</code></pre>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/output_83_1.png" class="img-fluid figure-img"></p>
<figcaption>png</figcaption>
</figure>
</div>
</section>
<section id="results" class="level4">
<h4 class="anchored" data-anchor-id="results">Results</h4>
<p>Our model shows a positive correlation between ENSO sea surface temperature anomaly and Santa Barbara sea surface temperature anomaly. The model output indicates that this correlation is statistically significant based on the p-value, but the low \(R^2\) value of 0.282 estimates that temperature near the equator only accounts for approximately 28% of the variability in sea surface temperature near Santa Barbara.Buoy height wave anomaly only has a slight positive correlation with ENSO sea surface temperature anomaly, but these results were not statistically significant due to a p-value &gt; 0.05. The model for buoy wave height vs.&nbsp;buoy sea surface temperature was statistically significant (p-value &lt; 0.05, but based on the \(R^2\) value, buoy sea surface temperature anomaly accounts for only 3.5% of the variability observed in wave height..</p>
</section>
<section id="future-work" class="level4">
<h4 class="anchored" data-anchor-id="future-work">Future Work</h4>
<p>Further analyses with these datasets could look at correlations on a larger spatial scale by comparing results for other buoy stations closer to and further from the equator than Santa Barbara. The CDIP datasets can also be used to model the effect of ENSO on wave direction.</p>
</section>
</section>
<section id="references" class="level3">
<h3 class="anchored" data-anchor-id="references">References</h3>
<p>References used to create this tutorial include:</p>
<ol type="1">
<li>Coastal Data Information Program (CDIP): <a href="https://cdip.ucsd.edu/" class="uri">https://cdip.ucsd.edu/</a></li>
<li>Coastal Data Information Program (CDIP) data access documentation: <a href="https://cdip.ucsd.edu/m/documents/data_access.html" class="uri">https://cdip.ucsd.edu/m/documents/data_access.html</a></li>
<li>Harvest bouy, station 071: <a href="https://cdip.ucsd.edu/m/products/?stn=071p1" class="uri">https://cdip.ucsd.edu/m/products/?stn=071p1</a></li>
</ol>
<p><strong>Buoy Data citation:</strong> Data furnished by the Coastal Data Information Program (CDIP), Integrative Oceanography Division, operated by the Scripps Institution of Oceanography, under the sponsorship of the U.S. Army Corps of Engineers and the California Department of Parks and Recreation</p>
<p><strong>ENSO Data citation:</strong> Data made publicly available by the National Weather Service’s Climate Prediction Center. The data used: Monthly ERSSTv5 (1991-2020 base period) Niño 3.4 (5°North-5°South)(170-120°West)</p>
<div class="sourceCode" id="cb56" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>
</section>
</section>

 ]]></description>
  <category>Python</category>
  <category>Ocean Data</category>
  <category>Remote Sensing</category>
  <category>ENSO</category>
  <guid>https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/</guid>
  <pubDate>Sat, 04 Dec 2021 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2021-12-04-modeling-enso-and-wave-height/output_51_0.png" medium="image" type="image/png" height="50" width="144"/>
</item>
<item>
  <title>Effect of ENSO on Coral Reefs</title>
  <dc:creator>Cullen Molitor, Desik Somasundaram, Ryan Munnikhuis, and Julia Parish</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2021-12-04-effect-of-enso-on-coral-reefs/</link>
  <description><![CDATA[ 





<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(metajam)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(lubridate)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(janitor)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(vegan)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(zoo)</span></code></pre></div>
</details>
<section id="eds-213-group-project" class="level1">
<h1>EDS 213 Group Project</h1>
<p>Our group discovered the Scott Reef and Rowley Shoals Coral Bleaching Data dataset while searching the DataOne repository for “coral bleaching.” This particular dataset focuses on long-term monitoring data from 1994 to 2017 at reef slope habitats off the coast of northwestern Australia. Data Source: <a href="https://search.dataone.org/view/https%3A%2F%2Fpasta.lternet.edu%2Fpackage%2Fmetadata%2Feml%2Fedi%2F952%2F1" class="uri">https://search.dataone.org/view/https%3A%2F%2Fpasta.lternet.edu%2Fpackage%2Fmetadata%2Feml%2Fedi%2F952%2F1</a>. The metadata includes the reef system, date range, taxonomy, habitat type, coral coverage, and dataset methods.</p>
<section id="download-data" class="level2">
<h2 class="anchored" data-anchor-id="download-data">Download data</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># assign data url to access coral data from DataOne then download</span></span>
<span id="cb2-2">data_url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://cn.dataone.org/cn/v2/resolve/https%3A%2F%2Fpasta.lternet.edu%2Fpackage%2Fdata%2Feml%2Fedi%2F952%2F1%2Ff6212784c45d0a077f2c863868d22c4b"</span></span>
<span id="cb2-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># If data is akready up to date, this will throw an error</span></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># error=T in header will move past this issue</span></span>
<span id="cb2-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">download_d1_data</span>(data_url, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dir_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span>)</span></code></pre></div>
</details>
<pre><code>[1] "./data"</code></pre>
</section>
<section id="load-and-tidy-data" class="level2">
<h2 class="anchored" data-anchor-id="load-and-tidy-data">Load and tidy data</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># assign data path</span></span>
<span id="cb4-2">data_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span></span>
<span id="cb4-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Read in data with metajam</span></span>
<span id="cb4-4">coral_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_d1_files</span>(data_path)</span>
<span id="cb4-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pick out the data read in above and clean it up</span></span>
<span id="cb4-6">corals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> coral_list<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-7">  janitor<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clean_names</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-8">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year_decimal =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">date_decimal</span>(year_decimal), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y-%m-%d"</span>),</span>
<span id="cb4-9">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">month =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">month</span>(year_decimal),</span>
<span id="cb4-10">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">year</span>(year_decimal)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-11">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date =</span> year_decimal)</span>
<span id="cb4-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Read in  ONI to be joined to coral data</span></span>
<span id="cb4-13">oni <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.table</span>(</span>
<span id="cb4-14">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://origin.cpc.ncep.noaa.gov/products/analysis_monitoring/ensostuff/detrend.nino34.ascii.txt"</span>,</span>
<span id="cb4-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">header =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-16">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ISOdate</span>(YR, MON, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)),</span>
<span id="cb4-17">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_start =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ISOdate</span>(YR, MON, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)),</span>
<span id="cb4-18">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_end =</span> lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling_date</span>(date_start, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"month"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-19">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">oni_anomaly =</span> ANOM,</span>
<span id="cb4-20">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">month =</span> MON,</span>
<span id="cb4-21">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year =</span> YR) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-22">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(year, month, oni_anomaly, date_start, date_end) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-23">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">roll_3_month_mean =</span> zoo<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rollmean</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> oni_anomaly, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">k =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">align =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"right"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-24">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(date_start <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ymd</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1994-09-01"</span>))</span>
<span id="cb4-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Calculate the Simpson's diversity index </span></span>
<span id="cb4-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># join corals and ONI data</span></span>
<span id="cb4-27">coral_oni <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> corals <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-28">  tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"species"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cover"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-29">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(system, reef, year, month, location) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-30">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simpson_index =</span> vegan<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diversity</span>(cover, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">index =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"simpson"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-31">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(oni <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>date_start, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>date_end)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-32">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date =</span> lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">make_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year =</span> year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">month =</span> month, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">day =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span></code></pre></div>
</details>
</section>
<section id="plot" class="level2">
<h2 class="anchored" data-anchor-id="plot">Plot</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot the coral diversity data with ONI color bar</span></span>
<span id="cb5-2">ggplot2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-3">  ggplot2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_rect</span>(</span>
<span id="cb5-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> oni,</span>
<span id="cb5-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> date_start, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> date_end, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> oni_anomaly)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-6">  ggplot2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis_c</span>(</span>
<span id="cb5-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">option =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plasma"</span>,</span>
<span id="cb5-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_colorbar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"horizontal"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>,</span>
<span id="cb5-9">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">barheight =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-10">  ggplot2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_date</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_breaks =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2 year"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date_labels =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mult =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-11">  ggplot2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> coral_oni, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb5-12">                     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> date, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> simpson_index, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> location)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-13">  ggplot2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_viridis_d</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-14">  ggplot2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-15">  ggplot2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Oceanic Ni\u00f1o Index"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sites"</span>, </span>
<span id="cb5-16">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Date"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Simpsons Diversity Index"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-17">  ggplot2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-effect-of-enso-on-coral-reefs/figures/unnamed-chunk-4-1.png" width="864"></p>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>
</section>

 ]]></description>
  <category>R</category>
  <category>Ocean Data</category>
  <category>Ecology</category>
  <category>ENSO</category>
  <guid>https://cullen-molitor.github.io/posts/2021-12-04-effect-of-enso-on-coral-reefs/</guid>
  <pubDate>Sat, 04 Dec 2021 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2021-12-04-effect-of-enso-on-coral-reefs/figures/unnamed-chunk-4-1.png" medium="image" type="image/png" height="64" width="144"/>
</item>
<item>
  <title>Remote Sensing with Google Earth Engine</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2021-12-04-precipitation-and-ndvi/</link>
  <description><![CDATA[ 





<section id="purpose" class="level2">
<h2 class="anchored" data-anchor-id="purpose">Purpose</h2>
<p>This analysis was done in order to get familiar with the <a href="https://developers.google.com/earth-engine/tutorials/community/intro-to-python-api-guiattard">Google Earth Engine Python API</a>. To run this code, an account with Google Earth Engine is required and student licences are available for free.</p>
<section id="choose-a-study-region" class="level3">
<h3 class="anchored" data-anchor-id="choose-a-study-region">1. Choose A Study Region</h3>
<p>For this project I am choosing Arcata California. This is where I attended college, and I chose to go there for it’s rural location and its proximity to a variety of outdoor recreation areas. Arcata is a situated along the northern coast of California. The coastal zone surrounding the town includes beautiful coast redwoods (<em>Sequoia sempervirens</em>), Humboldt Bay, and low-lying areas around Humboldt Bay. Going east from the coastal zone, you quickly gain elevation and enter the southern Cascade mountain range and the Trinity Alps. This region contains the volcanoes Mt. Shasta and Mt Lassen, formed by the Cascadia subduction zone. Arcata’s climate falls into the temperate rainforest category, and is dominated by a rainy season and a dry season. Arcata’s population is also somewhat seasonal thanks to the college population leaving for the summer months.</p>
</section>
<section id="locate-a-precipitation-dataset" class="level3">
<h3 class="anchored" data-anchor-id="locate-a-precipitation-dataset">2. Locate A Precipitation Dataset</h3>
<p>Take a look through the Google Earth Engine <a href="https://developers.google.com/earth-engine/datasets">data catalog</a>.</p>
<p>I chose the the ERA5 Daily Aggregates dataset because my other choice Global Precipitation Measurement (GPM) v6 kept exceeding my user memory limit. I also investigated many other datasets (test_1 to test_5 files) but I did not really like how a few of them looked in comparison. I think the ERA5 Daily Aggregates suited my needs quite well and showed the scope of the storm event I was looking at quite well. It feels a bit like cheating, but I really did try to use other datasets. This dataset also gives reasonable spatial resolution.</p>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Import packages</span></span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> ee</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> geemap</span>
<span id="cb1-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb1-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb1-6"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb1-7"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> IPython.display <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> Image</span>
<span id="cb1-8">ee.Initialize()</span></code></pre></div>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">gdat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.ImageCollection(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ECMWF/ERA5/DAILY'</span>)</span>
<span id="cb2-2">gdat_prop <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gdat.propertyNames().getInfo()</span>
<span id="cb2-3">pr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gdat.select(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'total_precipitation'</span>)</span>
<span id="cb2-4">prdflt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pr.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">filter</span>(ee.Filter.date(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2019-02-24'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2019-02-28'</span>)).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-5">prdflt.getInfo()</span></code></pre></div>
<pre><code>{'type': 'Image',
 'bands': [{'id': 'total_precipitation',
   'data_type': {'type': 'PixelType', 'precision': 'double'},
   'crs': 'EPSG:4326',
   'crs_transform': [1, 0, 0, 0, 1, 0]}]}</code></pre>
</section>
<section id="plot-a-time-series-of-precipitation" class="level3">
<h3 class="anchored" data-anchor-id="plot-a-time-series-of-precipitation">3. Plot a Time Series of Precipitation</h3>
<p>Let’s do a new type of analysis on the data: the creation of a time series.</p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">ar_lon <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">124</span></span>
<span id="cb4-2">ar_lat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.8</span></span>
<span id="cb4-3">ar_poi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.Geometry.Point(ar_lon, ar_lat)</span>
<span id="cb4-4">scale <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># scale in m</span></span>
<span id="cb4-5">ar_pr_ts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pr.getRegion(ar_poi, scale).getInfo()</span>
<span id="cb4-6">df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame(ar_pr_ts)</span>
<span id="cb4-7"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(df)</span></code></pre></div>
<pre><code>              0          1          2              3                    4
0            id  longitude   latitude           time  total_precipitation
1      19790102 -123.99895  40.796989   284083200000                    0
2      19790103 -123.99895  40.796989   284169600000                    0
3      19790104 -123.99895  40.796989   284256000000             0.002583
4      19790105 -123.99895  40.796989   284342400000                    0
...         ...        ...        ...            ...                  ...
15161  20200705 -123.99895  40.796989  1593907200000             0.000057
15162  20200706 -123.99895  40.796989  1593993600000             0.000298
15163  20200707 -123.99895  40.796989  1594080000000             0.000005
15164  20200708 -123.99895  40.796989  1594166400000              0.00015
15165  20200709 -123.99895  40.796989  1594252800000             0.000015

[15166 rows x 5 columns]</code></pre>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1">headers <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df.loc[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]     <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Assign the first entry in the data frame to a variable called "headers"</span></span>
<span id="cb6-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(headers) </span></code></pre></div>
<pre><code>0                     id
1              longitude
2               latitude
3                   time
4    total_precipitation
Name: 0, dtype: object</code></pre>
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1">df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame(df.values[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:], columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>headers)      </span>
<span id="cb8-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Make a new data frame out of the old one, but assigning the names we just retrieved as actual column headers</span></span>
<span id="cb8-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(df)  </span></code></pre></div>
<pre><code>0            id  longitude   latitude           time total_precipitation
0      19790102 -123.99895  40.796989   284083200000                   0
1      19790103 -123.99895  40.796989   284169600000                   0
2      19790104 -123.99895  40.796989   284256000000            0.002583
3      19790105 -123.99895  40.796989   284342400000                   0
4      19790106 -123.99895  40.796989   284428800000                   0
...         ...        ...        ...            ...                 ...
15160  20200705 -123.99895  40.796989  1593907200000            0.000057
15161  20200706 -123.99895  40.796989  1593993600000            0.000298
15162  20200707 -123.99895  40.796989  1594080000000            0.000005
15163  20200708 -123.99895  40.796989  1594166400000             0.00015
15164  20200709 -123.99895  40.796989  1594252800000            0.000015

[15165 rows x 5 columns]</code></pre>
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1">df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'datetime'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_datetime(df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'time'</span>], unit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ms'</span>)</span>
<span id="cb10-2">df</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">id</th>
<th style="text-align: left;">longitude</th>
<th style="text-align: left;">latitude</th>
<th style="text-align: left;">time</th>
<th style="text-align: left;">total_precipitation</th>
<th style="text-align: left;">datetime</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">19790102</td>
<td style="text-align: left;">-123.99895</td>
<td style="text-align: left;">40.796989</td>
<td style="text-align: left;">284083200000</td>
<td style="text-align: left;">0</td>
<td style="text-align: left;">1979-01-02</td>
</tr>
<tr class="even">
<td>1</td>
<td style="text-align: left;">19790103</td>
<td style="text-align: left;">-123.99895</td>
<td style="text-align: left;">40.796989</td>
<td style="text-align: left;">284169600000</td>
<td style="text-align: left;">0</td>
<td style="text-align: left;">1979-01-03</td>
</tr>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">19790104</td>
<td style="text-align: left;">-123.99895</td>
<td style="text-align: left;">40.796989</td>
<td style="text-align: left;">284256000000</td>
<td style="text-align: left;">0.002583</td>
<td style="text-align: left;">1979-01-04</td>
</tr>
<tr class="even">
<td>3</td>
<td style="text-align: left;">19790105</td>
<td style="text-align: left;">-123.99895</td>
<td style="text-align: left;">40.796989</td>
<td style="text-align: left;">284342400000</td>
<td style="text-align: left;">0</td>
<td style="text-align: left;">1979-01-05</td>
</tr>
<tr class="odd">
<td>4</td>
<td style="text-align: left;">19790106</td>
<td style="text-align: left;">-123.99895</td>
<td style="text-align: left;">40.796989</td>
<td style="text-align: left;">284428800000</td>
<td style="text-align: left;">0</td>
<td style="text-align: left;">1979-01-06</td>
</tr>
<tr class="even">
<td>…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
</tr>
<tr class="odd">
<td>15160</td>
<td style="text-align: left;">20200705</td>
<td style="text-align: left;">-123.99895</td>
<td style="text-align: left;">40.796989</td>
<td style="text-align: left;">1593907200000</td>
<td style="text-align: left;">0.000057</td>
<td style="text-align: left;">2020-07-05</td>
</tr>
<tr class="even">
<td>15161</td>
<td style="text-align: left;">20200706</td>
<td style="text-align: left;">-123.99895</td>
<td style="text-align: left;">40.796989</td>
<td style="text-align: left;">1593993600000</td>
<td style="text-align: left;">0.000298</td>
<td style="text-align: left;">2020-07-06</td>
</tr>
<tr class="odd">
<td>15162</td>
<td style="text-align: left;">20200707</td>
<td style="text-align: left;">-123.99895</td>
<td style="text-align: left;">40.796989</td>
<td style="text-align: left;">1594080000000</td>
<td style="text-align: left;">0.000005</td>
<td style="text-align: left;">2020-07-07</td>
</tr>
<tr class="even">
<td>15163</td>
<td style="text-align: left;">20200708</td>
<td style="text-align: left;">-123.99895</td>
<td style="text-align: left;">40.796989</td>
<td style="text-align: left;">1594166400000</td>
<td style="text-align: left;">0.00015</td>
<td style="text-align: left;">2020-07-08</td>
</tr>
<tr class="odd">
<td>15164</td>
<td style="text-align: left;">20200709</td>
<td style="text-align: left;">-123.99895</td>
<td style="text-align: left;">40.796989</td>
<td style="text-align: left;">1594252800000</td>
<td style="text-align: left;">0.000015</td>
<td style="text-align: left;">2020-07-09</td>
</tr>
</tbody>
</table>
<p>15165 rows × 6 columns</p>
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1">plt.figure(figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>), dpi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span>)    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create a new figure, set size and resolution (dpi)</span></span>
<span id="cb11-2">plt.plot(df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'datetime'</span>],df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'total_precipitation'</span>])   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add data to the plot</span></span>
<span id="cb11-3">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Arcata Rainfall'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span>
<span id="cb11-4">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Date'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>)</span>
<span id="cb11-5">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Precip (m)'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>)</span>
<span id="cb11-6">plt.ylim(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.12</span>)</span></code></pre></div>
<pre><code>(0.0, 0.12)</code></pre>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-precipitation-and-ndvi/output_19_1.png" class="img-fluid"></p>
</section>
<section id="make-some-maps-of-interesting-times" class="level3">
<h3 class="anchored" data-anchor-id="make-some-maps-of-interesting-times">4. Make Some Maps of Interesting Times</h3>
<p>I chose to take the sum of the time period I examined in order to look at how much precipitation there was over the Mad River watershed. The sum of the values also lets you see the total amount of precipitation over the entire time period of the storm event. My map shows heavy precipitation over the Pacific, making landfall in northern California and Oregon, while staying to the north and largely avoiding Nevada.</p>
<div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Base map</span></span>
<span id="cb13-2">Map <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geemap.Map(center<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.8</span>,<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">124</span>], zoom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)</span>
<span id="cb13-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Min and Max</span></span>
<span id="cb13-4">VIS_PREC <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb13-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'min'</span>:<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb13-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'max'</span>:<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.02</span>,</span>
<span id="cb13-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'palette'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#FFFFFF'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#00FFFF'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#0080FF'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#DA00FF'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#FFA400'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#FF0000'</span>]</span>
<span id="cb13-8">}</span>
<span id="cb13-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add layer</span></span>
<span id="cb13-10">Map.addLayer(prdflt, VIS_PREC,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'total precipitation'</span>,opacity<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)</span>
<span id="cb13-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot map</span></span>
<span id="cb13-12">Map</span></code></pre></div>
<pre><code>Map(center=[40.8, -124], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=HBox(children=…</code></pre>
<div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1">pt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.Geometry.Point([<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">124.3652</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.2922</span>])</span>
<span id="cb15-2">roi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pt.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">buffer</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1600000</span>)</span>
<span id="cb15-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create a URL to the styled image for a region around Mendocino County CA.</span></span>
<span id="cb15-4">url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> prdflt.getThumbUrl({</span>
<span id="cb15-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'min'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'max'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.02</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimensions'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">512</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'region'</span>: roi, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'opacity'</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,</span>
<span id="cb15-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'palette'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#FFFFFF'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#00FFFF'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#0080FF'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#DA00FF'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#FFA400'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#FF0000'</span>]})</span>
<span id="cb15-7">Image(url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>url, embed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">format</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'png'</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-precipitation-and-ndvi/output_26_0.png" class="img-fluid"></p>
</section>
<section id="plot-landsat-ndvi-for-the-region" class="level3">
<h3 class="anchored" data-anchor-id="plot-landsat-ndvi-for-the-region">5. Plot Landsat NDVI for the Region</h3>
<p>The precipitation analysis discussed above provides useful context for identifying interesting weather events for a particular region. Now let’s see what (if any!) effect changes in weather patterns have had on the landscape, using Landsat imagery.</p>
<p>I was able to see a slight difference in the two images. It is unclear to me if the long term average includes more cloud cover and is therefore less bright/vivid, or if the rain increased the vegetation. If I had to guess I would say that there was not a very noticeable change because I chose an area that is already very wet and productive.</p>
<div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1">land_8 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.ImageCollection(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'LANDSAT/LC08/C01/T1_TOA'</span>)</span>
<span id="cb16-2">pt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.Geometry.Point([<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">124</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.8</span>])   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Point corresponding to Arcata, CA</span></span>
<span id="cb16-3">land_8_pt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> land_8.filterBounds(pt)</span>
<span id="cb16-4">land_8_least_cld <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> land_8_pt.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CLOUD_COVER &lt; 20'</span>).mean()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb16-5">red <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> land_8_least_cld.select(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B4'</span>)</span>
<span id="cb16-6">nir <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> land_8_least_cld.select(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B5'</span>)</span>
<span id="cb16-7">ndvi<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(nir.subtract(red)).divide((nir.add(red))).rename(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'NDVI'</span>)</span>
<span id="cb16-8">ndvi</span></code></pre></div>
<pre><code>&lt;ee.image.Image at 0x22d22b1b280&gt;</code></pre>
<div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb18-1">ndviParams <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'min'</span>: <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, </span>
<span id="cb18-2">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'max'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, </span>
<span id="cb18-3">              <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'palette'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'blue'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'green'</span>]</span>
<span id="cb18-4">             }</span></code></pre></div>
<div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#  Interactive only, no saved output</span></span>
<span id="cb19-2">Map_NDVI <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geemap.Map(center<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.8</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">124</span>], zoom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb19-3">Map_NDVI.addLayer(ndvi, ndviParams,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'NDVI'</span>)</span>
<span id="cb19-4">Map_NDVI</span></code></pre></div>
<pre><code>Map(center=[40.8, -124], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=HBox(children=…</code></pre>
<div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb21-1">pt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.Geometry.Point([<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">124.3652</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.2922</span>])</span>
<span id="cb21-2">roi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pt.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">buffer</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120000</span>)</span>
<span id="cb21-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create a URL to the styled image for a region around Mendocino County CA.</span></span>
<span id="cb21-4">url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ndvi.getThumbUrl({</span>
<span id="cb21-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'min'</span>: <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'max'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimensions'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">512</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'region'</span>: roi,</span>
<span id="cb21-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'palette'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'blue'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'green'</span>]})</span>
<span id="cb21-7">Image(url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>url, embed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">format</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'png'</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-precipitation-and-ndvi/output_37_0.png" class="img-fluid"></p>
<div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb22-1">land_8_least_cld_flt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> land_8_pt.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'CLOUD_COVER &lt; 20'</span>)</span>
<span id="cb22-2">land_8_least_cld_flt_dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> land_8_least_cld_flt.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">filter</span>(ee.Filter.date(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2019-01-01'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'2019-04-28'</span>)).mean()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-3">red_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> land_8_least_cld_flt_dt.select(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B4'</span>)</span>
<span id="cb22-4">nir_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> land_8_least_cld_flt_dt.select(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B5'</span>)</span>
<span id="cb22-5">ndvi_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (nir_2.subtract(red_2)).divide((nir_2.add(red_2))).rename(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'NDVI'</span>)</span>
<span id="cb22-6">ndvi_2</span></code></pre></div>
<pre><code>&lt;ee.image.Image at 0x22d220f6820&gt;</code></pre>
<div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb24-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#  Interactive only, no saved output</span></span>
<span id="cb24-2">Map_NDVI_flt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geemap.Map(center<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.8</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">124</span>], zoom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb24-3">Map_NDVI_flt.addLayer(ndvi_2, ndviParams,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'NDVI'</span>)</span>
<span id="cb24-4">Map_NDVI_flt</span></code></pre></div>
<pre><code>Map(center=[40.8, -124], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=HBox(children=…</code></pre>
<div class="sourceCode" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb26-1">pt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ee.Geometry.Point([<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">124.3652</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.2922</span>])</span>
<span id="cb26-2">roi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pt.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">buffer</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120000</span>)</span>
<span id="cb26-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create a URL to the styled image for a region around Mendocino County CA.</span></span>
<span id="cb26-4">url <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ndvi_2.getThumbUrl({</span>
<span id="cb26-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'min'</span>: <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'max'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimensions'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">512</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'region'</span>: roi,</span>
<span id="cb26-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'palette'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'blue'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'green'</span>]})</span>
<span id="cb26-7">Image(url<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>url, embed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">format</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'png'</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-04-precipitation-and-ndvi/output_42_0.png" class="img-fluid"></p>
<div class="sourceCode" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>
</section>

 ]]></description>
  <category>Python</category>
  <category>Spatial Analysis</category>
  <category>Google Earth Engine</category>
  <category>Remote Sensing</category>
  <guid>https://cullen-molitor.github.io/posts/2021-12-04-precipitation-and-ndvi/</guid>
  <pubDate>Sat, 04 Dec 2021 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2021-12-04-precipitation-and-ndvi/output_42_0.png" medium="image" type="image/png" height="111" width="144"/>
</item>
<item>
  <title>Protecting Whales From Ships</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/</link>
  <description><![CDATA[ 





<section id="setup" class="level2">
<h2 class="anchored" data-anchor-id="setup">Setup</h2>
<p>Import Modules</p>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> geopandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> gpd </span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> rasterio <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> rio</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> rasterio.plot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> show</span>
<span id="cb1-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb1-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb1-6"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.image <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> mpimg</span>
<span id="cb1-7"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb1-8"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> os</span>
<span id="cb1-9"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> glob</span>
<span id="cb1-10"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> contextily <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> ctx</span>
<span id="cb1-11"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> shapely</span>
<span id="cb1-12"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> shapely.geometry <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> Polygon</span>
<span id="cb1-13"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span>matplotlib inline</span></code></pre></div>
<p>Set Parameters and constants</p>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">shoreline_shapefile  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'data/dominica/dma_admn_adm0_py_s1_dominode_v2.shp'</span></span>
<span id="cb2-2">whales_CSV           <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'data/sightings2005_2018.csv'</span></span>
<span id="cb2-3">vessels_CSV          <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'data/station1249.csv'</span></span>
<span id="cb2-4">ten_kn_in_ms <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.14</span></span>
<span id="cb2-5">projected_EPSG <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2002</span>   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Dominica 1945 / British West Indies Grid</span></span>
<span id="cb2-6">geodetic_EPSG  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4326</span>   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># WGS 84 (use as default CRS for incoming latlon)</span></span></code></pre></div>
</section>
<section id="load-data" class="level2">
<h2 class="anchored" data-anchor-id="load-data">Load Data</h2>
<p>Dominica Shape File</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1">dominica_shp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.read_file(shoreline_shapefile)</span>
<span id="cb3-2">dominica_shp.head()</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">ADM0_PCODE</th>
<th style="text-align: left;">ADM0_EN</th>
<th style="text-align: left;">geometry</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">DM</td>
<td style="text-align: left;">Dominica</td>
<td style="text-align: left;">POLYGON ((-61.43023 15.63952, -61.43019 15.639…</td>
</tr>
</tbody>
</table>
<p>Set CRS to <a href="https://epsg.io/2002">EPSG 2002</a></p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">dominica_shp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> dominica_shp.to_crs(projected_EPSG)</span>
<span id="cb4-2">dominica_shp.crs</span></code></pre></div>
<pre><code>&lt;Projected CRS: EPSG:2002&gt;
Name: Dominica 1945 / British West Indies Grid
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Dominica - onshore.
- bounds: (-61.55, 15.14, -61.2, 15.69)
Coordinate Operation:
- name: British West Indies Grid
- method: Transverse Mercator
Datum: Dominica 1945
- Ellipsoid: Clarke 1880 (RGS)
- Prime Meridian: Greenwich</code></pre>
</section>
<section id="plot-dominica" class="level2">
<h2 class="anchored" data-anchor-id="plot-dominica">Plot Dominica</h2>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb6-2">ax.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimgray'</span>)</span>
<span id="cb6-3">ax.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span>(ylim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.67e6</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.74e6</span>), xlim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">445000</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">490000</span>))</span>
<span id="cb6-4">ax.ticklabel_format(scilimits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb6-5">dominica_shp.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, edgecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>, facecolor<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"None"</span>)</span>
<span id="cb6-6">ctx.add_basemap(ax, crs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>projected_EPSG)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_15_0.png" class="img-fluid"></p>
</section>
<section id="load-data-1" class="level2">
<h2 class="anchored" data-anchor-id="load-data-1">Load Data</h2>
<p>Whale Sightings</p>
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1">whales <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.read_file(whales_CSV)</span>
<span id="cb7-2">whales</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">field_1</th>
<th style="text-align: left;">GPStime</th>
<th style="text-align: left;">Lat</th>
<th style="text-align: left;">Long</th>
<th style="text-align: left;">geometry</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">0</td>
<td style="text-align: left;">2005-01-15 07:43:27</td>
<td style="text-align: left;">15.36977117</td>
<td style="text-align: left;">-61.49328433</td>
<td style="text-align: left;">None</td>
</tr>
<tr class="even">
<td>1</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">2005-01-15 08:07:13</td>
<td style="text-align: left;">15.3834075</td>
<td style="text-align: left;">-61.503702</td>
<td style="text-align: left;">None</td>
</tr>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">2</td>
<td style="text-align: left;">2005-01-15 08:31:17</td>
<td style="text-align: left;">15.38106333</td>
<td style="text-align: left;">-61.50486067</td>
<td style="text-align: left;">None</td>
</tr>
<tr class="even">
<td>3</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">2005-01-15 09:19:10</td>
<td style="text-align: left;">15.33532083</td>
<td style="text-align: left;">-61.46858117</td>
<td style="text-align: left;">None</td>
</tr>
<tr class="odd">
<td>4</td>
<td style="text-align: left;">4</td>
<td style="text-align: left;">2005-01-15 10:08:00</td>
<td style="text-align: left;">15.294224</td>
<td style="text-align: left;">-61.45318517</td>
<td style="text-align: left;">None</td>
</tr>
<tr class="even">
<td>…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
</tr>
<tr class="odd">
<td>4888</td>
<td style="text-align: left;">4888</td>
<td style="text-align: left;">2018-05-25 12:01:25</td>
<td style="text-align: left;">15.39195</td>
<td style="text-align: left;">-61.572</td>
<td style="text-align: left;">None</td>
</tr>
<tr class="even">
<td>4889</td>
<td style="text-align: left;">4889</td>
<td style="text-align: left;">2018-05-25 13:08:29</td>
<td style="text-align: left;">15.4189</td>
<td style="text-align: left;">-61.5833</td>
<td style="text-align: left;">None</td>
</tr>
<tr class="odd">
<td>4890</td>
<td style="text-align: left;">4890</td>
<td style="text-align: left;">2018-05-25 14:50:00</td>
<td style="text-align: left;">15.443483</td>
<td style="text-align: left;">-61.60995</td>
<td style="text-align: left;">None</td>
</tr>
<tr class="even">
<td>4891</td>
<td style="text-align: left;">4891</td>
<td style="text-align: left;">2018-05-25 15:57:34</td>
<td style="text-align: left;">15.499866</td>
<td style="text-align: left;">-61.638333</td>
<td style="text-align: left;">None</td>
</tr>
<tr class="odd">
<td>4892</td>
<td style="text-align: left;">4892</td>
<td style="text-align: left;">2018-05-25 16:17:10</td>
<td style="text-align: left;">15.494783</td>
<td style="text-align: left;">-61.6482</td>
<td style="text-align: left;">None</td>
</tr>
</tbody>
</table>
<p>4893 rows × 5 columns</p>
<p>Create GeoDataFrame</p>
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1">points <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.points_from_xy(whales[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Long'</span>], whales[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Lat'</span>], crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geodetic_EPSG)</span>
<span id="cb8-2">whales_gdf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.GeoDataFrame(whales, geometry <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> points)</span>
<span id="cb8-3">whales_gdf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> whales_gdf.to_crs(projected_EPSG)</span></code></pre></div>
<p>Plot Whale Sightings</p>
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb9-2">ax.set_aspect(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'equal'</span>)</span>
<span id="cb9-3">ax.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimgray'</span>)</span>
<span id="cb9-4">ax.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span>(xlim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4e5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5e5</span>), ylim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5e6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.8e6</span>))</span>
<span id="cb9-5">dominica_shp.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'None'</span>, edgecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>)</span>
<span id="cb9-6">whales_gdf.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, markersize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.1</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>, alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.25</span>)</span>
<span id="cb9-7">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Whale Sightings'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)</span>
<span id="cb9-8">ax.ticklabel_format(scilimits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb9-9">ctx.add_basemap(ax, crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> projected_EPSG)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_24_0.png" class="img-fluid"></p>
</section>
<section id="create-grid" class="level2">
<h2 class="anchored" data-anchor-id="create-grid">Create Grid</h2>
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1">xmin, ymin, xmax, ymax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> whales_gdf.total_bounds</span>
<span id="cb10-2">cell_size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span></span>
<span id="cb10-3">xs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>(np.arange(xmin, xmax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> cell_size, cell_size))</span>
<span id="cb10-4">ys <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>(np.arange(ymin, ymax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> cell_size, cell_size))</span>
<span id="cb10-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> make_cell(x, y, cell_size):</span>
<span id="cb10-6">    ring <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb10-7">        (x, y),</span>
<span id="cb10-8">        (x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> cell_size, y),</span>
<span id="cb10-9">        (x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> cell_size, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> cell_size),</span>
<span id="cb10-10">        (x, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> cell_size)</span>
<span id="cb10-11">    ]</span>
<span id="cb10-12">    cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> shapely.geometry.Polygon(ring)</span>
<span id="cb10-13">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> cell</span>
<span id="cb10-14">cells <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb10-15"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> xs:</span>
<span id="cb10-16">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> y <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> ys:</span>
<span id="cb10-17">        cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_cell(x, y, cell_size)</span>
<span id="cb10-18">        cells.append(cell)</span>
<span id="cb10-19">grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.GeoDataFrame({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'geometry'</span>: cells}, crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geodetic_EPSG)</span>
<span id="cb10-20">grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid.set_geometry(crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> projected_EPSG, col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'geometry'</span>])</span></code></pre></div>
<p>Plot Grid</p>
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1">grid.plot(facecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>), linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div>
<pre><code>&lt;AxesSubplot:&gt;</code></pre>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_36_1.png" class="img-fluid"></p>
<p>Extract Whale Habitat</p>
<div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1">whale_grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid.sjoin(whales_gdf, how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"inner"</span>)</span></code></pre></div>
<p>Plot whale sighting grid cells</p>
<div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb14-1">whale_grid.plot(facecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>), linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.75</span>)</span></code></pre></div>
<pre><code>&lt;AxesSubplot:&gt;</code></pre>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_40_1.png" class="img-fluid"></p>
<section id="summarise-whale-counts" class="level3">
<h3 class="anchored" data-anchor-id="summarise-whale-counts">Summarise Whale Counts</h3>
<div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1">grid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'count'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> whale_grid.groupby(whale_grid.index).count()[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'index_right'</span>]</span>
<span id="cb16-2">grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid[grid[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'count'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>]</span></code></pre></div>
<p>Plot Whale Habitat</p>
<div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1">grid.plot(facecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>, figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>), linewidth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.75</span>)</span></code></pre></div>
<pre><code>&lt;AxesSubplot:&gt;</code></pre>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_46_1.png" class="img-fluid"></p>
</section>
<section id="create-unary-union" class="level3">
<h3 class="anchored" data-anchor-id="create-unary-union">Create Unary Union</h3>
<div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-1">grid_union <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid.unary_union</span>
<span id="cb19-2">grid_union</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_49_0.svg" class="img-fluid"></p>
</section>
</section>
<section id="create-vessel-speed-reduction-zone" class="level2">
<h2 class="anchored" data-anchor-id="create-vessel-speed-reduction-zone">Create Vessel Speed Reduction Zone</h2>
<p>The vessel speed reduction zone is determined by the whale habitat areas in which more than 20 whales were observed per 2,000 m².</p>
<div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb20-1">grid_convex <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid_union.convex_hull</span>
<span id="cb20-2">grid_convex</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_52_0.svg" class="img-fluid"></p>
<p>Make GeoDataFrame</p>
<div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb21-1">whale_habitat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.GeoDataFrame(index <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>], geometry <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [grid_convex], crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> projected_EPSG)</span></code></pre></div>
<p>Plot</p>
<div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb22-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb22-2">ax.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimgray'</span>)</span>
<span id="cb22-3">ax.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span>(xlim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.4e5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.85e5</span>), ylim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.675e6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.73e6</span>))</span>
<span id="cb22-4">dominica_shp.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'None'</span>, edgecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>)</span>
<span id="cb22-5">whale_habitat.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, edgecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>, facecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>)</span>
<span id="cb22-6">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Whale Habitat'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)</span>
<span id="cb22-7">ax.ticklabel_format(scilimits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb22-8">ctx.add_basemap(ax, crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> projected_EPSG)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_56_0.png" class="img-fluid"></p>
<div class="sourceCode" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb23-1">whale_habitat_diff <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> whale_habitat.difference(dominica_shp)</span>
<span id="cb23-2">whale_habitat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.GeoDataFrame(geometry <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> whale_habitat_diff)</span>
<span id="cb23-3">whale_habitat</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">geometry</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">POLYGON ((456480.652 1682792.746, 454480.652 1…</td>
</tr>
</tbody>
</table>
<div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb24-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb24-2">ax.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimgray'</span>)</span>
<span id="cb24-3">ax.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span>(xlim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.4e5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.85e5</span>), ylim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.675e6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.73e6</span>))</span>
<span id="cb24-4">dominica_shp.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'None'</span>, edgecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>)</span>
<span id="cb24-5">whale_habitat.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, edgecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>, facecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>)</span>
<span id="cb24-6">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Whale Habitat'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)</span>
<span id="cb24-7">ax.ticklabel_format(scilimits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb24-8">ctx.add_basemap(ax, crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> projected_EPSG)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_58_0.png" class="img-fluid"></p>
<div class="sourceCode" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb25-1">whale_habitat</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">geometry</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">POLYGON ((456480.652 1682792.746, 454480.652 1…</td>
</tr>
</tbody>
</table>
</section>
<section id="load-ais-vessel-data" class="level2">
<h2 class="anchored" data-anchor-id="load-ais-vessel-data">Load AIS Vessel Data</h2>
<div class="sourceCode" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb26-1">vessels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.read_file(vessels_CSV)</span>
<span id="cb26-2">points <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.points_from_xy(vessels[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'LON'</span>], vessels[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'LAT'</span>], crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> geodetic_EPSG)</span>
<span id="cb26-3">vessels_gdf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.GeoDataFrame(vessels, geometry <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> points)</span>
<span id="cb26-4">vessels_gdf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vessels_gdf.to_crs(projected_EPSG)</span>
<span id="cb26-5">vessels_gdf[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'TIMESTAMP'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.to_datetime(vessels_gdf[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'TIMESTAMP'</span>])</span>
<span id="cb26-6">vessels_gdf</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">field_1</th>
<th style="text-align: left;">MMSI</th>
<th style="text-align: left;">LON</th>
<th style="text-align: left;">LAT</th>
<th style="text-align: left;">TIMESTAMP</th>
<th style="text-align: left;">geometry</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">0</td>
<td style="text-align: left;">233092000</td>
<td style="text-align: left;">-61.84788</td>
<td style="text-align: left;">15.23238</td>
<td style="text-align: left;">2015-05-22 13:53:26</td>
<td style="text-align: left;">POINT (-61.84788 15.23238)</td>
</tr>
<tr class="even">
<td>1</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">255803280</td>
<td style="text-align: left;">-61.74397</td>
<td style="text-align: left;">15.96114</td>
<td style="text-align: left;">2015-05-22 13:52:57</td>
<td style="text-align: left;">POINT (-61.74397 15.96114)</td>
</tr>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">2</td>
<td style="text-align: left;">329002300</td>
<td style="text-align: left;">-61.38968</td>
<td style="text-align: left;">15.29744</td>
<td style="text-align: left;">2015-05-22 13:52:32</td>
<td style="text-align: left;">POINT (-61.38968 15.29744)</td>
</tr>
<tr class="even">
<td>3</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">257674000</td>
<td style="text-align: left;">-61.54395</td>
<td style="text-align: left;">16.2334</td>
<td style="text-align: left;">2015-05-22 13:52:24</td>
<td style="text-align: left;">POINT (-61.54395 16.23340)</td>
</tr>
<tr class="odd">
<td>4</td>
<td style="text-align: left;">4</td>
<td style="text-align: left;">636092006</td>
<td style="text-align: left;">-61.52401</td>
<td style="text-align: left;">15.81954</td>
<td style="text-align: left;">2015-05-22 13:51:23</td>
<td style="text-align: left;">POINT (-61.52401 15.81954)</td>
</tr>
<tr class="even">
<td>…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
</tr>
<tr class="odd">
<td>617257</td>
<td style="text-align: left;">238722</td>
<td style="text-align: left;">256525000</td>
<td style="text-align: left;">-61.40679</td>
<td style="text-align: left;">15.36907</td>
<td style="text-align: left;">2015-05-21 21:34:59</td>
<td style="text-align: left;">POINT (-61.40679 15.36907)</td>
</tr>
<tr class="even">
<td>617258</td>
<td style="text-align: left;">238723</td>
<td style="text-align: left;">311077100</td>
<td style="text-align: left;">-61.37539</td>
<td style="text-align: left;">15.27406</td>
<td style="text-align: left;">2015-05-21 21:34:55</td>
<td style="text-align: left;">POINT (-61.37539 15.27406)</td>
</tr>
<tr class="odd">
<td>617259</td>
<td style="text-align: left;">238724</td>
<td style="text-align: left;">377907247</td>
<td style="text-align: left;">-61.39461</td>
<td style="text-align: left;">15.30672</td>
<td style="text-align: left;">2015-05-21 21:34:46</td>
<td style="text-align: left;">POINT (-61.39461 15.30672)</td>
</tr>
<tr class="even">
<td>617260</td>
<td style="text-align: left;">238725</td>
<td style="text-align: left;">253365000</td>
<td style="text-align: left;">-61.49001</td>
<td style="text-align: left;">16.14007</td>
<td style="text-align: left;">2015-05-21 21:34:46</td>
<td style="text-align: left;">POINT (-61.49001 16.14007)</td>
</tr>
<tr class="odd">
<td>617261</td>
<td style="text-align: left;">238726</td>
<td style="text-align: left;">329002300</td>
<td style="text-align: left;">-61.48073</td>
<td style="text-align: left;">15.44751</td>
<td style="text-align: left;">2015-05-21 21:34:45</td>
<td style="text-align: left;">POINT (-61.48073 15.44751)</td>
</tr>
</tbody>
</table>
<p>617262 rows × 6 columns</p>
<section id="select-vessels-inside-whale-habitat" class="level3">
<h3 class="anchored" data-anchor-id="select-vessels-inside-whale-habitat">Select Vessels Inside Whale Habitat</h3>
<div class="sourceCode" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb27-1">vessels_whale <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vessels_gdf.sjoin(whale_habitat, how <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'inner'</span>)</span>
<span id="cb27-2">vessels_whale</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">field_1</th>
<th style="text-align: left;">MMSI</th>
<th style="text-align: left;">LON</th>
<th style="text-align: left;">LAT</th>
<th style="text-align: left;">TIMESTAMP</th>
<th style="text-align: left;">geometry</th>
<th style="text-align: left;">index_right</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">2</td>
<td style="text-align: left;">329002300</td>
<td style="text-align: left;">-61.38968</td>
<td style="text-align: left;">15.29744</td>
<td style="text-align: left;">2015-05-22 13:52:32</td>
<td style="text-align: left;">POINT (464555.392 1690588.725)</td>
<td style="text-align: left;">0</td>
</tr>
<tr class="even">
<td>7</td>
<td style="text-align: left;">7</td>
<td style="text-align: left;">338143127</td>
<td style="text-align: left;">-61.39575</td>
<td style="text-align: left;">15.33418</td>
<td style="text-align: left;">2015-05-22 13:50:54</td>
<td style="text-align: left;">POINT (463892.452 1694650.397)</td>
<td style="text-align: left;">0</td>
</tr>
<tr class="odd">
<td>13</td>
<td style="text-align: left;">13</td>
<td style="text-align: left;">329002300</td>
<td style="text-align: left;">-61.38968</td>
<td style="text-align: left;">15.29745</td>
<td style="text-align: left;">2015-05-22 13:48:32</td>
<td style="text-align: left;">POINT (464555.389 1690589.831)</td>
<td style="text-align: left;">0</td>
</tr>
<tr class="even">
<td>15</td>
<td style="text-align: left;">15</td>
<td style="text-align: left;">338143015</td>
<td style="text-align: left;">-61.39558</td>
<td style="text-align: left;">15.33423</td>
<td style="text-align: left;">2015-05-22 13:47:31</td>
<td style="text-align: left;">POINT (463910.683 1694655.978)</td>
<td style="text-align: left;">0</td>
</tr>
<tr class="odd">
<td>16</td>
<td style="text-align: left;">16</td>
<td style="text-align: left;">338143127</td>
<td style="text-align: left;">-61.39757</td>
<td style="text-align: left;">15.33139</td>
<td style="text-align: left;">2015-05-22 13:47:25</td>
<td style="text-align: left;">POINT (463697.964 1694341.275)</td>
<td style="text-align: left;">0</td>
</tr>
<tr class="even">
<td>…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
</tr>
<tr class="odd">
<td>617252</td>
<td style="text-align: left;">238717</td>
<td style="text-align: left;">329002300</td>
<td style="text-align: left;">-61.4885</td>
<td style="text-align: left;">15.4706</td>
<td style="text-align: left;">2015-05-21 21:37:45</td>
<td style="text-align: left;">POINT (453901.647 1709712.916)</td>
<td style="text-align: left;">0</td>
</tr>
<tr class="even">
<td>617253</td>
<td style="text-align: left;">238718</td>
<td style="text-align: left;">338143015</td>
<td style="text-align: left;">-61.39553</td>
<td style="text-align: left;">15.33448</td>
<td style="text-align: left;">2015-05-21 21:37:14</td>
<td style="text-align: left;">POINT (463915.972 1694683.643)</td>
<td style="text-align: left;">0</td>
</tr>
<tr class="odd">
<td>617255</td>
<td style="text-align: left;">238720</td>
<td style="text-align: left;">338143127</td>
<td style="text-align: left;">-61.39563</td>
<td style="text-align: left;">15.33468</td>
<td style="text-align: left;">2015-05-21 21:35:12</td>
<td style="text-align: left;">POINT (463905.177 1694705.734)</td>
<td style="text-align: left;">0</td>
</tr>
<tr class="even">
<td>617259</td>
<td style="text-align: left;">238724</td>
<td style="text-align: left;">377907247</td>
<td style="text-align: left;">-61.39461</td>
<td style="text-align: left;">15.30672</td>
<td style="text-align: left;">2015-05-21 21:34:46</td>
<td style="text-align: left;">POINT (464023.288 1691613.624)</td>
<td style="text-align: left;">0</td>
</tr>
<tr class="odd">
<td>617261</td>
<td style="text-align: left;">238726</td>
<td style="text-align: left;">329002300</td>
<td style="text-align: left;">-61.48073</td>
<td style="text-align: left;">15.44751</td>
<td style="text-align: left;">2015-05-21 21:34:45</td>
<td style="text-align: left;">POINT (454741.236 1707161.130)</td>
<td style="text-align: left;">0</td>
</tr>
</tbody>
</table>
<p>167402 rows × 7 columns</p>
</section>
<section id="plot-vessel-data" class="level3">
<h3 class="anchored" data-anchor-id="plot-vessel-data">Plot Vessel Data</h3>
<div class="sourceCode" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb28-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb28-2">ax.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimgray'</span>)</span>
<span id="cb28-3">ax.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span>(xlim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.4e5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.85e5</span>), ylim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.675e6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.73e6</span>))</span>
<span id="cb28-4">dominica_shp.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'None'</span>, edgecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>)</span>
<span id="cb28-5">vessels_whale.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, markersize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.1</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>, alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.1</span>)</span>
<span id="cb28-6">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Vessel Data Inside Whale Habitat'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)</span>
<span id="cb28-7">ax.ticklabel_format(scilimits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb28-8">ctx.add_basemap(ax, crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> projected_EPSG)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_74_0.png" class="img-fluid"></p>
</section>
</section>
<section id="calculate-vessel-speeds" class="level2">
<h2 class="anchored" data-anchor-id="calculate-vessel-speeds">Calculate Vessel Speeds</h2>
<div class="sourceCode" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb29-1">vessels_whale_sorted <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vessels_whale.sort_values([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'MMSI'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'TIMESTAMP'</span>])</span>
<span id="cb29-2">vessels_whale_shifted <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vessels_whale_sorted.shift(periods <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb29-3">vw_sorted_shifted <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vessels_whale_sorted.join(vessels_whale_shifted, lsuffix <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_original"</span>, rsuffix <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_copy"</span>)</span>
<span id="cb29-4">vw_matched <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_sorted_shifted[vw_sorted_shifted[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'MMSI_original'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> vw_sorted_shifted[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'MMSI_copy'</span>]]</span>
<span id="cb29-5">vw_matched <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched.set_geometry(col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'geometry_original'</span>], crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> projected_EPSG)</span>
<span id="cb29-6">vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'distance_m'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'geometry_original'</span>].distance(vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'geometry_copy'</span>]) </span>
<span id="cb29-7">vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'time_s'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'TIMESTAMP_original'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'TIMESTAMP_copy'</span>]</span>
<span id="cb29-8">vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'time_s'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'time_s'</span>].dt.total_seconds() </span>
<span id="cb29-9">vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'speed_ms'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'distance_m'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'time_s'</span>]</span>
<span id="cb29-10">vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'10_kn_time'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'distance_m'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> ten_kn_in_ms</span>
<span id="cb29-11">vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'time_diff'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'10_kn_time'</span>].sub(vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'time_s'</span>])</span>
<span id="cb29-12">vw_matched <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched[vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'time_diff'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]</span></code></pre></div>
<section id="plot-vessels-travelling-over-10-knots" class="level3">
<h3 class="anchored" data-anchor-id="plot-vessels-travelling-over-10-knots">Plot Vessels travelling over 10 knots</h3>
<div class="sourceCode" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb30-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb30-2">ax.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimgray'</span>)</span>
<span id="cb30-3">ax.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span>(xlim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.4e5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.85e5</span>), ylim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.675e6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.73e6</span>))</span>
<span id="cb30-4">dominica_shp.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'None'</span>, edgecolor <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k"</span>)</span>
<span id="cb30-5">vw_matched.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, markersize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.1</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>, alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.25</span>)</span>
<span id="cb30-6">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Vessel Data Inside Whale Habitat'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)</span>
<span id="cb30-7">ax.ticklabel_format(scilimits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb30-8">ctx.add_basemap(ax, crs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> projected_EPSG)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_97_0.png" class="img-fluid"></p>
</section>
</section>
<section id="impact-of-a-10-knot-speed-reduction-zone" class="level2">
<h2 class="anchored" data-anchor-id="impact-of-a-10-knot-speed-reduction-zone">Impact of a 10 knot Speed Reduction Zone</h2>
<p>We calculated that ship vessel traffic would be slowed by 2 minutes per mile on average. Over the course of the year, this equated to approximately 28 days of increased shipping time.</p>
<div class="sourceCode" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb31-1">num_days <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'time_diff'</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span></span></code></pre></div>
<div class="sourceCode" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb32-1">num_days</span></code></pre></div>
<pre><code>27.9423247732646</code></pre>
<div class="sourceCode" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb34-1">mean_time_lost <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vw_matched[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'time_diff'</span>].mean() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span></span></code></pre></div>
<div class="sourceCode" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb35-1">mean_time_lost</span></code></pre></div>
<pre><code>1.8906563139508044</code></pre>
<div class="sourceCode" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>

 ]]></description>
  <category>Python</category>
  <category>Spatial Analysis</category>
  <guid>https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/</guid>
  <pubDate>Fri, 03 Dec 2021 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2021-12-03-protecting-whales-from-ships/output_74_0.png" medium="image" type="image/png" height="174" width="144"/>
</item>
<item>
  <title>Houston Blackout Analysis (2021)</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2021-12-03-houston-blackout-analysis-2021/</link>
  <description><![CDATA[ 





<section id="load-libraries" class="level2">
<h2 class="anchored" data-anchor-id="load-libraries">Load libraries</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(sf)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(here)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(stars)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rosm)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tmap)</span></code></pre></div>
</details>
</section>
<section id="function-to-load-the-dnb-dataset-from-vnp46a1-granules" class="level2">
<h2 class="anchored" data-anchor-id="function-to-load-the-dnb-dataset-from-vnp46a1-granules">Function to load the DNB dataset from VNP46A1 granules</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">read_dnb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(file_name) {</span>
<span id="cb2-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Reads the "DNB_At_Sensor_Radiance_500m" dataset from a VNP46A1 granule into a STARS object.</span></span>
<span id="cb2-3">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Then read the sinolsoidal tile x/y positions and adjust the STARS dimensions (extent+delta)</span></span>
<span id="cb2-4"></span>
<span id="cb2-5">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The name of the dataset holding the nightlight band in the granule</span></span>
<span id="cb2-6">  dataset_name <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"//HDFEOS/GRIDS/VNP_Grid_DNB/Data_Fields/DNB_At_Sensor_Radiance_500m"</span></span>
<span id="cb2-7"></span>
<span id="cb2-8">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># From the metadata, we pull out a string containing the horizontal and vertical tile index</span></span>
<span id="cb2-9">  h_string <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gdal_metadata</span>(file_name)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span>]</span>
<span id="cb2-10">  v_string <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gdal_metadata</span>(file_name)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">219</span>]</span>
<span id="cb2-11">  </span>
<span id="cb2-12">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We parse the h/v string to pull out the integer number of h and v</span></span>
<span id="cb2-13">  tile_h <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_split</span>(h_string, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"="</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simplify =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]])</span>
<span id="cb2-14">  tile_v <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_split</span>(v_string, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"="</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simplify =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]])</span>
<span id="cb2-15"></span>
<span id="cb2-16">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># From the h/v tile grid position, we get the offset and the extent</span></span>
<span id="cb2-17">  west <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> tile_h) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">180</span></span>
<span id="cb2-18">  north <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> tile_v)</span>
<span id="cb2-19">  east <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> west <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb2-20">  south <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> north <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb2-21"></span>
<span id="cb2-22">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># A tile is 10 degrees and has 2400x2400 grid cells</span></span>
<span id="cb2-23">  delta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2400</span></span>
<span id="cb2-24"></span>
<span id="cb2-25">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Reading the dataset</span></span>
<span id="cb2-26">  dnb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_stars</span>(file_name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sub =</span> dataset_name)</span>
<span id="cb2-27"></span>
<span id="cb2-28">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Setting the CRS and applying offsets and deltas</span></span>
<span id="cb2-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_crs</span>(dnb) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_crs</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4326</span>)</span>
<span id="cb2-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_dimensions</span>(dnb)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>delta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> delta</span>
<span id="cb2-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_dimensions</span>(dnb)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>offset <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> west</span>
<span id="cb2-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_dimensions</span>(dnb)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>delta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>delta</span>
<span id="cb2-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_dimensions</span>(dnb)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>offset <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> north</span>
<span id="cb2-34">  </span>
<span id="cb2-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(dnb)</span>
<span id="cb2-36">}</span></code></pre></div>
</details>
</section>
<section id="read-in-day-night-band-dnb-data" class="level2">
<h2 class="anchored" data-anchor-id="read-in-day-night-band-dnb-data">Read in day night band (DNB) data</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">Feb_07_v5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_dnb</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/VNP46A1.A2021038.h08v05.001.2021039064328.h5"</span>)</span></code></pre></div>
</details>
<pre><code>//HDFEOS/GRIDS/VNP_Grid_DNB/Data_Fields/DNB_At_Sensor_Radiance_500m, </code></pre>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">Feb_07_v6 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_dnb</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/VNP46A1.A2021038.h08v06.001.2021039064329.h5"</span>)</span></code></pre></div>
</details>
<pre><code>//HDFEOS/GRIDS/VNP_Grid_DNB/Data_Fields/DNB_At_Sensor_Radiance_500m, </code></pre>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">Feb_16_v5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_dnb</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/VNP46A1.A2021047.h08v05.001.2021048091106.h5"</span>)</span></code></pre></div>
</details>
<pre><code>//HDFEOS/GRIDS/VNP_Grid_DNB/Data_Fields/DNB_At_Sensor_Radiance_500m, </code></pre>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">Feb_16_v6 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_dnb</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/VNP46A1.A2021047.h08v06.001.2021048091105.h5"</span>)</span></code></pre></div>
</details>
<pre><code>//HDFEOS/GRIDS/VNP_Grid_DNB/Data_Fields/DNB_At_Sensor_Radiance_500m, </code></pre>
</section>
<section id="combine-adjacent-tiles-for-each-date" class="level2">
<h2 class="anchored" data-anchor-id="combine-adjacent-tiles-for-each-date">Combine adjacent tiles for each date</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">Feb_07_v5_v6 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_mosaic</span>(Feb_07_v5, Feb_07_v6)</span>
<span id="cb11-2">Feb_16_v5_v6 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_mosaic</span>(Feb_16_v5, Feb_16_v6)</span></code></pre></div>
</details>
</section>
<section id="create-blackout-mask" class="level2">
<h2 class="anchored" data-anchor-id="create-blackout-mask">Create blackout Mask</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Take the difference of light data from before the storm and after the storm to make a mask of values with a difference greater than 200 nW cm-2 sr-1</span></span>
<span id="cb12-2">diff <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (Feb_07_v5_v6 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> Feb_16_v5_v6) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span></span>
<span id="cb12-3"></span>
<span id="cb12-4"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Convert values with a difference of less than 200 to NA</span></span>
<span id="cb12-5">diff[diff <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> F] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span></code></pre></div>
</details>
</section>
<section id="vectorize-blackout-mask" class="level2">
<h2 class="anchored" data-anchor-id="vectorize-blackout-mask">Vectorize blackout mask</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">blackout_mask <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_as_sf</span>(diff)</span>
<span id="cb13-2"></span>
<span id="cb13-3"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Fix invalid geometries </span></span>
<span id="cb13-4">blackout_mask_fixed <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_make_valid</span>(blackout_mask)</span>
<span id="cb13-5"></span>
<span id="cb13-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rm</span>(diff, blackout_mask)</span>
<span id="cb13-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gc</span>()</span></code></pre></div>
</details>
<pre><code>           used  (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells  3047944 162.8    4503170  240.5   4503170  240.5
Vcells 27482570 209.7  132454492 1010.6 156217946 1191.9</code></pre>
</section>
<section id="crop-the-vectorized-blackout-mask-to-the-region-of-interest" class="level2">
<h2 class="anchored" data-anchor-id="crop-the-vectorized-blackout-mask-to-the-region-of-interest">Crop the vectorized blackout mask to the region of interest</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Set region of interest</span></span>
<span id="cb15-2">houston <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_polygon</span>(</span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb15-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(</span>
<span id="cb15-5">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">96.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">29</span>), </span>
<span id="cb15-6">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">96.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">30.5</span>), </span>
<span id="cb15-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">94.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">30.5</span>), </span>
<span id="cb15-8">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">94.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">29</span>), </span>
<span id="cb15-9">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">96.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">29</span>)</span>
<span id="cb15-10">    )</span>
<span id="cb15-11">  )</span>
<span id="cb15-12">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_sfc</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4326</span>)</span>
<span id="cb15-14"></span>
<span id="cb15-15"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Crop night lights data</span></span>
<span id="cb15-16">intersects <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_intersects</span>(blackout_mask_fixed, houston, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sparse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb15-17">blackout_cropped <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> blackout_mask_fixed[intersects,]</span>
<span id="cb15-18"></span>
<span id="cb15-19"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## Transform cropped blackout mask back to EPSG:3083 (NAD83 / Texas Centric Albers Equal Area)</span></span>
<span id="cb15-20">blackout_cropped_NAD83 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_transform</span>(blackout_cropped, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3083</span>)</span>
<span id="cb15-21"></span>
<span id="cb15-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rm</span>(blackout_cropped)</span>
<span id="cb15-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gc</span>()</span></code></pre></div>
</details>
<pre><code>           used  (Mb) gc trigger  (Mb)  max used   (Mb)
Ncells  3020703 161.4    4503170 240.5   4503170  240.5
Vcells 27554636 210.3  105963594 808.5 156217946 1191.9</code></pre>
</section>
<section id="sanity-check-plot" class="level2">
<h2 class="anchored" data-anchor-id="sanity-check-plot">Sanity check plot</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> blackout_cropped_NAD83) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>()</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-houston-blackout-analysis-2021/figures/sanity-check-plot-1.png" width="624"></p>
</section>
<section id="roads-data" class="level2">
<h2 class="anchored" data-anchor-id="roads-data">Roads data</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1">query <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb18-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SELECT * </span></span>
<span id="cb18-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">   FROM gis_osm_roads_free_1 </span></span>
<span id="cb18-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">   WHERE fclass='motorway'"</span></span>
<span id="cb18-5"></span>
<span id="cb18-6">highways <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb18-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_read</span>(</span>
<span id="cb18-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/gis_osm_roads_free_1.gpkg"</span>, </span>
<span id="cb18-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">query =</span> query) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_transform</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3083</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_buffer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dist =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_union</span>()</span></code></pre></div>
</details>
<pre><code>Reading query `SELECT * 
   FROM gis_osm_roads_free_1 
   WHERE fclass='motorway'' from data source `C:\Users\Cullen\OneDrive\Documents\MEDS\cullen-molitor.github.io\_posts\2021-12-03-houston-blackout-analysis-2021\data\gis_osm_roads_free_1.gpkg' 
  using driver `GPKG'
Simple feature collection with 6085 features and 10 fields
Geometry type: LINESTRING
Dimension:     XY
Bounding box:  xmin: -96.50429 ymin: 29.00174 xmax: -94.39619 ymax: 30.50886
Geodetic CRS:  WGS 84</code></pre>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\n\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">After Transforming</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span></code></pre></div>
</details>
<pre><code>After Transforming</code></pre>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1">highways</span></code></pre></div>
</details>
<pre><code>Geometry set for 1 feature 
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 1837420 ymin: 7218299 xmax: 2040621 ymax: 7387049
Projected CRS: NAD83 / Texas Centric Albers Equal Area</code></pre>
</section>
<section id="basic-highways-plot" class="level2">
<h2 class="anchored" data-anchor-id="basic-highways-plot">Basic highways plot</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> highways) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>()</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-houston-blackout-analysis-2021/figures/unnamed-chunk-1-1.png" width="624"></p>
</section>
<section id="buildings-data" class="level2">
<h2 class="anchored" data-anchor-id="buildings-data">Buildings data</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1">query <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb25-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SELECT * </span></span>
<span id="cb25-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">   FROM gis_osm_buildings_a_free_1</span></span>
<span id="cb25-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">   WHERE (type IS NULL AND name IS NULL)</span></span>
<span id="cb25-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">   OR type in ('residential', 'apartments', 'house', 'static_caravan', 'detached')"</span></span>
<span id="cb25-6"></span>
<span id="cb25-7">buildings <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb25-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_read</span>(</span>
<span id="cb25-9">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/gis_osm_buildings_a_free_1.gpkg"</span>, </span>
<span id="cb25-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">query =</span> query) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb25-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_transform</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3083</span>) </span></code></pre></div>
</details>
<pre><code>Reading query `SELECT * 
   FROM gis_osm_buildings_a_free_1
   WHERE (type IS NULL AND name IS NULL)
   OR type in ('residential', 'apartments', 'house', 'static_caravan', 'detached')' from data source `C:\Users\Cullen\OneDrive\Documents\MEDS\cullen-molitor.github.io\_posts\2021-12-03-houston-blackout-analysis-2021\data\gis_osm_buildings_a_free_1.gpkg' 
  using driver `GPKG'
Simple feature collection with 475941 features and 5 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -96.50055 ymin: 29.00344 xmax: -94.53285 ymax: 30.50393
Geodetic CRS:  WGS 84</code></pre>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\n\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">After Transforming</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span></code></pre></div>
</details>
<pre><code>After Transforming</code></pre>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1">buildings</span></code></pre></div>
</details>
<pre><code>Simple feature collection with 475941 features and 5 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 1838180 ymin: 7216470 xmax: 2027040 ymax: 7386914
Projected CRS: NAD83 / Texas Centric Albers Equal Area
First 10 features:
     osm_id code   fclass name       type
1  15289727 1500 building &lt;NA&gt;       &lt;NA&gt;
2  15289869 1500 building &lt;NA&gt;       &lt;NA&gt;
3  15299261 1500 building &lt;NA&gt; apartments
4  15331425 1500 building &lt;NA&gt;       &lt;NA&gt;
5  15349970 1500 building &lt;NA&gt;       &lt;NA&gt;
6  20868178 1500 building &lt;NA&gt;       &lt;NA&gt;
7  20871848 1500 building &lt;NA&gt;       &lt;NA&gt;
8  20871948 1500 building &lt;NA&gt;       &lt;NA&gt;
9  20876080 1500 building &lt;NA&gt;       &lt;NA&gt;
10 20877241 1500 building &lt;NA&gt;       &lt;NA&gt;
                             geom
1  MULTIPOLYGON (((1948074 728...
2  MULTIPOLYGON (((1927251 732...
3  MULTIPOLYGON (((1984491 730...
4  MULTIPOLYGON (((1932443 731...
5  MULTIPOLYGON (((1925238 732...
6  MULTIPOLYGON (((1922763 727...
7  MULTIPOLYGON (((1922899 727...
8  MULTIPOLYGON (((1922788 727...
9  MULTIPOLYGON (((1922699 727...
10 MULTIPOLYGON (((1922807 727...</code></pre>
</section>
<section id="census-data" class="level2">
<h2 class="anchored" data-anchor-id="census-data">Census data</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># st_layers("ACS_2019_5YR_TRACT_48_TEXAS.gdb"))</span></span>
<span id="cb31-2"></span>
<span id="cb31-3">acs_geoms <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb31-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_read</span>(</span>
<span id="cb31-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/ACS_2019_5YR_TRACT_48_TEXAS.gdb"</span>,</span>
<span id="cb31-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">layer =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ACS_2019_5YR_TRACT_48_TEXAS"</span></span>
<span id="cb31-7">  )</span></code></pre></div>
</details>
<pre><code>Reading layer `ACS_2019_5YR_TRACT_48_TEXAS' from data source 
  `C:\Users\Cullen\OneDrive\Documents\MEDS\cullen-molitor.github.io\_posts\2021-12-03-houston-blackout-analysis-2021\data\ACS_2019_5YR_TRACT_48_TEXAS.gdb' 
  using driver `OpenFileGDB'
Simple feature collection with 5265 features and 15 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -106.6456 ymin: 25.83716 xmax: -93.50804 ymax: 36.5007
Geodetic CRS:  NAD83</code></pre>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1">acs_income <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb33-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_read</span>(</span>
<span id="cb33-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/ACS_2019_5YR_TRACT_48_TEXAS.gdb"</span>,</span>
<span id="cb33-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">layer =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X19_INCOME"</span></span>
<span id="cb33-5">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(GEOID, B19013e1) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GEOID_Data =</span> GEOID,</span>
<span id="cb33-8">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">median_income =</span> B19013e1)</span></code></pre></div>
</details>
<pre><code>Reading layer `X19_INCOME' from data source 
  `C:\Users\Cullen\OneDrive\Documents\MEDS\cullen-molitor.github.io\_posts\2021-12-03-houston-blackout-analysis-2021\data\ACS_2019_5YR_TRACT_48_TEXAS.gdb' 
  using driver `OpenFileGDB'</code></pre>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1">acs_geoms_med <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(acs_geoms, acs_income)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb35-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_transform</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3083</span>) </span></code></pre></div>
</details>
</section>
<section id="merge-datasets" class="level2">
<h2 class="anchored" data-anchor-id="merge-datasets">Merge datasets</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1">blackout_no_hwy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_difference</span>(blackout_cropped_NAD83, highways)</span>
<span id="cb36-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rm</span>(highways)</span>
<span id="cb36-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gc</span>()</span></code></pre></div>
</details>
<pre><code>           used  (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells  7126649 380.7   20004878 1068.4  20004878 1068.4
Vcells 56415877 430.5  105963594  808.5 156217946 1191.9</code></pre>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1">houston_res_wo_power <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> buildings[blackout_no_hwy, op <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> st_intersects]</span>
<span id="cb38-2">number_houses_wo_power <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(houston_res_wo_power<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>osm_id)</span></code></pre></div>
</details>
</section>
<section id="the-number-of-buildings-that-were-left-without-power-is-157411." class="level2">
<h2 class="anchored" data-anchor-id="the-number-of-buildings-that-were-left-without-power-is-157411.">The number of buildings that were left without power is 157411.</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1">acs_building <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_join</span>(houston_res_wo_power, acs_geoms_med, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">join =</span> st_intersects)</span></code></pre></div>
</details>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1">acs_polygon <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_join</span>(blackout_no_hwy, acs_geoms_med, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">join =</span> st_intersects)</span></code></pre></div>
</details>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1">houston_bbox <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_bbox</span>(houston)</span>
<span id="cb41-2">houston_map <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">osm.raster</span>(houston_bbox)</span></code></pre></div>
</details>
</section>
<section id="area-and-median-incomes-of-residences-affected-by-houston-blackout-in-february-2021" class="level2">
<h2 class="anchored" data-anchor-id="area-and-median-incomes-of-residences-affected-by-houston-blackout-in-february-2021">Area and Median Incomes of Residences Affected by Houston Blackout in February, 2021</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_shape</span>(houston_map) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_rgb</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">75</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-3">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># tm_shape(acs_geoms_med,</span></span>
<span id="cb42-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#          border.alpha = 0) +</span></span>
<span id="cb42-5">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># tm_polygons(col = "median_income") +</span></span>
<span id="cb42-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_shape</span>(blackout_no_hwy) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_polygons</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">border.alpha =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_shape</span>(acs_polygon) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb42-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_fill</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"median_income"</span>, </span>
<span id="cb42-10">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, </span>
<span id="cb42-11">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pretty"</span>,</span>
<span id="cb42-12">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median Income ($)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_compass</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tm_scale_bar</span>()</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-houston-blackout-analysis-2021/figures/unnamed-chunk-8-1.png" width="624"></p>
<p>This map was created by Amber McEldowney and Cullen Molitor 2021-10-24.<br>
<strong>Sources</strong>: Socioeconomic data: U.S. Census Bureau’s American Community Survey for Texas census tracts in 2019<br>
Light data: NASA’s Level-1 and Atmosphere Archive &amp; Distribution System Distributed Active Archive Center (LAADS DAAC)<br>
Spatial &amp; Buildings Data: OpenStreetMap</p>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb43" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rm</span>(blackout_cropped_NAD83, acs_geoms, acs_income, buildings)</span>
<span id="cb43-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gc</span>()</span></code></pre></div>
</details>
<pre><code>           used  (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells  4929805 263.3   16003903  854.8  20004878 1068.4
Vcells 46664452 356.1  152763574 1165.5 156217946 1191.9</code></pre>
</section>
<section id="histogram-of-median-income-for-houses-affected-by-blackout" class="level2">
<h2 class="anchored" data-anchor-id="histogram-of-median-income-for-houses-affected-by-blackout">Histogram of Median Income for Houses Affected by Blackout</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb45" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb45-1">Median_Income <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> acs_polygon<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>median_income</span>
<span id="cb45-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hist</span>(Median_Income,</span>
<span id="cb45-3"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median Income in Regions Affected by Blackout"</span>,</span>
<span id="cb45-4"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median Income ($)"</span>,</span>
<span id="cb45-5"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of Households"</span>,</span>
<span id="cb45-6"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>,</span>
<span id="cb45-7"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">freq=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb45-8">)</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-houston-blackout-analysis-2021/figures/unnamed-chunk-10-1.png" width="624"></p>
</section>
<section id="histogram-of-median-income-in-houston" class="level2">
<h2 class="anchored" data-anchor-id="histogram-of-median-income-in-houston">Histogram of Median Income in Houston</h2>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1">houston_nad <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> houston <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb46-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_as_sf</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb46-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_transform</span>(houston, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3083</span>)</span>
<span id="cb46-4"></span>
<span id="cb46-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># acs_geoms_med_bb &lt;- st_join(acs_geoms_med, houston_nad, join = st_intersects)</span></span>
<span id="cb46-6"></span>
<span id="cb46-7">intersects <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">st_intersects</span>(acs_geoms_med, houston_nad, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sparse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb46-8">acs_geoms_med_bb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> acs_geoms_med[intersects,]</span>
<span id="cb46-9"></span>
<span id="cb46-10">Median_Income_Houston <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> acs_geoms_med_bb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>median_income</span>
<span id="cb46-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hist</span>(Median_Income_Houston,</span>
<span id="cb46-12"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median Income in Houston"</span>,</span>
<span id="cb46-13"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median Income ($)"</span>,</span>
<span id="cb46-14"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of Households"</span>,</span>
<span id="cb46-15"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>,</span>
<span id="cb46-16"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">freq=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb46-17">)</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-houston-blackout-analysis-2021/figures/unnamed-chunk-11-1.png" width="624"></p>
<p>We thought it would be interesting to compare the median incomes of households affected by the blackout, to median incomes in Houston in general, but because the blackouts seem to have occured in a more metropolitan area, it is likely the incomes are skewed higher for that area, and it does not give a clear indication of whether median income had an effect on whether or not a household experienced a blackout.</p>
<div class="sourceCode" id="cb47" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>

 ]]></description>
  <category>R</category>
  <category>Remote Sensing</category>
  <category>Spatial Analysis</category>
  <guid>https://cullen-molitor.github.io/posts/2021-12-03-houston-blackout-analysis-2021/</guid>
  <pubDate>Fri, 03 Dec 2021 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2021-12-03-houston-blackout-analysis-2021/figures/unnamed-chunk-8-1.png" medium="image" type="image/png" height="89" width="144"/>
</item>
<item>
  <title>Iowa’s Wind Power Potential</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2021-12-03-iowas-wind-power-potential/</link>
  <description><![CDATA[ 





<section id="import-modules" class="level2">
<h2 class="anchored" data-anchor-id="import-modules">Import Modules</h2>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> sqlalchemy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> sa</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> geopandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> gpd</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb1-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb1-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> contextily <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> ctx</span>
<span id="cb1-6"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> math</span>
<span id="cb1-7"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span>matplotlib inline</span></code></pre></div>
</section>
<section id="database-connection" class="level2">
<h2 class="anchored" data-anchor-id="database-connection">Database Connection</h2>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">pg_uri_template <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'postgresql+psycopg2://</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{user}</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">:</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{pwd}</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">@</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{host}</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{db_name}</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span></span>
<span id="cb2-2">db_uri <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pg_uri_template.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">format</span>(</span>
<span id="cb2-3">    drivername<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'postgresql+psycopg2'</span>,</span>
<span id="cb2-4">    host <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'{ip address}'</span>,</span>
<span id="cb2-5">    user <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{username}</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>,</span>
<span id="cb2-6">    pwd <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{pwd}</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>,</span>
<span id="cb2-7">    db_name <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'osmiowa'</span></span>
<span id="cb2-8">)</span>
<span id="cb2-9">engine <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sa.create_engine(db_uri)</span></code></pre></div>
</section>
<section id="data-details" class="level2">
<h2 class="anchored" data-anchor-id="data-details">Data Details</h2>
<p>Database Name: - osmiowa</p>
<p>Database Tables: - planet_osm_line - planet_osm_point - planet_osm_polygon - planet_osm_roads - spatial_ref_sys - wind - wind_cells</p>
<p>Geometry: - Projected in <a href="https://epsg.io/26975">EPSG:26975</a> - Geodetic CRS: NAD83 - Units: meters - Coordinate system: Cartesian 2D CS - Axes: easting, northing (X,Y) - Orientations: east, north</p>
</section>
<section id="query-database" class="level1">
<h1>Query Database</h1>
<p>Residential Scenario 1 (3H)</p>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1">sql_buildings_residential_1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb3-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT </span></span>
<span id="cb3-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ST_BUFFER(way, 450) as way</span></span>
<span id="cb3-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb3-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_polygon </span></span>
<span id="cb3-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb3-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    building IN ('yes', 'residential', 'apartments', 'house', 'static_caravan', 'detached')</span></span>
<span id="cb3-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">OR </span></span>
<span id="cb3-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    landuse = 'residential'</span></span>
<span id="cb3-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">OR </span></span>
<span id="cb3-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    place = 'town'</span></span>
<span id="cb3-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Residential Scenario 2 (10H)</p>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">sql_buildings_residential_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb4-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb4-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT </span></span>
<span id="cb4-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ST_BUFFER(way, 1500) as way </span></span>
<span id="cb4-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb4-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_polygon </span></span>
<span id="cb4-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb4-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    building </span></span>
<span id="cb4-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">IN </span></span>
<span id="cb4-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ('yes', 'residential', 'apartments', 'house', 'static_caravan', 'detached')</span></span>
<span id="cb4-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">OR </span></span>
<span id="cb4-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    landuse = 'residential'</span></span>
<span id="cb4-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">OR</span></span>
<span id="cb4-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    place = 'town'</span></span>
<span id="cb4-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Non-residential (3H)</p>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1">sql_buildings_nonresidential <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb5-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb5-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT </span></span>
<span id="cb5-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ST_BUFFER(way, 450) as way</span></span>
<span id="cb5-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb5-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_polygon </span></span>
<span id="cb5-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb5-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    building </span></span>
<span id="cb5-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">NOT IN </span></span>
<span id="cb5-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ('yes', 'residential', 'apartments', 'house', 'static_caravan', 'detached')</span></span>
<span id="cb5-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Airports</p>
<div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1">sql_airports <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb6-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb6-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT </span></span>
<span id="cb6-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ST_BUFFER(way, 7500) as way</span></span>
<span id="cb6-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb6-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_polygon </span></span>
<span id="cb6-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb6-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    aeroway IS NOT NULL</span></span>
<span id="cb6-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Military Bases</p>
<div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1">sql_military <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb7-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb7-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT </span></span>
<span id="cb7-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ST_BUFFER(way, 0) as way </span></span>
<span id="cb7-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb7-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_polygon </span></span>
<span id="cb7-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb7-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    military IS NOT NULL</span></span>
<span id="cb7-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">OR </span></span>
<span id="cb7-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    landuse = 'military'</span></span>
<span id="cb7-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Railways and Roads</p>
<div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1">sql_railways_n_roads <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb8-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb8-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT </span></span>
<span id="cb8-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ST_BUFFER(way, 300) as way</span></span>
<span id="cb8-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb8-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_line </span></span>
<span id="cb8-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb8-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    (railway IS NOT NULL</span></span>
<span id="cb8-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">     AND railway </span></span>
<span id="cb8-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">     NOT IN ('abandoned', 'disused', 'razed', 'dismantled'))</span></span>
<span id="cb8-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">OR </span></span>
<span id="cb8-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    (highway IS NOT NULL</span></span>
<span id="cb8-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">AND </span></span>
<span id="cb8-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    highway </span></span>
<span id="cb8-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">IN </span></span>
<span id="cb8-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ('motorway', 'motorway_link', 'trunk', 'trunk_link', 'road',</span></span>
<span id="cb8-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    'primary', 'primary_link', 'secondary', 'secondary_link'))</span></span>
<span id="cb8-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Nature Reserves, Parks, and Wetlands</p>
<div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1">sql_nature <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb9-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb9-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT </span></span>
<span id="cb9-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    way </span></span>
<span id="cb9-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb9-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_polygon </span></span>
<span id="cb9-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb9-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    leisure </span></span>
<span id="cb9-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">IN </span></span>
<span id="cb9-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ('nature_reserve', 'park')</span></span>
<span id="cb9-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">OR</span></span>
<span id="cb9-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "natural" </span></span>
<span id="cb9-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">IN </span></span>
<span id="cb9-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ('wetland')</span></span>
<span id="cb9-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Rivers</p>
<div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1">sql_rivers <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb10-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb10-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT </span></span>
<span id="cb10-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ST_BUFFER(way, 150) as way </span></span>
<span id="cb10-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb10-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_line </span></span>
<span id="cb10-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb10-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    waterway </span></span>
<span id="cb10-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">IN </span></span>
<span id="cb10-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ('river')</span></span>
<span id="cb10-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Lakes</p>
<div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1">sql_lakes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb11-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb11-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT</span></span>
<span id="cb11-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    way</span></span>
<span id="cb11-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb11-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_polygon</span></span>
<span id="cb11-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb11-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    water </span></span>
<span id="cb11-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">IN </span></span>
<span id="cb11-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ('lake', 'reservoir', 'pond')</span></span>
<span id="cb11-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Power Lines</p>
<div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1">sql_powerlines <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb12-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb12-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT </span></span>
<span id="cb12-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ST_BUFFER(way, 300) as way</span></span>
<span id="cb12-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb12-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_line </span></span>
<span id="cb12-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb12-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    power IS NOT NULL</span></span>
<span id="cb12-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Power Plants</p>
<div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1">sql_powerplants <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb13-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb13-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT </span></span>
<span id="cb13-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ST_BUFFER(way, 150) as way</span></span>
<span id="cb13-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb13-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_polygon </span></span>
<span id="cb13-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb13-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    power IS NOT NULL</span></span>
<span id="cb13-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<p>Wind Turbines</p>
<div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb14-1">sql_turbines <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb14-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb14-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT</span></span>
<span id="cb14-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ST_BUFFER(way, 680) as way</span></span>
<span id="cb14-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb14-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    planet_osm_point </span></span>
<span id="cb14-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb14-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "generator:source" IS NOT NULL</span></span>
<span id="cb14-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">AND </span></span>
<span id="cb14-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    "generator:source" IN ('wind')</span></span>
<span id="cb14-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span></code></pre></div>
<section id="merge-subqueries" class="level2">
<h2 class="anchored" data-anchor-id="merge-subqueries">Merge Subqueries</h2>
<section id="scenario-1" class="level3">
<h3 class="anchored" data-anchor-id="scenario-1">Scenario 1</h3>
<div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1">sql_siting_constraints <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb15-2"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"""</span></span>
<span id="cb15-3"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_buildings_residential_1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb15-4"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb15-5"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_buildings_nonresidential<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb15-6"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb15-7"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_airports<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb15-8"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb15-9"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_military<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb15-10"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb15-11"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_railways_n_roads<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb15-12"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb15-13"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_nature<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb15-14"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb15-15"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_rivers<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb15-16"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb15-17"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_lakes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb15-18"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb15-19"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_powerlines<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb15-20"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb15-21"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_powerplants<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb15-22"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb15-23"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_turbines<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb15-24"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb15-25">siting_constraints <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.read_postgis(sql_siting_constraints, con <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> engine, geom_col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'way'</span>)</span></code></pre></div>
</section>
<section id="scenario-2" class="level3">
<h3 class="anchored" data-anchor-id="scenario-2">Scenario 2</h3>
<div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1">sql_siting_constraints_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb16-2"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"""</span></span>
<span id="cb16-3"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_buildings_residential_2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb16-4"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb16-5"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_buildings_nonresidential<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb16-6"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb16-7"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_airports<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb16-8"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb16-9"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_military<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb16-10"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb16-11"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_railways_n_roads<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb16-12"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb16-13"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_nature<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb16-14"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb16-15"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_rivers<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb16-16"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb16-17"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_lakes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb16-18"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb16-19"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_powerlines<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb16-20"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb16-21"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_powerplants<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb16-22"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">UNION</span></span>
<span id="cb16-23"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>sql_turbines<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb16-24"><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb16-25">siting_constraints_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.read_postgis(sql_siting_constraints_2, con <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> engine, geom_col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'way'</span>)</span></code></pre></div>
<div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>))</span>
<span id="cb17-2">siting_constraints.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, markersize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.1</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>, alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.5</span>)</span>
<span id="cb17-3">ax.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimgray'</span>)</span>
<span id="cb17-4">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Siting Constraints (Scenario 1)'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)</span>
<span id="cb17-5">ax.ticklabel_format(scilimits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb17-6">ctx.add_basemap(ax, crs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EPSG:26975"</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-iowas-wind-power-potential/output_40_0.png" class="img-fluid"></p>
<div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb18-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>))</span>
<span id="cb18-2">siting_constraints_2.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, markersize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.1</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>, alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.5</span>)</span>
<span id="cb18-3">ax.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimgray'</span>)</span>
<span id="cb18-4">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Siting Constraints (Scenario 2)'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)</span>
<span id="cb18-5">ax.ticklabel_format(scilimits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb18-6">ctx.add_basemap(ax, crs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EPSG:26975"</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-iowas-wind-power-potential/output_41_0.png" class="img-fluid"></p>
</section>
</section>
<section id="wind-data" class="level2">
<h2 class="anchored" data-anchor-id="wind-data">Wind Data</h2>
<p>The table wind_cells_10000 contains 10 km2 square polygons with associated average annual wind speeds (m s-1), arranged to cover Iowa in a ragged grid.</p>
<div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-1">sql_wind_speeds <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb19-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb19-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">SELECT * </span></span>
<span id="cb19-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">FROM </span></span>
<span id="cb19-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    wind_cells_10000 </span></span>
<span id="cb19-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">WHERE </span></span>
<span id="cb19-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    wind_speed IS NOT NULL</span></span>
<span id="cb19-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"""</span></span>
<span id="cb19-9">wind_speeds <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gpd.read_postgis(sql_wind_speeds, con <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> engine, geom_col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'geom'</span>)</span></code></pre></div>
</section>
</section>
<section id="results" class="level1">
<h1>Results</h1>
<section id="scenario-1-1" class="level2">
<h2 class="anchored" data-anchor-id="scenario-1-1">Scenario #1</h2>
<section id="subtract-siting-constraints-from-wind-cells" class="level3">
<h3 class="anchored" data-anchor-id="subtract-siting-constraints-from-wind-cells">Subtract Siting Constraints from Wind Cells</h3>
<div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb20-1">suitable_cells <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> wind_speeds.overlay(siting_constraints, how <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'difference'</span>, keep_geom_type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span></code></pre></div>
</section>
<section id="plot-suitable-wind-cells" class="level3">
<h3 class="anchored" data-anchor-id="plot-suitable-wind-cells">Plot Suitable Wind Cells</h3>
<div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb21-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>))</span>
<span id="cb21-2">suitable_cells.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, markersize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.1</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>, alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.5</span>)</span>
<span id="cb21-3">ax.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimgray'</span>)</span>
<span id="cb21-4">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Suitable Areas (Scenario 1)'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)</span>
<span id="cb21-5">ax.ticklabel_format(scilimits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb21-6">ctx.add_basemap(ax, crs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EPSG:26975"</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-iowas-wind-power-potential/output_47_0.png" class="img-fluid"></p>
</section>
<section id="find-number-of-turbines" class="level3">
<h3 class="anchored" data-anchor-id="find-number-of-turbines">Find Number of Turbines</h3>
<div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb22-1">rotor_5x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> math.pi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">136</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb22-2">suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"area"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'geom'</span>].area</span>
<span id="cb22-3">suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"number_wind_turbines"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'geom'</span>].area <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> rotor_5x</span></code></pre></div>
<div class="sourceCode" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb23-1">total_wind_turbines <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"number_wind_turbines"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb23-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The total number of turbines in scenario 1 is:"</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(total_wind_turbines))</span></code></pre></div>
<pre><code>The total number of turbines in scenario 1 is: 57286</code></pre>
</section>
<section id="power-production" class="level3">
<h3 class="anchored" data-anchor-id="power-production">Power production</h3>
<div class="sourceCode" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb25-1">suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'energy_per_turbine'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'wind_speed'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span></span>
<span id="cb25-2">suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'power_per_cell'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'energy_per_turbine'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'number_wind_turbines'</span>]</span></code></pre></div>
</section>
<section id="total-power-production" class="level3">
<h3 class="anchored" data-anchor-id="total-power-production">Total Power Production</h3>
<div class="sourceCode" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb26-1">total_scenario_1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> suitable_cells[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'power_per_cell'</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb26-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The total power produced in scenario 1 is:"</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(total_scenario_1), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GWH/year"</span>)</span></code></pre></div>
<pre><code>The total power produced in scenario 1 is: 1064159 GWH/year</code></pre>
</section>
</section>
<section id="scenario-2-1" class="level2">
<h2 class="anchored" data-anchor-id="scenario-2-1">Scenario #2</h2>
<section id="subtract-siting-constraints-from-wind-cells-1" class="level3">
<h3 class="anchored" data-anchor-id="subtract-siting-constraints-from-wind-cells-1">Subtract Siting Constraints from Wind Cells</h3>
<div class="sourceCode" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb28-1">suitable_cells_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> wind_speeds.overlay(siting_constraints_2, how <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'difference'</span>, keep_geom_type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span></code></pre></div>
</section>
<section id="plot-suitable-wind-cells-1" class="level3">
<h3 class="anchored" data-anchor-id="plot-suitable-wind-cells-1">Plot Suitable Wind Cells</h3>
<div class="sourceCode" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb29-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>))</span>
<span id="cb29-2">suitable_cells_2.plot(ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax, markersize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.1</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>, alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.5</span>)</span>
<span id="cb29-3">ax.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'dimgray'</span>)</span>
<span id="cb29-4">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Suitable Areas (Scenario 2)'</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)</span>
<span id="cb29-5">ax.ticklabel_format(scilimits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb29-6">ctx.add_basemap(ax, crs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EPSG:26975"</span>)</span></code></pre></div>
<p><img src="https://cullen-molitor.github.io/posts/2021-12-03-iowas-wind-power-potential/output_58_0.png" class="img-fluid"></p>
</section>
<section id="find-number-of-turbines-1" class="level3">
<h3 class="anchored" data-anchor-id="find-number-of-turbines-1">Find Number of Turbines</h3>
<div class="sourceCode" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb30-1">rotor_5x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> math.pi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">136</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb30-2">suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"area"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'geom'</span>].area</span>
<span id="cb30-3">suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"number_wind_turbines"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'geom'</span>].area <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> rotor_5x</span></code></pre></div>
<div class="sourceCode" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb31-1">total_wind_turbines_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"number_wind_turbines"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb31-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The total number of turbines in scenario 2 is:"</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(total_wind_turbines_2))</span></code></pre></div>
<pre><code>The total number of turbines in scenario 2 is: 52055</code></pre>
</section>
<section id="power-production-1" class="level3">
<h3 class="anchored" data-anchor-id="power-production-1">Power Production</h3>
<div class="sourceCode" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb33-1">suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'energy_per_turbine'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'wind_speed'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span></span>
<span id="cb33-2">suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'power_per_cell'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'energy_per_turbine'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'number_wind_turbines'</span>]</span>
<span id="cb33-3">wind_speeds</span></code></pre></div>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th style="text-align: left;">id</th>
<th style="text-align: left;">geom</th>
<th style="text-align: left;">wind_speed</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">POLYGON ((1256222.769 1212179.582, 1266222.769…</td>
<td style="text-align: left;">9.336039</td>
</tr>
<tr class="even">
<td>1</td>
<td style="text-align: left;">2</td>
<td style="text-align: left;">POLYGON ((1266222.769 1212179.582, 1276222.769…</td>
<td style="text-align: left;">9.097315</td>
</tr>
<tr class="odd">
<td>2</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">POLYGON ((1276222.769 1212179.582, 1286222.769…</td>
<td style="text-align: left;">8.984566</td>
</tr>
<tr class="even">
<td>3</td>
<td style="text-align: left;">4</td>
<td style="text-align: left;">POLYGON ((1286222.769 1212179.582, 1296222.769…</td>
<td style="text-align: left;">9.266137</td>
</tr>
<tr class="odd">
<td>4</td>
<td style="text-align: left;">5</td>
<td style="text-align: left;">POLYGON ((1296222.769 1212179.582, 1306222.769…</td>
<td style="text-align: left;">9.296747</td>
</tr>
<tr class="even">
<td>…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
<td style="text-align: left;">…</td>
</tr>
<tr class="odd">
<td>1437</td>
<td style="text-align: left;">1438</td>
<td style="text-align: left;">POLYGON ((1686222.769 902179.582, 1696222.769 …</td>
<td style="text-align: left;">8.678687</td>
</tr>
<tr class="even">
<td>1438</td>
<td style="text-align: left;">1439</td>
<td style="text-align: left;">POLYGON ((1426222.769 892179.582, 1436222.769 …</td>
<td style="text-align: left;">9.114730</td>
</tr>
<tr class="odd">
<td>1439</td>
<td style="text-align: left;">1440</td>
<td style="text-align: left;">POLYGON ((1656222.769 892179.582, 1666222.769 …</td>
<td style="text-align: left;">8.237385</td>
</tr>
<tr class="even">
<td>1440</td>
<td style="text-align: left;">1441</td>
<td style="text-align: left;">POLYGON ((1666222.769 892179.582, 1676222.769 …</td>
<td style="text-align: left;">8.423034</td>
</tr>
<tr class="odd">
<td>1441</td>
<td style="text-align: left;">1442</td>
<td style="text-align: left;">POLYGON ((1666222.769 882179.582, 1676222.769 …</td>
<td style="text-align: left;">8.109468</td>
</tr>
</tbody>
</table>
<p>1442 rows × 3 columns</p>
</section>
<section id="total-power-production-1" class="level3">
<h3 class="anchored" data-anchor-id="total-power-production-1">Total Power Production</h3>
<div class="sourceCode" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb34-1">total_scenario_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> suitable_cells_2[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'power_per_cell'</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb34-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The total power produced in scenario 2 is:"</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(total_scenario_2), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" GWH/year"</span>)</span></code></pre></div>
<pre><code>The total power produced in scenario 2 is: 967009  GWH/year</code></pre>
<div class="sourceCode" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>
</section>
</section>

 ]]></description>
  <category>Python</category>
  <category>SQL</category>
  <category>Spatial Analysis</category>
  <guid>https://cullen-molitor.github.io/posts/2021-12-03-iowas-wind-power-potential/</guid>
  <pubDate>Fri, 03 Dec 2021 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2021-12-03-iowas-wind-power-potential/output_58_0.png" medium="image" type="image/png" height="100" width="144"/>
</item>
<item>
  <title>Cartography in R</title>
  <dc:creator>Cullen Molitor</dc:creator>
  <link>https://cullen-molitor.github.io/posts/2021-11-29-cartography-in-r/</link>
  <description><![CDATA[ 





<section id="purpose" class="level2">
<h2 class="anchored" data-anchor-id="purpose">Purpose</h2>
<p>This notebook demonstrates how to work with geospatial data using the R software environment to make maps. I chose to plot the bathymetry around New Zealand. This project uses the R package <code>marmap</code> to querry NOAA databases to get the digital elevation model data. I then use a shapefile of the New Zealand coastlines to get better delineation between ocean and land.</p>
<section id="load-libraries" class="level3">
<h3 class="anchored" data-anchor-id="load-libraries">Load libraries</h3>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(sf)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(raster)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(here)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(marmap)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggspatial)</span></code></pre></div>
</details>
</section>
<section id="load-data" class="level3">
<h3 class="anchored" data-anchor-id="load-data">Load Data</h3>
<p>Use <code>marmap::getNOAA.bathy()</code> to load New Zealand bathymetry and elevation data directly from NOAA database and convert <code>bathy</code> object to <code>dataframe</code> for ggplot.</p>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">nz_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> marmap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getNOAA.bathy</span>(</span>
<span id="cb2-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lon1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">162</span>,</span>
<span id="cb2-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lon2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">180</span>,</span>
<span id="cb2-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lat1 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">33</span>,</span>
<span id="cb2-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lat2 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,</span>
<span id="cb2-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">resolution =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-8">  marmap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.raster</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-9">  raster<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rasterToPoints</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-10">  base<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-11">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(layer <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span></code></pre></div>
</details>
<p>Read in New Zealand coastlines with <code>sf::read_sf()</code> to read the shapefile containing the New Zealand coastline.</p>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">nz_coast <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sf<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_sf</span>(</span>
<span id="cb3-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/nz-coastlines-and-islands-polygons-topo-150k.shp"</span></span>
<span id="cb3-3">  )</span></code></pre></div>
</details>
</section>
<section id="plot-data" class="level3">
<h3 class="anchored" data-anchor-id="plot-data">Plot Data</h3>
<p>Use <code>ggplot()</code> to plot New Zealand coastline, bathymetric raster, and depth contours.</p>
<details>
<summary>
Show code
</summary>
<div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_raster</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> nz_df,</span>
<span id="cb4-3">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> layer)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_contour</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> nz_df,</span>
<span id="cb4-5">               <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">z =</span> layer), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey20"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> nz_coast,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey40"</span>, </span>
<span id="cb4-7">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_sf</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">162</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">180</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">33</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Depth (m)"</span>,</span>
<span id="cb4-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Longitude"</span>,</span>
<span id="cb4-11">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Latitude"</span>,</span>
<span id="cb4-12">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bathymetric Map of New Zealand"</span>,</span>
<span id="cb4-13">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> </span>
<span id="cb4-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"This map highlights the bathymetric data surrounding the coast of New Zealand.</span></span>
<span id="cb4-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Note that the scale on map varies by more than 10%, scale bar may be inaccurate.</span></span>
<span id="cb4-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">NA bathymetry values are reflected in white and can be seen in shallow coastal areas.</span></span>
<span id="cb4-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Source: (A) NOAA National Geophysical Data Center. 2009: ETOPO1 1 Arc-Minute </span></span>
<span id="cb4-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Global Relief Model. NOAA National Centers for Environmental Information. Accessed [2021-10-01]. </span></span>
<span id="cb4-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(B) New Zealand Coastline shapefile downloaded from https://data.linz.govt.nz/data/. Accessed [2021-10-01].</span></span>
<span id="cb4-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Map created by Cullen Molitor, Shelby Smith, and Amber McEldowney at the UCSB Bren School [2021-10-04]."</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-21">  ggspatial<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotation_scale</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">location =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"br"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-22">  ggspatial<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotation_north_arrow</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">which_north=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">location =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tl"</span> ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.border =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_rect</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>),</span>
<span id="cb4-25">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.caption =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))</span></code></pre></div>
</details>
<p><img src="https://cullen-molitor.github.io/posts/2021-11-29-cartography-in-r/figures/New-Zealand-plot-1.png" width="720"></p>
<div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r distill-force-highlighting-css code-with-copy"><code class="sourceCode r"></code></pre></div>


</section>
</section>

 ]]></description>
  <category>R</category>
  <category>Ocean Data</category>
  <category>Remote Sensing</category>
  <category>Spatial Analysis</category>
  <guid>https://cullen-molitor.github.io/posts/2021-11-29-cartography-in-r/</guid>
  <pubDate>Mon, 29 Nov 2021 08:00:00 GMT</pubDate>
  <media:content url="https://cullen-molitor.github.io/posts/2021-11-29-cartography-in-r/cartography.png" medium="image" type="image/png" height="148" width="144"/>
</item>
</channel>
</rss>
