-
Notifications
You must be signed in to change notification settings - Fork 0
/
writedb_hurdat2_hadisst_pdis.R
66 lines (47 loc) · 2.11 KB
/
writedb_hurdat2_hadisst_pdis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Code to build a PDI (from HURDAT2) data set with SST data (from HADISST)
# Author: Alfredo Hernández <[email protected]>
# Source base code -----------------------------------------
source("hadisst_base.R")
source("hurdat2_pdi_base.R")
# Create PDI data frame ------------------------------------
# Get hurricanes data frames
hurr.natl.obs <- get_hurr_obs("hurdat2-1851-2016-apr2017.txt")
hurr.epac.obs <- get_hurr_obs("hurdat2-nepac-1949-2016-apr2017.txt")
# Create data frame with PDI and year of the storm
hurr.natl.pdi <- get_pdis(hurr.natl.obs) %>%
dplyr::filter(storm.id != "AL171988") %>%
mutate(basin = "NATL") %>%
dplyr::filter(storm.year %in% 1966:2016)
hurr.epac.pdi <- get_pdis(hurr.epac.obs) %>%
dplyr::filter(storm.id != "EP231989") %>%
mutate(basin = "EPAC") %>%
dplyr::filter(storm.year %in% 1986:2016)
# hurr.all.pdi <- rbind(hurr.natl.pdi, hurr.epac.pdi)
# Create SST data frames -----------------------------------
hadsst.raster <- load_hadsst(file = "data/HadISST_sst.nc")
# Windows of activity
years.natl <- 1966:2016
coords.natl <- c("90W", "20W", "5N", "25N")
years.epac <- 1986:2016
coords.epac <- c("120W", "90W", "5N", "20N")
# Construct SST data frames
ssts.natl <- get_mean_ssts(years = years.natl, coords = coords.natl)
ssts.epac <- get_mean_ssts(years = years.epac, coords = coords.epac)
# Build PDI + SST data set ---------------------------------
ssts.natl <- ssts.natl %>%
mutate(storm.year = as.character(year(year))) %>%
dplyr::select(-year)
ssts.epac <- ssts.epac %>%
mutate(storm.year = as.character(year(year))) %>%
dplyr::select(-year)
# Add SST data into HURDAT2 data
hurr.sst.pdi.natl <- full_join(hurr.natl.pdi, ssts.natl)
hurr.sst.pdi.epac <- full_join(hurr.epac.pdi, ssts.epac)
# Sort by year
hurr.sst.pdi.natl <- arrange(hurr.sst.pdi.natl, storm.year)
hurr.sst.pdi.epac <- arrange(hurr.sst.pdi.epac, storm.year)
hurr.sst.all.pdi <- rbind(hurr.sst.pdi.natl, hurr.sst.pdi.epac)
# Write into CSV -------------------------------------------
if (!file.exists("data/hurdat2-hadisst-1966-2016_pdis.csv")) {
write_csv(hurr.sst.all.pdi, "data/hurdat2-hadisst-1966-2016_pdis.csv")
}