Skip to content

Commit

Permalink
Use dynamic number of scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
usr110 committed Aug 4, 2023
1 parent 5296ae8 commit b1741d0
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions summary_tables_PA_AP.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ cities <- names(io)[!names(io) %in% 'scen_prop']
scen_names <- c("Baseline", "Bicycling", "Driving", "Public Transport", "Motorcycling")
input_parameter_file <- "InputParameters_v28.0.xlsx"
NUMS <- io$scen_prop |> nrow()
if (NUMS != 4)
scen_names <- c("Baseline", "Bicycling", "Driving", "Public Transport")
scen_length <- length(scen_names) - 1
if (!exists("input_parameter_file"))
input_parameter_file <<- "InputParameters_v30.1.xlsx"
# scenario definition
scenario_name <- "GLOBAL"
reference_scenario <- 'Baseline'
Expand Down Expand Up @@ -182,10 +190,10 @@ for (x in 1:length(cities)) {
# "Public Transport")
n_col <- ncol(io[[cities[x]]]$outcomes$pm_conc_pp)
names(io[[cities[x]]]$outcomes$pm_conc_pp)[(n_col - 4):n_col] <- scen_names
names(io[[cities[x]]]$outcomes$pm_conc_pp)[(n_col - scen_length):n_col] <- scen_names
data_long <- gather(io[[cities[x]]]$outcomes$pm_conc_pp, scenario, pm_conc,
Baseline:`Motorcycling`, factor_key = TRUE)
Baseline:scen_names[length(scen_names)], factor_key = TRUE)
y <- ggplot(data_long, aes(x = scenario, y = pm_conc, fill = scenario)) +
geom_boxplot(outlier.shape = 8) + ggtitle(cities[x]) +
labs(y = "Daily PM2.5 Concentration", x = "Scenarios") #+
Expand Down Expand Up @@ -215,9 +223,9 @@ for (x in 1:length(cities)) {
#names(io[[cities[x]]]$outcomes$pm_conc_pp)[6:11]<-c("Baseline","Walking", "Bicycling", "Driving", "Motorcycling", "Public Transport")
#
n_col <- ncol(io[[cities[x]]]$outcomes$pm_conc_pp)
names(io[[cities[x]]]$outcomes$pm_conc_pp)[(n_col - 4):n_col] <- scen_names
names(io[[cities[x]]]$outcomes$pm_conc_pp)[(n_col - scen_length):n_col] <- scen_names
data_long <- gather(io[[cities[x]]]$outcomes$pm_conc_pp, scenario, pm_conc,
Baseline:`Motorcycling`, factor_key = TRUE)
Baseline:scen_names[length(scen_names)], factor_key = TRUE)
summary <- as.data.frame(data_long %>% group_by(scenario) %>%
summarise('mean' = mean(pm_conc),
'5th' = quantile(pm_conc, 0.05),
Expand Down Expand Up @@ -307,9 +315,9 @@ print(kable(co2_conc))
limit = 100
for (x in 1:length(cities)) {
n_col <- ncol(io[[cities[x]]]$outcomes$mmets)
names(io[[cities[x]]]$outcomes$mmets)[(n_col - 4):n_col] <- scen_names
names(io[[cities[x]]]$outcomes$mmets)[(n_col - scen_length):n_col] <- scen_names
data_long <- gather(io[[cities[x]]]$outcomes$mmets, scenario, mmet, Baseline:`Motorcycling`, factor_key = TRUE)
data_long <- gather(io[[cities[x]]]$outcomes$mmets, scenario, mmet, Baseline:scen_names[length(scen_names)], factor_key = TRUE)
y <- ggplot(data_long, aes(x = scenario, y = mmet, fill = scenario)) +
geom_boxplot(outlier.shape = NA) + ggtitle(cities[x]) +
labs(y = "Weekly MMET", x = "Scenarios")+ ylim(0, limit)
Expand All @@ -323,9 +331,9 @@ for (x in 1:length(cities)) {
for (x in 1:length(cities)) {
#names(io[[cities[x]]]$outcomes$mmets)[5:10] <- c("baseline","walk_scen", "bike_scen", "car_scen", "MC_scen", "bus_scen")
n_col <- ncol(io[[cities[x]]]$outcomes$mmets)
names(io[[cities[x]]]$outcomes$mmets)[(n_col - 4):n_col] <- scen_names
names(io[[cities[x]]]$outcomes$mmets)[(n_col - scen_length):n_col] <- scen_names
data_long <- gather(io[[cities[x]]]$outcomes$mmets, scenario, mmet, Baseline:Motorcycling, factor_key = TRUE)
data_long <- gather(io[[cities[x]]]$outcomes$mmets, scenario, mmet, Baseline:scen_names[length(scen_names)], factor_key = TRUE)
summary <- as.data.frame(data_long %>% group_by(scenario) %>%
summarise('mean' = mean(mmet),
'5th' = quantile(mmet, 0.05),
Expand All @@ -349,7 +357,7 @@ for (city in cities)
#
n_col <- ncol(io[[cities[x]]]$outcomes$mmets)
td <- round(colMeans(io[[city]]$outcomes$mmets[,(n_col - 4):n_col], na.rm = T), 1) %>%
td <- round(colMeans(io[[city]]$outcomes$mmets[,(n_col - scen_length):n_col], na.rm = T), 1) %>%
as.data.frame() %>% tibble::rownames_to_column()
names(td) <- c('Scenario', city)
Expand Down Expand Up @@ -403,10 +411,10 @@ for (x in 1:length(cities)) {
# PM 2.5 table and plot
n_col <- ncol(io[[cities[x]]]$outcomes$mmets)
names(io[[cities[x]]]$outcomes$pm_conc_pp)[(n_col - 4):n_col] <- scen_names
names(io[[cities[x]]]$outcomes$pm_conc_pp)[(n_col - scen_length):n_col] <- scen_names
data_long <- gather(io[[cities[x]]]$outcomes$pm_conc_pp, scenario, pm_conc,
Baseline:`Motorcycling`, factor_key = TRUE)
Baseline:scen_names[length(scen_names)], factor_key = TRUE)
summary2 <- as.data.frame(data_long %>% group_by(scenario) %>%
summarise('mean' = mean(pm_conc),
Expand Down Expand Up @@ -462,8 +470,8 @@ write_csv(bind_rows(l), "results/multi_city/AP/desc_stats.csv")
limit = 100
for (x in 1:length(cities)) {
n_col <- ncol(io[[cities[x]]]$outcomes$mmets)
names(io[[cities[x]]]$outcomes$mmets)[(n_col - 4):n_col] <- scen_names
data_long <- gather(io[[cities[x]]]$outcomes$mmets, scenario, mmet, Baseline:`Motorcycling`, factor_key = TRUE)
names(io[[cities[x]]]$outcomes$mmets)[(n_col - scen_length):n_col] <- scen_names
data_long <- gather(io[[cities[x]]]$outcomes$mmets, scenario, mmet, Baseline:scen_names[length(scen_names)], factor_key = TRUE)
y <- ggplot(data_long, aes(x = scenario, y = mmet, fill = scenario)) + geom_boxplot(outlier.shape = NA) + ggtitle(cities[x]) +
labs(y = "Weekly MMET", x = "Scenarios") + ylim(0, limit)
print(y)
Expand Down

0 comments on commit b1741d0

Please sign in to comment.