CoCalc Public FilesPublic / r-hurricane-tracker-beryl.ipynbOpen with one click!
Author: Hal Snyder
Views : 216
Description: R-based storm tracker showing Hurricane Beryl
Compute Environment: Ubuntu 18.04 (Deprecated)

Hurricane Tracker Example in R - Beryl 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 Beryl.

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

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")
In [1]:
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: 9 x 4 Year Name Basin Link <dbl> <chr> <chr> <chr> 1 2018 Subtropical Storm Alberto AL http://www.nhc.noaa.gov/archive/2018/A… 2 2018 Hurricane Beryl AL http://www.nhc.noaa.gov/archive/2018/B… 3 2018 Tropical Depression One-E EP http://www.nhc.noaa.gov/archive/2018/O… 4 2018 Hurricane Aletta EP http://www.nhc.noaa.gov/archive/2018/A… 5 2018 Hurricane Bud EP http://www.nhc.noaa.gov/archive/2018/B… 6 2018 Tropical Storm Carlotta EP http://www.nhc.noaa.gov/archive/2018/C… 7 2018 Tropical Storm Daniel EP http://www.nhc.noaa.gov/archive/2018/D… 8 2018 Tropical Storm Emilia EP http://www.nhc.noaa.gov/archive/2018/E… 9 2018 Hurricane Fabio EP http://www.nhc.noaa.gov/archive/2018/F…
In [2]:
# look at Hurricane Beryl in 2018 ds <- get_storms() %>% filter(Name == "Hurricane Beryl") %>% pull(Link) %>% get_storm_data(products = c("discus", "fstadv"))
In [3]:
key <- ds$fstadv %>% pull(Key) %>% first() key
'AL022018'
In [4]:
dyn.load("/home/user/opt/lib/libgdal.so")
In [5]:
# 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
In [7]:
gis <- gis_advisory(key = key, advisory = "5") %>% gis_download()
OGR data source with driver: ESRI Shapefile Source: "/tmp/RtmpXjbvkL", layer: "al022018-005_5day_lin" with 1 features It has 7 fields OGR data source with driver: ESRI Shapefile Source: "/tmp/RtmpXjbvkL", layer: "al022018-005_5day_pgn" with 1 features It has 7 fields OGR data source with driver: ESRI Shapefile Source: "/tmp/RtmpXjbvkL", layer: "al022018-005_5day_pts" with 7 features It has 23 fields
In [8]:
names(gis)
  1. 'al022018_005_5day_lin'
  2. 'al022018_005_5day_pgn'
  3. 'al022018_005_5day_pts'
In [9]:
library(ggplot2) al_tracking_chart(color = "black", size = 0.18, fill = "white") + geom_path(data = shp_to_df(gis$al022018_005_5day_lin), aes(x = long, y = lat))
Regions defined for each Polygons Regions defined for each Polygons
In [10]:
sp::bbox(gis$al022018_005_5day_lin)
minmax
x-72.0-46.5
y 10.7 18.5
In [11]:
sp::bbox(gis$al022018_005_5day_pgn)
minmax
x-74.65359-46.16853
y 10.38538 21.00741
In [18]:
offset = 10 bb <- sp::bbox(gis$al022018_005_5day_pgn) al_tracking_chart(color = "black", size = 0.1, fill = "white") + geom_path(data = shp_to_df(gis$al022018_005_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
In [19]:
bp <- al_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
In [14]:
names(gis$al022018_005_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'
In [15]:
# which forecast ranges, i.e. 60-day, 120-day, are available in the data? table(gis$al022018_005_5day_pts$FCSTPRD)
120 7
In [20]:
bp + geom_point(data = tibble::as_data_frame(gis$al022018_005_5day_pts), aes(x = LON, y = LAT))
In [21]:
bp + geom_polygon(data = shp_to_df(gis$al022018_005_5day_pgn) %>% filter(FCSTPRD == 120), aes(x = long, y = lat, color = FCSTPRD), alpha=0.15, size=0.1)
In [ ]: