Created
February 19, 2018 20:55
-
-
Save gregmacfarlane/87e61b4649bbb0aa08000029be2a03da to your computer and use it in GitHub Desktop.
Load a series of binary matrices into OMX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(omxr) # gregmacfarlane/omxr | |
library(tcadr) # pbsag/tcad | |
library(sf) | |
# number of zones + number of external stations | |
n <- 672 | |
periods <- c("am", "pm", "md", "nt") | |
create_omx("asheville.omx", numrows = n, numcols = n) | |
lapply(periods, function(p){ | |
od <- read_tcad(file.path("~/Downloads/od_matrices_by_purpose/", | |
stringr::str_c(toupper(p), "_trips.bin"))) %>% | |
transmute( | |
Rows, Columns, | |
visitor = Vis.OD, | |
freight = CV1.OD + CV2.OD + CV3.OD + External.Truck.OD, | |
external = External.Auto.OD | |
) %>% | |
gather(matrix, flow, visitor:external) %>% | |
reshape2::acast(Rows ~ Columns ~ matrix, value.var = 'flow') | |
cores <- c("visitor", "freight", "external") | |
for(core in 1:length(cores)){ | |
write_omx("asheville.omx", | |
od[, , core], | |
name = stringr::str_c(p, cores[core], sep = "_"), | |
replace = TRUE) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment