Skip to content

Instantly share code, notes, and snippets.

@gregmacfarlane
Created February 19, 2018 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregmacfarlane/87e61b4649bbb0aa08000029be2a03da to your computer and use it in GitHub Desktop.
Save gregmacfarlane/87e61b4649bbb0aa08000029be2a03da to your computer and use it in GitHub Desktop.
Load a series of binary matrices into OMX
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