Skip to content

Instantly share code, notes, and snippets.

@jebyrnes jebyrnes/spike_wave.R
Last active Mar 6, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.