Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
| Download

R-based storm tracker showing Hurricane Lane

Views: 218
Kernel: R (R-Project)

Hurricane Tracker Example in R - Lane 2018

This demo uses the excellent rrricanes package to load and analyze data from the National Hurricane Center. We present an abridged walk-through of the tutorial at the former link, using sample data from 2018. This notebook is a revision of the previous version, updated to show Hurricane Lane.

Compare plots in this file to National Hurricane Center graphics for Lane.

Comments/corrections to [email protected].

Note: running this notebook requires a project with internet access.

Preparation

Before this worksheet can be run, some files need to be installed in your project. We expect these preparatory steps will not be necessary after pending CoCalc system updates are completed. The software request for system updates for rrricanes and dependencies is tracked on GitHub under CoCalc issue 2922.

Update GDAL - Geospatial Data Abstraction Library

We need an up-to-date version of GDAL. In a .term, do

~$ wget http://download.osgeo.org/gdal/2.3.0/gdal-2.3.0.tar.xz ~$ tar -xf gdal-2.3.0.tar.xz ~$ cd gdal-2.3.0/ ~$ ./configure --prefix=/home/user/opt ~$ make # this step can take up to an hour ~$ make install ~$ export LD_LIBRARY_PATH="/home/user/opt/lib" ~$ R > withr::with_makevars(c(PKG_CONFIG_PATH="/home/user/opt/lib/pkgconfig", LD_LIBRARY_PATH="/home/user/opt/lib"), install.packages("rgdal",verbose=TRUE, lib="/home/user/R/x86_64-pc-linux-gnu-library/3.4"), assignment="+=")

Install R packages for Hurricane Data

In a .term, do the one Installation and the two Optional Supporting Packages steps at the tutorial. When you install packages with R inside a project, they are stored under your home directory, for example: /home/user/R/x86_64-pc-linux-gnu-library/3.4

~$ R > devtools::install_github("ropensci/rrricanes", build_vignettes = TRUE) > install.packages("rrricanesdata", repos = "https://timtrice.github.io/drat/", type = "source") > install.packages("rnaturalearthhires", repos = "http://packages.ropensci.org", type = "source")
library(dplyr) library(rrricanes) get_storms() %>% print(n = nrow(.))
Attaching package: ‘dplyr’ The following objects are masked from ‘package:stats’: filter, lag The following objects are masked from ‘package:base’: intersect, setdiff, setequal, union rrricanes is not intended for use in emergency situations.
# A tibble: 19 x 4 Year Name Basin Link <dbl> <chr> <chr> <chr> 1 2018 Subtropical Storm Alberto AL http://www.nhc.noaa.gov/archive/2018… 2 2018 Hurricane Beryl AL http://www.nhc.noaa.gov/archive/2018… 3 2018 Hurricane Chris AL http://www.nhc.noaa.gov/archive/2018… 4 2018 Tropical Storm Debby AL http://www.nhc.noaa.gov/archive/2018… 5 2018 Tropical Storm Ernesto AL http://www.nhc.noaa.gov/archive/2018… 6 2018 Tropical Depression One-E EP http://www.nhc.noaa.gov/archive/2018… 7 2018 Hurricane Aletta EP http://www.nhc.noaa.gov/archive/2018… 8 2018 Hurricane Bud EP http://www.nhc.noaa.gov/archive/2018… 9 2018 Tropical Storm Carlotta EP http://www.nhc.noaa.gov/archive/2018… 10 2018 Tropical Storm Daniel EP http://www.nhc.noaa.gov/archive/2018… 11 2018 Tropical Storm Emilia EP http://www.nhc.noaa.gov/archive/2018… 12 2018 Hurricane Fabio EP http://www.nhc.noaa.gov/archive/2018… 13 2018 Tropical Storm Gilma EP http://www.nhc.noaa.gov/archive/2018… 14 2018 Tropical Depression Nine-E EP http://www.nhc.noaa.gov/archive/2018… 15 2018 Hurricane Hector EP http://www.nhc.noaa.gov/archive/2018… 16 2018 Tropical Storm Ileana EP http://www.nhc.noaa.gov/archive/2018… 17 2018 Hurricane John EP http://www.nhc.noaa.gov/archive/2018… 18 2018 Tropical Storm Kristy EP http://www.nhc.noaa.gov/archive/2018… 19 2018 Hurricane Lane EP http://www.nhc.noaa.gov/archive/2018…
# look at Hurricane Lane in 2018 ds <- get_storms() %>% filter(Name == "Hurricane Lane") %>% pull(Link) %>% get_storm_data(products = c("discus", "fstadv"))
key <- ds$fstadv %>% pull(Key) %>% first() key
'EP142018'
dyn.load("/home/user/opt/lib/libgdal.so")
# make sure we are using the correct library version library(rgdal)
Loading required package: sp rgdal: version: 1.3-2, (SVN revision 755) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 2.3.0, released 2018/05/04 Path to GDAL shared files: /home/user/opt/share/gdal GDAL binary built with GEOS: TRUE Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492] Path to PROJ.4 shared files: (autodetected) Linking to sp version: 1.3-1
gis <- gis_advisory(key = key, advisory = "16") %>% gis_download()
OGR data source with driver: ESRI Shapefile Source: "/tmp/RtmptNR1vA", layer: "ep142018-016_5day_lin" with 1 features It has 7 fields OGR data source with driver: ESRI Shapefile Source: "/tmp/RtmptNR1vA", layer: "ep142018-016_5day_pgn" with 1 features It has 7 fields OGR data source with driver: ESRI Shapefile Source: "/tmp/RtmptNR1vA", layer: "ep142018-016_5day_pts" with 8 features It has 23 fields
names(gis)
  1. 'ep142018_016_5day_lin'
  2. 'ep142018_016_5day_pgn'
  3. 'ep142018_016_5day_pts'
library(ggplot2) ep_tracking_chart(color = "black", size = 0.18, fill = "white") + geom_path(data = shp_to_df(gis$ep142018_016_5day_lin), aes(x = long, y = lat))
Regions defined for each Polygons Regions defined for each Polygons
Image in a Jupyter notebook
sp::bbox(gis$ep142018_016_5day_lin)
minmax
x-158.2-139.7
y 12.5 15.9
sp::bbox(gis$ep142018_016_5day_pgn)
minmax
x-161.00659-139.36890
y 12.16641 18.60486
offset = 10 bb <- sp::bbox(gis$ep142018_016_5day_pgn) ep_tracking_chart(color = "black", size = 0.1, fill = "white") + geom_path(data = shp_to_df(gis$ep142018_016_5day_lin), aes(x = long, y = lat)) + coord_equal(xlim = c(bb[1,1] - offset, bb[1,2] + offset), ylim = c(bb[2,1] - offset, bb[2,2] + offset))
Regions defined for each Polygons Regions defined for each Polygons
Image in a Jupyter notebook
bp <- ep_tracking_chart(color = "black", size = 0.1, fill = "white") + coord_equal(xlim = c(bb[1,1] - offset, bb[1,2] + offset), ylim = c(bb[2,1] - offset, bb[2,2] + offset))
Regions defined for each Polygons Regions defined for each Polygons
names(gis$ep142018_016_5day_pts)
  1. 'ADVDATE'
  2. 'ADVISNUM'
  3. 'BASIN'
  4. 'DATELBL'
  5. 'DVLBL'
  6. 'FCSTPRD'
  7. 'FLDATELBL'
  8. 'GUST'
  9. 'LAT'
  10. 'LON'
  11. 'MAXWIND'
  12. 'MSLP'
  13. 'SSNUM'
  14. 'STORMNAME'
  15. 'STORMNUM'
  16. 'STORMSRC'
  17. 'STORMTYPE'
  18. 'TCDVLP'
  19. 'TAU'
  20. 'TCDIR'
  21. 'TCSPD'
  22. 'TIMEZONE'
  23. 'VALIDTIME'
# which forecast ranges, i.e. 60-day, 120-day, are available in the data? table(gis$ep142018_016_5day_pts$FCSTPRD)
120 8
bp + geom_point(data = tibble::as_data_frame(gis$ep142018_016_5day_pts), aes(x = LON, y = LAT))
Image in a Jupyter notebook
bp + geom_polygon(data = shp_to_df(gis$ep142018_016_5day_pgn) %>% filter(FCSTPRD == 120), aes(x = long, y = lat, color = FCSTPRD), alpha=0.15, size=0.1)
Image in a Jupyter notebook