Welcome to the Matrixconverters documentation!

Matrixconverters has been developed to read and write PTV Matrices as xarray-Datasets

Readme File

License: GPL v3 Build Status Linux Build Status Windows codecov PyPI version Anaconda-Server Badge

tools to read and write matrices in the format or PTV VISUM

It implements:

Reading and writing PTV-Matrices

It can read and write the following formats:

  • Text-Formats: O-Format, V-Format, S-Format

  • Binary formats: BI-Format, BK-Format, BL-Format

# read a matrix into a xarray-Dataset
from matrixconverters import ReadPTVMatrix, SavePTVMatrix
ds = ReadPTVMatrix(filepath)

# save a xr.Dataset as PTV-Matrix
import xarray as xr
da = xr.DataArray(np.arange(9).reshape(3, 3))
zones = xr.DataArray([100, 200, 300])
names = xr.DataArray(['A-Town', 'B-Village', 'C-City'])
ds = xr.Dataset({'matrix': da,
                 'zone_no': zones,
                 'zone_name': names,})
from matrixconverters.save_ptv import SavePTV
s = SavePTV(ds)
s.savePTVMatrix(file_name=matrix_fn_out, file_type='BK')

Writing PSV-Matrices

  • Programmsystem Verkehr by Software-Kontor Helmert-Hilke)

  • File-Types CC and CN

from matrixconverters.save_ptv import SavePTV
s = SavePTV(ds)
s.savePSVMatrix(file_name=matrix_fn_out, ftype='CC')

Export xarray-Dataset as compressed NetCDF-File

from matrixconverters.xarray2netcdf import xarray2netcdf
xarray2netcdf(ds, file_path)

ds_saved = xr.open_dataset(file_path)

Documentation

Installation

You can use pip to install the packages (and the requirements like numpy).

pip install matrixconverters

Another way to handle dependencies is to use conda.

There conda packages for python 3.8-3.12 for windows and linux are generated in the channel MaxBo in Anaconda Cloud.

conda create -n myenv python=3.12
conda activate myenv

conda config --add channels conda-forge
conda config --add channels MaxBo

conda install matrixconverters

This documentation contains

Code Documentation

Indices and tables