Skip to content

Commit

Permalink
Remove trended variables and plots from heatwave and heatwave_year
Browse files Browse the repository at this point in the history
  • Loading branch information
BBeltz1 committed Jan 31, 2025
1 parent d8f0f6a commit faf2942
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 74 deletions.
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
65 changes: 2 additions & 63 deletions data-raw/get_heatwave.R
Original file line number Diff line number Diff line change
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 @@ -420,7 +359,7 @@ get_heatwave_year <- function(save_clean = F){
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_year.rda
Binary file not shown.

0 comments on commit faf2942

Please sign in to comment.