Library for connection of TransCAD data files to Python
Project description
model-connector: Library for accessing travel model data
Installation:
Install using pip
pip install model-connector
Use Cases
- TransCAD fixed format binary tables: fast read and write using pandas dataframes.
- TransCAD matrix files: read a TransCAD matrix into a numpy array (beta)
TransCAD Binary Files
Reading from a TransCAD binary file
import model_connector as mc
# Read a TransCAD fixed format binary file into a dataframe,
# retaining null values
df = mc.read_ffb("myfile.bin")
# Read a TransCAD fixed format binary file into a dataframe,
# converting null values to zeros
dfz = mc.read_ffb("myfile.bin", null_to_zero=True)
Writing to a TransCAD binary file
import model_connector as mc
import pandas as pd
df = pd.DataFrame({"ID":[1,2,3],
"RealField":[1.1, 2.2, 3.3, ],
"IntField":[1, 2, 3],
"DateField":[20210101, 20210115, 20210130],
"DateTimeField":[pd.Timestamp("2021-01-01 00:00:05"),
pd.Timestamp("2021-01-15 00:10:05"),
pd.Timestamp("2021-01-30 00:20:05")]})
mc.write_ffb(df, "sample_output.bin")
TransCAD Matrix Files
Matrix access requires TransCAD 9 or greater with a valid license.
Reading a TransCAD Matrix File
import model_connector as mc
import numpy as np
# Reading a TransCAD matrix into a dictionary of numpy arrays,
# using the default behavior of converting null to zero.
matrix = mc.read_matrix_tc("myfile.mtx")
for core in matrix.keys():
print(f"Sum of {core} = {matrix[core].sum()}" )
# Optionally Convert null to NAN. This will fail for integer matrices since
# numpy doesn't support NAN in integer arrays.
matrix_withnan = mc.read_matrix_tc("myfile.mtx", missing=mc.ConvertMissing.NAN)
for core in matrix_withnan.keys():
print(f"Sum of {core} = {matrix_withnan[core].sum()}" )
# By default, all matrix cores are loaded. Use the cores parameter to load only
# some matrix tables.
matrix_autos = mc.read_matrix_tc("myfile.mtx", cores=["DA", "SR2", "SR3p"])
for core in matrix_autos.keys():
print(f"Sum of {core} = {matrix_autos[core].sum()}" )
# By default, data is read using the base index. Use the row_index and
# col_index parameters to read data using a different index.
# Indices must be specified as an integer. the base index is 0, and
# the remaining indices are ordered as returned by GetMatrixIndexNames()
# in GISDK.
matrix_subset = mc.read_matrix_tc("myfile.mtx", row_index=1, col_index=1)
for core in matrix_subset.keys():
print(f"Sum of {core} = {matrix_subset[core].sum()}" )
print(f"Shape of matrix is {matrix_subset["DA"].shape}")
Writing a TransCAD Matrix File
This functionality has not yet been implemented.
Specifying the TransCAD Installation
The TransCAD matrix functions search the system registry to locate a TransCAD installation. If the matrix functions fail even with a valid installation, this may be due to multiple versions or licensing methods being present on the computer.
The TransCAD program location can be specified using set_tcpath(). The current path can be obtained using get_tcpath(). If the path is not set manually, get_tcpath() will report the detected version of TransCAD.
# Set the TransCAD location as shown below
import model_connector as mc
mc.set_tcpath("C:/Program Files/TransCAD 10.0/tcw.exe")
print("TransCAD Path: ", mc.get_tcpath())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file model_connector-0.0.4b1.tar.gz.
File metadata
- Download URL: model_connector-0.0.4b1.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a74b9ebabb3bb767a8ea2cec05f2decb435d2751ae4918cffe03c2d203e7da3
|
|
| MD5 |
aea523db1514aaaa1c9c486376cef8dd
|
|
| BLAKE2b-256 |
226a397344e8555396900bacbe6724f5a7b2d8554b3274986a425003521e70b0
|
File details
Details for the file model_connector-0.0.4b1-py3-none-any.whl.
File metadata
- Download URL: model_connector-0.0.4b1-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
677804a2e72f1522e4fbde65c901e0b0101a498cd69f63bc7a762633909c22cf
|
|
| MD5 |
a875be9eba0482065a07493363fd5db5
|
|
| BLAKE2b-256 |
35ed0a226b6383d566aef52fcde5db5aad746b5f60141c73face3d24f2ef8a80
|