Loading R/dam_conversion.R +15 −3 Original line number Diff line number Diff line Loading @@ -36,9 +36,21 @@ convert_EIA_to_COMPLX <- function(EHA, by = join_by(year)) |> mutate(cap_MWh = nameplate_MW * n_hrs, CF = gen_MWh / cap_MWh) |> arrange(COMPLXID) -> gen_cap_CF_1970_2021 arrange(COMPLXID) |> filter(!is.na(COMPLXID)) -> gen_cap_CF_1970_2022 return(gen_cap_CF_1970_2021) gen_cap_CF_1970_2022 |> filter(year == 2021) |> select(COMPLXID, nameplate_2021_MW = nameplate_MW) -> nameplate_2021 gen_cap_CF_1970_2022 |> left_join(nameplate_2021, by = join_by(COMPLXID)) |> mutate(CF_static = gen_MWh / (nameplate_2021_MW * n_hrs)) -> gen_cap_CF_1970_2022_plus_static return(gen_cap_CF_1970_2022_plus_static) } R/plots.R +188 −0 Original line number Diff line number Diff line Loading @@ -1390,4 +1390,192 @@ plot_shift_sparks <- function(trend_shift_analysis, } plot_trend_comparisons <- function(EHA, CF_trends, CF_trends_static){ #tar_read(CF_trends) -> CF_trends #tar_read(CF_trends_fixed_CF) -> CF_trends_static #tar_read(EHA) -> EHA # ensure HUC2 grabbed proper options(scipen = 999) CF_trends |> filter(!is.na(sens_slope)) |> pull(COMPLXID) |> unique() -> study_dam_IDs_610 st_read(EHA, quiet = TRUE) |> as_tibble() |> mutate(COMPLXID = str_replace(EHA_PtID, "\\_..*", "")) |> filter(COMPLXID %in% study_dam_IDs_610, PtName != "Hoover Dam (NV)", PtName != "St Stephen", !(COMPLXID == "hc0027" & Mode == "Run-of-river"), !(COMPLXID == "hc0225" & Mode == "Run-of-river")) |> summarise(CH_MW = sum(CH_MW), .by = c(COMPLXID, State, HUC, Mode)) |> mutate(size_cat = case_when( CH_MW > 1000 ~ "> 1 ", CH_MW > 500 & CH_MW <= 1000 ~ "0.5 - 1 ", CH_MW > 100 & CH_MW <= 500 ~ "0.1 - 0.5 ", CH_MW >= 5 & CH_MW <= 100 ~ "0.05 - 0.1 " )) |> mutate(size_cat = factor(size_cat, levels = c( "0.05 - 0.1 ", "0.1 - 0.5 ", "0.5 - 1 ", "> 1 " ))) |> mutate(region = case_when( substr(HUC, 1, 2) == "18" ~ "California", substr(HUC, 1, 2) == "17" ~ "Pacific NW", substr(HUC, 1, 2) %in% c("14", "15") ~ "Colorado River Basin", State %in% c("NY", "VT", "NH", "ME", "MA", "RI", "CT") ~ "Northeast", State %in% c("TN", "AL", "GA", "SC", "MD", "VA", "WV", "KY") ~ "Southeast", TRUE ~ "Other" ), region = factor(region, levels = c( "Pacific NW", "Other", "Northeast", "California", "Colorado River Basin", "Southeast" ))) -> dam_detail CF_trends |> filter(analysis %in% c( "flow period add 2022", "pre renewables period" )) |> filter(!is.na(sens_slope)) -> full_vs_pre full_vs_pre |> select(COMPLXID, analysis, sens_slope) |> mutate(sens_slope = sens_slope * 1000) |> pivot_wider(names_from = analysis, values_from = sens_slope) -> compare_w_pre_renewables compare_w_pre_renewables |> left_join(dam_detail, join_by(COMPLXID)) |> mutate(type = case_when( Mode %in% c("Peaking", "Intermediate Peaking", "Run-of-river/Peaking") ~ "Peaking or intermediate peaking ", TRUE ~ "Run-of-river, reregulating, canal/conduit" )) |> ggplot(aes(`flow period add 2022`, `pre renewables period`, size = size_cat, fill = type)) + geom_abline(slope = 1) + geom_hline(yintercept = 0, linetype = 2) + geom_vline(xintercept = 0, linetype = 2) + geom_point(pch = 21, alpha = 0.5) + scale_size_manual(values = c( "0.05 - 0.1 " = 1, "0.1 - 0.5 " = 2, "0.5 - 1 " = 4, "> 1 " = 7 )) + scale_fill_manual(values = c( "Peaking or intermediate peaking " = "dodgerblue", "Run-of-river, reregulating, canal/conduit" = "grey" )) + facet_wrap(~region) + labs(size = "Nameplate (GW)", fill = "Mode of operation", x = "CF trend (PPPD)\n1980 - 2022", y = "CF trend (PPPD)\n1980 - 2009") + coord_equal() + theme_bw() + theme(strip.background = element_blank(), legend.position = "top", legend.direction = "horizontal", legend.box = "vertical", axis.title.y = element_text(angle = 0, vjust = 0.5)) bind_rows( CF_trends_static |> filter(COMPLXID %in% study_dam_IDs_610) |> filter(analysis == "flow period add 2022") |> mutate(trend_PPPD = sens_slope * 1000, data = "static") |> select(COMPLXID, trend_PPPD, data), CF_trends |> filter(COMPLXID %in% study_dam_IDs_610) |> filter(analysis == "flow period add 2022") |> mutate(trend_PPPD = sens_slope * 1000, data = "actual") |> select(COMPLXID, trend_PPPD, data) ) -> CF_vs_gen_trends CF_vs_gen_trends |> #filter(is.na(trend_PPPD)) # summarise( # med = median(trend_PPPD, na.rm = T), # q95 = quantile(trend_PPPD, 0.95, na.rm = T), # q05 = quantile(trend_PPPD, 0.05, na.rm = T), # .by = data # ) |> pivot_wider(names_from = data, values_from = trend_PPPD) |> left_join(dam_detail, join_by(COMPLXID)) |> ggplot(aes(actual, static, size = size_cat)) + geom_abline(slope = 1) + geom_hline(yintercept = 0, linetype = 2) + geom_vline(xintercept = 0, linetype = 2) + geom_point(pch = 21, alpha = 0.5, fill = "dodgerblue") + scale_size_manual(values = c( "0.05 - 0.1 " = 1, "0.1 - 0.5 " = 2, "0.5 - 1 " = 4, "> 1 " = 7 )) + # scale_fill_manual(values = c( # "Peaking or intermediate peaking " = "dodgerblue", # "Run-of-river, reregulating, canal/conduit" = "grey" # )) + facet_wrap(~region) + labs(size = "Nameplate (GW)", fill = "Mode of operation", x = "CF trend (PPPD)\n1980 - 2022", y = "CF* trend (PPPD)\n1980 - 2022\n") + coord_equal() + theme_bw() + theme(strip.background = element_blank(), legend.position = "top", legend.direction = "horizontal", legend.box = "vertical", axis.title.y = element_text(angle = 0, vjust = 0.5)) CF_vs_gen_trends |> #filter(is.na(trend_PPPD)) # summarise( # med = median(trend_PPPD, na.rm = T), # q95 = quantile(trend_PPPD, 0.95, na.rm = T), # q05 = quantile(trend_PPPD, 0.05, na.rm = T), # .by = data # ) |> pivot_wider(names_from = data, values_from = trend_PPPD) |> filter(actual < static) |> #342 with cap additions filter(actual < 0) |> #of which 87% (298) trending down CF filter(static < 0) } R/trends.R +3 −2 Original line number Diff line number Diff line Loading @@ -11,7 +11,8 @@ get_CF_trends <- function(annual_CFs){ ~start_yr, ~end_yr, ~analysis, #1970, 2021, "full period", 1980, 2019, "flow period", 1980, 2021, "flow period plus", 1980, 2009, "pre renewables period", #1980, 2021, "flow period plus", 1980, 2022, "flow period add 2022" #2001, 2021, "923 period" ) |> Loading Loading @@ -240,7 +241,7 @@ trend_vs_shift <- function(flow_CF_models, CF_trends, flow_cats){ #tar_load(CF_trends) CF_trends |> filter(analysis == "flow period plus") |> filter(analysis == "flow period add 2022") |> filter(sens_slope < 0, p_value < 0.05) |> pull(COMPLXID) -> dams_with_signif_neg_trend Loading _targets.R +8 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,14 @@ list( get_CF_trends(annual_CFs = dam_annual_gen_cap_CF_1970_2022), format = "parquet" ), tar_target( CF_trends_fixed_CF, get_CF_trends( dam_annual_gen_cap_CF_1970_2022 |> mutate(CF = CF_static) ), format = "parquet" ), tar_target( HESC, "./data/HESC_v2/", Loading _targets/meta/meta +21 −64 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
R/dam_conversion.R +15 −3 Original line number Diff line number Diff line Loading @@ -36,9 +36,21 @@ convert_EIA_to_COMPLX <- function(EHA, by = join_by(year)) |> mutate(cap_MWh = nameplate_MW * n_hrs, CF = gen_MWh / cap_MWh) |> arrange(COMPLXID) -> gen_cap_CF_1970_2021 arrange(COMPLXID) |> filter(!is.na(COMPLXID)) -> gen_cap_CF_1970_2022 return(gen_cap_CF_1970_2021) gen_cap_CF_1970_2022 |> filter(year == 2021) |> select(COMPLXID, nameplate_2021_MW = nameplate_MW) -> nameplate_2021 gen_cap_CF_1970_2022 |> left_join(nameplate_2021, by = join_by(COMPLXID)) |> mutate(CF_static = gen_MWh / (nameplate_2021_MW * n_hrs)) -> gen_cap_CF_1970_2022_plus_static return(gen_cap_CF_1970_2022_plus_static) }
R/plots.R +188 −0 Original line number Diff line number Diff line Loading @@ -1390,4 +1390,192 @@ plot_shift_sparks <- function(trend_shift_analysis, } plot_trend_comparisons <- function(EHA, CF_trends, CF_trends_static){ #tar_read(CF_trends) -> CF_trends #tar_read(CF_trends_fixed_CF) -> CF_trends_static #tar_read(EHA) -> EHA # ensure HUC2 grabbed proper options(scipen = 999) CF_trends |> filter(!is.na(sens_slope)) |> pull(COMPLXID) |> unique() -> study_dam_IDs_610 st_read(EHA, quiet = TRUE) |> as_tibble() |> mutate(COMPLXID = str_replace(EHA_PtID, "\\_..*", "")) |> filter(COMPLXID %in% study_dam_IDs_610, PtName != "Hoover Dam (NV)", PtName != "St Stephen", !(COMPLXID == "hc0027" & Mode == "Run-of-river"), !(COMPLXID == "hc0225" & Mode == "Run-of-river")) |> summarise(CH_MW = sum(CH_MW), .by = c(COMPLXID, State, HUC, Mode)) |> mutate(size_cat = case_when( CH_MW > 1000 ~ "> 1 ", CH_MW > 500 & CH_MW <= 1000 ~ "0.5 - 1 ", CH_MW > 100 & CH_MW <= 500 ~ "0.1 - 0.5 ", CH_MW >= 5 & CH_MW <= 100 ~ "0.05 - 0.1 " )) |> mutate(size_cat = factor(size_cat, levels = c( "0.05 - 0.1 ", "0.1 - 0.5 ", "0.5 - 1 ", "> 1 " ))) |> mutate(region = case_when( substr(HUC, 1, 2) == "18" ~ "California", substr(HUC, 1, 2) == "17" ~ "Pacific NW", substr(HUC, 1, 2) %in% c("14", "15") ~ "Colorado River Basin", State %in% c("NY", "VT", "NH", "ME", "MA", "RI", "CT") ~ "Northeast", State %in% c("TN", "AL", "GA", "SC", "MD", "VA", "WV", "KY") ~ "Southeast", TRUE ~ "Other" ), region = factor(region, levels = c( "Pacific NW", "Other", "Northeast", "California", "Colorado River Basin", "Southeast" ))) -> dam_detail CF_trends |> filter(analysis %in% c( "flow period add 2022", "pre renewables period" )) |> filter(!is.na(sens_slope)) -> full_vs_pre full_vs_pre |> select(COMPLXID, analysis, sens_slope) |> mutate(sens_slope = sens_slope * 1000) |> pivot_wider(names_from = analysis, values_from = sens_slope) -> compare_w_pre_renewables compare_w_pre_renewables |> left_join(dam_detail, join_by(COMPLXID)) |> mutate(type = case_when( Mode %in% c("Peaking", "Intermediate Peaking", "Run-of-river/Peaking") ~ "Peaking or intermediate peaking ", TRUE ~ "Run-of-river, reregulating, canal/conduit" )) |> ggplot(aes(`flow period add 2022`, `pre renewables period`, size = size_cat, fill = type)) + geom_abline(slope = 1) + geom_hline(yintercept = 0, linetype = 2) + geom_vline(xintercept = 0, linetype = 2) + geom_point(pch = 21, alpha = 0.5) + scale_size_manual(values = c( "0.05 - 0.1 " = 1, "0.1 - 0.5 " = 2, "0.5 - 1 " = 4, "> 1 " = 7 )) + scale_fill_manual(values = c( "Peaking or intermediate peaking " = "dodgerblue", "Run-of-river, reregulating, canal/conduit" = "grey" )) + facet_wrap(~region) + labs(size = "Nameplate (GW)", fill = "Mode of operation", x = "CF trend (PPPD)\n1980 - 2022", y = "CF trend (PPPD)\n1980 - 2009") + coord_equal() + theme_bw() + theme(strip.background = element_blank(), legend.position = "top", legend.direction = "horizontal", legend.box = "vertical", axis.title.y = element_text(angle = 0, vjust = 0.5)) bind_rows( CF_trends_static |> filter(COMPLXID %in% study_dam_IDs_610) |> filter(analysis == "flow period add 2022") |> mutate(trend_PPPD = sens_slope * 1000, data = "static") |> select(COMPLXID, trend_PPPD, data), CF_trends |> filter(COMPLXID %in% study_dam_IDs_610) |> filter(analysis == "flow period add 2022") |> mutate(trend_PPPD = sens_slope * 1000, data = "actual") |> select(COMPLXID, trend_PPPD, data) ) -> CF_vs_gen_trends CF_vs_gen_trends |> #filter(is.na(trend_PPPD)) # summarise( # med = median(trend_PPPD, na.rm = T), # q95 = quantile(trend_PPPD, 0.95, na.rm = T), # q05 = quantile(trend_PPPD, 0.05, na.rm = T), # .by = data # ) |> pivot_wider(names_from = data, values_from = trend_PPPD) |> left_join(dam_detail, join_by(COMPLXID)) |> ggplot(aes(actual, static, size = size_cat)) + geom_abline(slope = 1) + geom_hline(yintercept = 0, linetype = 2) + geom_vline(xintercept = 0, linetype = 2) + geom_point(pch = 21, alpha = 0.5, fill = "dodgerblue") + scale_size_manual(values = c( "0.05 - 0.1 " = 1, "0.1 - 0.5 " = 2, "0.5 - 1 " = 4, "> 1 " = 7 )) + # scale_fill_manual(values = c( # "Peaking or intermediate peaking " = "dodgerblue", # "Run-of-river, reregulating, canal/conduit" = "grey" # )) + facet_wrap(~region) + labs(size = "Nameplate (GW)", fill = "Mode of operation", x = "CF trend (PPPD)\n1980 - 2022", y = "CF* trend (PPPD)\n1980 - 2022\n") + coord_equal() + theme_bw() + theme(strip.background = element_blank(), legend.position = "top", legend.direction = "horizontal", legend.box = "vertical", axis.title.y = element_text(angle = 0, vjust = 0.5)) CF_vs_gen_trends |> #filter(is.na(trend_PPPD)) # summarise( # med = median(trend_PPPD, na.rm = T), # q95 = quantile(trend_PPPD, 0.95, na.rm = T), # q05 = quantile(trend_PPPD, 0.05, na.rm = T), # .by = data # ) |> pivot_wider(names_from = data, values_from = trend_PPPD) |> filter(actual < static) |> #342 with cap additions filter(actual < 0) |> #of which 87% (298) trending down CF filter(static < 0) }
R/trends.R +3 −2 Original line number Diff line number Diff line Loading @@ -11,7 +11,8 @@ get_CF_trends <- function(annual_CFs){ ~start_yr, ~end_yr, ~analysis, #1970, 2021, "full period", 1980, 2019, "flow period", 1980, 2021, "flow period plus", 1980, 2009, "pre renewables period", #1980, 2021, "flow period plus", 1980, 2022, "flow period add 2022" #2001, 2021, "923 period" ) |> Loading Loading @@ -240,7 +241,7 @@ trend_vs_shift <- function(flow_CF_models, CF_trends, flow_cats){ #tar_load(CF_trends) CF_trends |> filter(analysis == "flow period plus") |> filter(analysis == "flow period add 2022") |> filter(sens_slope < 0, p_value < 0.05) |> pull(COMPLXID) -> dams_with_signif_neg_trend Loading
_targets.R +8 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,14 @@ list( get_CF_trends(annual_CFs = dam_annual_gen_cap_CF_1970_2022), format = "parquet" ), tar_target( CF_trends_fixed_CF, get_CF_trends( dam_annual_gen_cap_CF_1970_2022 |> mutate(CF = CF_static) ), format = "parquet" ), tar_target( HESC, "./data/HESC_v2/", Loading