<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/rtide-a-r-package-for-predicting-tide-heights-us-locations-only-currently/"></div></div><div><a data-url="https://www.r-bloggers.com/rtide-a-r-package-for-predicting-tide-heights-us-locations-only-currently/" data-counturl="https://www.r-bloggers.com/rtide-a-r-package-for-predicting-tide-heights-us-locations-only-currently/" data-count="horizontal" data-text="rtide: a R package for predicting tide heights (US locations only currently)" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://lukemiller.org/index.php/2016/09/rtide-a-r-package-for-predicting-tide-heights-us-locations-only-currently/"> R-project – lukemiller.org</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Joe Thorley at <a target="_blank" href="http://www.poissonconsulting.ca/">Poisson Consulting </a>has released a new R package, <a target="_blank" href="https://cran.r-project.org/package=rtide">rtide</a>, (on which I am listed as a co-author) that provides the ability to predict future (and past) tide heights for 637 different tide stations in the United States and associated territories. The underlying data, consisting of tide harmonic constituents, are collected and released by the <a target="_blank" href="http://tidesandcurrents.noaa.gov/">National Oceanic and Atmospheric Administration</a>. The author of the definitive open source tide prediction software, <a target="_blank" href="http://flaterco.com/xtide/index.html">XTide</a>, collates those harmonic data into a usable format, and we have harvested the data to create the <a target="_blank" href="https://cran.r-project.org/package=rtide">rtide package</a> which operates in R without the need to have XTide installed.</p>
<div class="wp-caption"><img sizes="(max-width: 300px) 100vw, 300px" alt="An example tide prediction for Monterey Harbor, California, produced by rtide. " class="wp-image-2303" src="https://i1.wp.com/lukemiller.org/wp-content/uploads/2016/09/Example_Monterey_Harbor-300x263.jpg?resize=300%2C263" data-recalc-dims="1">
<p class="wp-caption-text">An example tide prediction for Monterey Harbor, California, produced by rtide.</p>
</div>
<p>You can install and load the rtide package by simply running the following commands at your R console:</p>
<div><span><sup><a title="WP-CodeBox HowTo?" target="_blank" href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples"><span>?</span></a></sup></span><span><a target="_blank">View Code</a> R</span>
<div></div>
</div>
<div>
<table>
<tr>
<td>
<pre>install.packages('rtide') # run this one time to install the package on your computer
library(rtide) # use this command to load the package whenever you start a new R session</pre>
</td>
</tr>
</table>
</div>
<p>To generate a set of tide height predictions, use a command like the following:</p>
<div><span><sup><a title="WP-CodeBox HowTo?" target="_blank" href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples"><span>?</span></a></sup></span><span><a target="_blank">View Code</a> R</span>
<div></div>
</div>
<div>
<table>
<tr>
<td>
<pre>dat = tide_height('Monterey Harbor',from = as.Date('2016-09-05'), 
		to = as.Date('2016-09-07'), minutes = 10, tz ='PST8PDT')</pre>
</td>
</tr>
</table>
</div>
<p>The results in <code>dat</code> will be a 3-column ‘tibble’ (essentially a data frame) consisting of the<br>
station name (Monterey Harbor), the DateTime column (which should be in the given time zone, which we specified as Pacific Daylight Time), and TideHeight, which is in units of meters. The time step between estimates is declared by the minutes argument, and we set it to 10 minutes above.</p>
<div><span><sup><a title="WP-CodeBox HowTo?" target="_blank" href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples"><span>?</span></a></sup></span><span><a target="_blank">View Code</a> R</span>
<div></div>
</div>
<div>
<table>
<tr>
<td>
<pre>head(dat)  # show some of the resulting data
 
# A tibble: 6 x 3
                                Station            DateTime TideHeight
                                  &amp;lt;chr&amp;gt;              &amp;lt;time&amp;gt;      &amp;lt;dbl&amp;gt;
1 Monterey, Monterey Harbor, California 2016-09-05 00:00:00   1.207174
2 Monterey, Monterey Harbor, California 2016-09-05 00:10:00   1.230523
3 Monterey, Monterey Harbor, California 2016-09-05 00:20:00   1.251265
4 Monterey, Monterey Harbor, California 2016-09-05 00:30:00   1.269248
5 Monterey, Monterey Harbor, California 2016-09-05 00:40:00   1.284345
6 Monterey, Monterey Harbor, California 2016-09-05 00:50:00   1.296448</pre>
</td>
</tr>
</table>
</div>
<p>You could then use these predicted tide heights for any number of things, such as figuring out when your field site might be exposed or underwater at a given time, or making pretty plots of the tide cycle at your favorite location. The plot above was generated using the example data produced here and the code below:</p>
<div><span><sup><a title="WP-CodeBox HowTo?" target="_blank" href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples"><span>?</span></a></sup></span><span><a target="_blank">View Code</a> R</span>
<div></div>
</div>
<div>
<table>
<tr>
<td>
<pre>library(ggplot2)
library(scales) # for the date_format function
 
ggplot(data = dat, aes(x = DateTime, y = TideHeight)) + 
		geom_line() + 
		scale_x_datetime(name = &quot;September 5-7, 2016&quot;, 
				labels = date_format(&quot;%H:%M&quot;, tz=&quot;PST8PDT&quot;)) +
		scale_y_continuous(name = &quot;Tide Height (m)&quot;) +
		ggtitle(&quot;Monterey Harbor&quot;)</pre>
</td>
</tr>
</table>
</div>
<p>The available sites for tide prediction can be found by calling the <code>tide_stations()</code> function. If you’re concerned about the accuracy of the predictions, you can always double-check them against the official NOAA tide predictions available on the <a target="_blank" href="http://tidesandcurrents.noaa.gov/">http://tidesandcurrents.noaa.gov/ </a>website.</p>
<p>Some folks will be wondering whether rtide can produce predictions for other locations around the world (for instance, Canada). At the present time there is no facility to predict the tides for other countries, primarily because other countries do not release their tidal harmonic data into the public domain like the US does. Hopefully this will be rectified in the future via legislative action (don’t hold your breath), but for the present time we are limited to providing predictions for the US.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/rtide-a-r-package-for-predicting-tide-heights-us-locations-only-currently/"></div></div><div><a data-url="https://www.r-bloggers.com/rtide-a-r-package-for-predicting-tide-heights-us-locations-only-currently/" data-counturl="https://www.r-bloggers.com/rtide-a-r-package-for-predicting-tide-heights-us-locations-only-currently/" data-count="vertical" data-text="rtide: a R package for predicting tide heights (US locations only currently)" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://lukemiller.org/index.php/2016/09/rtide-a-r-package-for-predicting-tide-heights-us-locations-only-currently/"> R-project – lukemiller.org</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/8-pVJCL1L68"></a></div>