Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update heatwave and heatwave_year with GLORYS bottom data through 11-26-2024 #225

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions R/plot_heatwave_year.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
#'
#' @param shadedRegion Numeric vector. Years denoting the shaded region of the plot (most recent 10)
#' @param report Character string. Which SOE report ("MidAtlantic", "NewEngland")
#' @param varName Character string. Which Variable to plot ("Surface", "Bottom", "withtrend")
#' default variables Surface and Bottom are detrended; option to print surface including
#' climate change signal is "withtrend"
#' @param varName Character string. Which Variable to plot ("Surface", "Bottom")
#' default variables Surface and Bottom are detrended
#'
#' @return ggplot object
#'
Expand All @@ -33,7 +32,7 @@ plot_heatwave_year <- function(shadedRegion = NULL,
# optional code to wrangle ecodata object prior to plotting
# e.g., calculate mean, max or other needed values to join below

plotvar = ifelse(varName == "withtrend", "Surface", paste0(varName,"Detrended"))
plotvar = paste0(varName,"Detrended")

year <- max(ecodata::heatwave_year$Year, na.rm = TRUE)

Expand All @@ -42,15 +41,11 @@ plot_heatwave_year <- function(shadedRegion = NULL,
Year == year,
Var == plotvar)

legendlab <- ifelse(varName == "withtrend", "Climatology",
"Shifted Climatology")
legendlab <- "Shifted Climatology"

ylabs <- ifelse(varName == "withtrend",
c("Temperature (C)"),
c("Temperature - Climate Trend (C)"))
ylabs <- "Temperature - Climate Trend (C)"

plotvartitle <- ifelse(varName == "withtrend", "Surface (not detrended)",
paste(varName,"Detrended"))
plotvartitle <- paste(varName,"Detrended")

# code for generating plot object p
# ensure that setup list objects are called as setup$...
Expand Down
32,359 changes: 15,671 additions & 16,688 deletions data-raw/daily_bottomT_GB_1959_2024_detrended.csv

Large diffs are not rendered by default.

32,359 changes: 15,671 additions & 16,688 deletions data-raw/daily_bottomT_GOM_1959_2024_detrended.csv

Large diffs are not rendered by default.

32,359 changes: 15,671 additions & 16,688 deletions data-raw/daily_bottomT_MAB_1959_2024_detrended.csv

Large diffs are not rendered by default.

83 changes: 11 additions & 72 deletions data-raw/get_heatwave.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ get_heatwave <- function(save_clean = F){
tidyr::drop_na()

# GB - define climatology, detect events
ts <- heatwaveR::ts2clm(gb, climatologyPeriod = c("1982-01-01", "2024-09-10"))
ts <- heatwaveR::ts2clm(gb, climatologyPeriod = c("1982-01-01", "2024-11-26"))
gb.mhw <- heatwaveR::detect_event(ts, minDuration = 30)
gb.hw<- gb.mhw$event %>%
dplyr::select(event_no, duration, date_start, date_peak, intensity_max, intensity_cumulative)%>%
dplyr::mutate(EPU = "GB")

# GOM - define climatology, detect events
ts <- heatwaveR::ts2clm(gom, climatologyPeriod = c("1982-01-01", "2024-09-10"))
ts <- heatwaveR::ts2clm(gom, climatologyPeriod = c("1982-01-01", "2024-11-26"))
gom.mhw <- heatwaveR::detect_event(ts, minDuration = 30)
gom.hw<- gom.mhw$event %>%
dplyr::select(event_no, duration, date_start, date_peak, intensity_max, intensity_cumulative) %>%
dplyr::mutate(EPU = "GOM")

# MAB - define climatology, detect events
ts <- heatwaveR::ts2clm(mab, climatologyPeriod = c("1982-01-01", "2024-09-10"))
ts <- heatwaveR::ts2clm(mab, climatologyPeriod = c("1982-01-01", "2024-11-26"))
mab.mhw <- heatwaveR::detect_event(ts, minDuration = 30)
mab.hw<- mab.mhw$event %>%
dplyr::select(event_no, duration, date_start, date_peak, intensity_max, intensity_cumulative) %>%
Expand Down Expand Up @@ -233,67 +233,6 @@ get_heatwave(save_clean = T)
#### get_heatwave_year get single year of heatwave
get_heatwave_year <- function(save_clean = F){
# import data
# SURFACE
gom<-read.csv(file.path(raw.dir,heatwave_gomd), header = FALSE) %>%
janitor::row_to_names(1) %>%
dplyr::select(t, detrended) %>%
dplyr::rename(temp = detrended) %>%
dplyr::filter(!temp == "temp") %>%
dplyr::mutate(temp = as.numeric(temp),
t = as.Date(t, format = "%m/%d/%Y")) %>%
tidyr::drop_na()

gb<-read.csv(file.path(raw.dir,heatwave_gbd), header = FALSE) %>%
janitor::row_to_names(1) %>%
dplyr::select(t, detrended) %>%
dplyr::rename(temp = detrended) %>%
dplyr::filter(!temp == "temp") %>%
dplyr::mutate(temp = as.numeric(temp),
t = as.Date(t, format = "%m/%d/%Y")) %>%
tidyr::drop_na()

mab<-read.csv(file.path(raw.dir,heatwave_mabd), header = FALSE) %>%
janitor::row_to_names(1) %>%
dplyr::select(t, detrended) %>%
dplyr::rename(temp = detrended) %>%
dplyr::filter(!temp == "temp") %>%
dplyr::mutate(temp = as.numeric(temp),
t = as.Date(t, format = "%m/%d/%Y")) %>%
tidyr::drop_na()
#GB
ts <- heatwaveR::ts2clm(gb, climatologyPeriod = c("1982-01-01", "2024-12-31"))
gb.mhw <- heatwaveR::detect_event(ts)

#GOM
ts <- heatwaveR::ts2clm(gom, climatologyPeriod = c("1982-01-01", "2024-12-31"))
gom.mhw <- heatwaveR::detect_event(ts)

#MAB
ts <- heatwaveR::ts2clm(mab, climatologyPeriod = c("1982-01-01", "2024-12-31"))
mab.mhw <- heatwaveR::detect_event(ts)

### Take just clim
#GB
mhw<- gb.mhw$clim %>%
mutate(EPU = c("GB"),
Year = c("2024"))# add EPU column
mhw.gb.year <- mhw[15341:15706,]## days in 2024 data set

#GOM
mhw<- gom.mhw$clim %>%
mutate(EPU = c("GOM"),
Year = c("2024"))# add EPU column
mhw.gom.year <- mhw[15341:15706,]## days in 2024 data set

#MAB
mhw<- mab.mhw$clim %>%
mutate(EPU = c("MAB"),
Year = c("2024"))# add EPU column
mhw.mab.year <- mhw[15341:15706,]## days in 2024 data set

heatwave_year<- rbind(mhw.gb.year, mhw.gom.year, mhw.mab.year) %>%
dplyr::mutate(Var = "Surface")

# SURFACE DETRENDED
gom<-read.csv(file.path(raw.dir,heatwave_gomd), header = FALSE) %>%
janitor::row_to_names(1) %>%
Expand Down Expand Up @@ -357,7 +296,7 @@ get_heatwave_year <- function(save_clean = F){
heatwave_year_detrended<- rbind(mhw.gb.year, mhw.gom.year, mhw.mab.year) %>%
dplyr::mutate(Var = "SurfaceDetrended")

#Bottom heatwave
#Bottom heatwave detrended
gom<-read.csv(file.path(raw.dir,bheatwave_gomd), header = FALSE) %>%
janitor::row_to_names(1) %>%
dplyr::select(date, Detrended) %>%
Expand Down Expand Up @@ -386,41 +325,41 @@ get_heatwave_year <- function(save_clean = F){
tidyr::drop_na()

#GB
ts <- heatwaveR::ts2clm(gb, climatologyPeriod = c("1982-01-01", "2024-09-10"))
ts <- heatwaveR::ts2clm(gb, climatologyPeriod = c("1982-01-01", "2024-11-26"))
gb.mhw <- heatwaveR::detect_event(ts, minDuration = 30)

#GOM
ts <- heatwaveR::ts2clm(gom, climatologyPeriod = c("1982-01-01", "2024-09-10"))
ts <- heatwaveR::ts2clm(gom, climatologyPeriod = c("1982-01-01", "2024-11-26"))
gom.mhw <- heatwaveR::detect_event(ts, minDuration = 30)

#MAB
ts <- heatwaveR::ts2clm(mab, climatologyPeriod = c("1982-01-01", "2024-09-10"))
ts <- heatwaveR::ts2clm(mab, climatologyPeriod = c("1982-01-01", "2024-11-26"))
mab.mhw <- heatwaveR::detect_event(ts, minDuration = 30)

### Take just clim
#GB
mhw<- gb.mhw$clim %>%
mutate(EPU = c("GB"),
Year = c("2024"))# add EPU column
mhw.gb.year <- mhw[15341:15594,]## days in 2024 data set only went to Sep 10, 2024
mhw.gb.year <- mhw[15341:15671,]## days in 2024 data set only went to Sep 10, 2024

#GOM
mhw<- gom.mhw$clim %>%
mutate(EPU = c("GOM"),
Year = c("2024"))# add EPU column
mhw.gom.year <- mhw[15341:15594,]## days in 2024 data set only went to Sep 10, 2024
mhw.gom.year <- mhw[15341:15671,]## days in 2024 data set only went to Sep 10, 2024

#MAB
mhw<- mab.mhw$clim %>%
mutate(EPU = c("MAB"),
Year = c("2024"))# add EPU column
mhw.mab.year <- mhw[15341:15594,]## days in 2024 data set only went to Sep 10, 2024
mhw.mab.year <- mhw[15341:15671,]## days in 2024 data set only went to Sep 10, 2024


bheatwave_year_detrended<- rbind(mhw.gb.year, mhw.gom.year, mhw.mab.year) %>%
dplyr::mutate(Var = "BottomDetrended")

heatwave_year <- rbind(heatwave_year, heatwave_year_detrended,
heatwave_year <- rbind(heatwave_year_detrended,
bheatwave_year_detrended)

if (save_clean){
Expand Down
Binary file modified data/heatwave.rda
Binary file not shown.
Binary file modified data/heatwave_year.rda
Binary file not shown.
5 changes: 2 additions & 3 deletions man/plot_heatwave_year.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading