Last active
March 6, 2019 21:32
-
-
Save jebyrnes/82799ca242cd00c14bf52872763707f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(heatwaveR) | |
library(tsibble) | |
library(lubridate) | |
library(dplyr) | |
# Detect the events in a time series | |
ts <- ts2clm(sst_WA, climatologyPeriod = c("1982-01-01", "2011-12-31")) | |
mhw <- detect_event(ts, minDuration = 1, maxGap = 0) | |
# View just a few metrics | |
events <- mhw$event %>% | |
dplyr::ungroup() %>% | |
dplyr::select(event_no, duration, date_start, date_peak, intensity_max, intensity_cumulative) %>% | |
dplyr::arrange(-intensity_max) %>% | |
mutate(spike_wave = ifelse(duration<5, "spike", "wave")) %>% | |
as_tsibble(index = date_peak) | |
annual <- events %>% | |
index_by(event_year = year(date_start)) %>% | |
group_by(spike_wave) %>% | |
tally() %>% | |
fill_gaps(n = 0) | |
ggplot(annual, | |
aes(x = event_year, y = n, color = spike_wave)) + | |
geom_line() | |
ggplot(events, | |
aes(x = duration, fill = spike_wave)) + | |
geom_histogram(position = position_dodge()) | |
ggplot(events, | |
aes(x = intensity_max, fill = spike_wave)) + | |
geom_histogram(position = position_dodge(), | |
bins = 15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment