{"id":2300,"date":"2016-09-06T17:20:45","date_gmt":"2016-09-07T00:20:45","guid":{"rendered":"http:\/\/lukemiller.org\/?p=2300"},"modified":"2016-09-06T17:20:45","modified_gmt":"2016-09-07T00:20:45","slug":"rtide-a-r-package-for-predicting-tide-heights-us-locations-only-currently","status":"publish","type":"post","link":"https:\/\/lukemiller.org\/index.php\/2016\/09\/rtide-a-r-package-for-predicting-tide-heights-us-locations-only-currently\/","title":{"rendered":"rtide: a R package for predicting tide heights (US locations only currently)"},"content":{"rendered":"<p>Joe Thorley at <a href=\"http:\/\/www.poissonconsulting.ca\/\" target=\"_blank\">Poisson Consulting <\/a>has released a new R package, <a href=\"https:\/\/CRAN.R-project.org\/package=rtide\" target=\"_blank\">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 href=\"http:\/\/tidesandcurrents.noaa.gov\/\" target=\"blank\">National Oceanic and Atmospheric Administration<\/a>. The author of the definitive open source tide prediction software, <a href=\"http:\/\/flaterco.com\/xtide\/index.html\" target=\"_blank\">XTide<\/a>, collates those harmonic data into a usable format, and we have harvested the data to create the <a href=\"https:\/\/cran.r-project.org\/package=rtide\" target=\"_blank\">rtide package<\/a> which operates in R without the need to have XTide installed.<\/p>\n<figure id=\"attachment_2303\" aria-describedby=\"caption-attachment-2303\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2303\" src=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2016\/09\/Example_Monterey_Harbor-300x263.jpg\" alt=\"An example tide prediction for Monterey Harbor, California, produced by rtide. \" width=\"300\" height=\"263\" srcset=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2016\/09\/Example_Monterey_Harbor-300x263.jpg 300w, https:\/\/lukemiller.org\/wp-content\/uploads\/2016\/09\/Example_Monterey_Harbor.jpg 600w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-2303\" class=\"wp-caption-text\">An example tide prediction for Monterey Harbor, California, produced by rtide.<\/figcaption><\/figure>\n<p>You can install and load the rtide package by simply running the following commands at your R console:<\/p>\n<pre lang=\"R\" colla=\"+\">install.packages('rtide') # run this one time to install the package on your computer\r\nlibrary(rtide) # use this command to load the package whenever you start a new R session\r\n<\/pre>\n<p>To generate a set of tide height predictions, use a command like the following:<\/p>\n<pre lang=\"R\" colla=\"+\">dat = tide_height('Monterey Harbor',from = as.Date('2016-09-05'), \r\n\t\tto = as.Date('2016-09-07'), minutes = 10, tz ='PST8PDT')\r\n<\/pre>\n<p>The results in <code>dat<\/code> will be a 3-column &#8216;tibble&#8217; (essentially a data frame) consisting of the<br \/>\nstation 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>\n<pre lang=\"R\" colla=\"+\">head(dat)  # show some of the resulting data\r\n\r\n# A tibble: 6 x 3\r\n                                Station            DateTime TideHeight\r\n                                  &lt;chr&gt;              &lt;time&gt;      &lt;dbl&gt;\r\n1 Monterey, Monterey Harbor, California 2016-09-05 00:00:00   1.207174\r\n2 Monterey, Monterey Harbor, California 2016-09-05 00:10:00   1.230523\r\n3 Monterey, Monterey Harbor, California 2016-09-05 00:20:00   1.251265\r\n4 Monterey, Monterey Harbor, California 2016-09-05 00:30:00   1.269248\r\n5 Monterey, Monterey Harbor, California 2016-09-05 00:40:00   1.284345\r\n6 Monterey, Monterey Harbor, California 2016-09-05 00:50:00   1.296448\r\n<\/pre>\n<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>\n<pre lang=\"R\" colla=\"+\">library(ggplot2)\r\nlibrary(scales) # for the date_format function\r\n\r\nggplot(data = dat, aes(x = DateTime, y = TideHeight)) + \r\n\t\tgeom_line() + \r\n\t\tscale_x_datetime(name = \"September 5-7, 2016\", \r\n\t\t\t\tlabels = date_format(\"%H:%M\", tz=\"PST8PDT\")) +\r\n\t\tscale_y_continuous(name = \"Tide Height (m)\") +\r\n\t\tggtitle(\"Monterey Harbor\")\r\n\r\n<\/pre>\n<p>The available sites for tide prediction can be found by calling the <code>tide_stations()<\/code> function. If you&#8217;re concerned about the accuracy of the predictions, you can always double-check them against the official NOAA tide predictions available on the <a href=\"http:\/\/tidesandcurrents.noaa.gov\/\" target=\"_blank\">http:\/\/tidesandcurrents.noaa.gov\/ <\/a>website.<\/p>\n<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&#8217;t hold your breath), but for the present time we are limited to providing predictions for the US.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Joe Thorley at Poisson Consulting has released a new R package, rtide, (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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[218,240],"tags":[58,261,255,153],"class_list":["post-2300","post","type-post","status-publish","format-standard","hentry","category-r-project","category-tide-prediction","tag-r-project","tag-rtide","tag-tide","tag-xtide"],"_links":{"self":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/2300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/comments?post=2300"}],"version-history":[{"count":10,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/2300\/revisions"}],"predecessor-version":[{"id":2312,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/2300\/revisions\/2312"}],"wp:attachment":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/media?parent=2300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/categories?post=2300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/tags?post=2300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}