Skip to content

Commit a362ec4

Browse files
committed
Add comments and read vehicle inventory for PM2.5 and C02. Re #93
1 parent cb10dbb commit a362ec4

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

code/co2_data_extraction/extract_co2_datasets.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
library(tidyverse)
22
library(tibble)
33

4+
# Load ithim object
45
io <- read_rds(file.choose())
56

7+
# Init cities
68
cities <- names(io)[!names(io) %in% 'scen_prop']
79

10+
# Loop all cities
811
for (city in cities){
912

13+
# Create dir if it does not already exist
1014
if (!file.exists(city))
1115
dir.create(city)
1216

17+
# Write trips
1318
write_csv(io[[city]]$trip_scen_sets, paste0(city, "/", paste0(city, "_trips"), ".csv"))
1419

15-
vehicle_inventory <- data.frame(t(sapply(io[[city]]$PM_emission_inventory,c))) %>%
16-
tibble::rowid_to_column() %>%
17-
tidyr::pivot_longer(cols = -("rowid")) %>%
18-
dplyr::rename(stage_mode = name, CO2_emission_inventory = value) %>%
19-
dplyr::distinct(stage_mode, .keep_all = T) %>%
20-
dplyr::select(-rowid)
20+
# Read vehicle inventory and remove all duplicates
21+
vehicle_inventory <- io[[city]]$vehicle_inventory %>% dplyr::distinct(stage_mode, .keep_all = T)
2122

23+
# Write vehicle inventory with PM2.5 and CO2 entries
2224
write_csv(vehicle_inventory, paste0(city, "/", paste0(city, "_vehicle_inventory"), ".csv"))
2325

2426
# Total distance by mode
@@ -27,6 +29,9 @@ for (city in cities){
2729
# Rename columns
2830
names(dist)[2:5] <- c("Baseline", "Bicycling", "Driving", "Public Transport")
2931

32+
# Write passenger dist
33+
# Note if you like to calculate vehicle distance for bus, you need to divide it by 31.
34+
# In case you have better bus to passenger ratio - for all studied countries, please use that insteat
3035
write_csv(dist, paste0(city, "/", paste0(city, "_distance"), ".csv"))
3136

3237
# Combine CO2 emission inventory with distance by mode, to calculate emission factors

0 commit comments

Comments
 (0)